-
Notifications
You must be signed in to change notification settings - Fork 1
Description
The psql settings we might go a bit futher.
You have hard-coded the the authencation type, but we could get it from user input (probably using zenity) and assign the values to variables.
local_all_auth='md5'
local_all_loop4='md5'
local_all_loop6='md5'
local_repl_auth='md5'
local_repl_loop4='md5'
local_repl_loop6='md5'And then run the sed commands. I have modified your commands a bit. I have partially simplified, but probably partially not (because of [deimnprstu5]*, but I think it is good enough). Also, I have added the replication lines as they are in the default config in psql v10. We might also ask the user if you should add/enable or disable a particular line in the config and then first check if the particular setting (line) is in the config and remove disabled auths.
sed -i "s|\(local\s*all\s*all\s*\)[deimnprstu5]*$|\1$local_all_auth|" $pg_hba_conf
sed -i "s|\(host\s*all\s*all\s*127\.0\.0\.1/32\s*\)[deimnprstu5]*$|\1$local_all_loop4|" $pg_hba_conf
sed -i "s|\(host\s*all\s*all\s*::1/128\s*\)[deimnprstu5]*$|\1$local_all_loop6|" $pg_hba_conf
sed -i "s|\(local\s*replication\s*all\s*\)[deimnprstu5]*$|\1$local_repl_auth|" $pg_hba_conf
sed -i "s|\(host\s*replication\s*all\s*127\.0\.0\.1/32\s*\)[deimnprstu5]*$|\1$local_repl_loop4|" $pg_hba_conf
sed -i "s|\(host\s*replication\s*all\s*::1/128\s*\)[deimnprstu5]*$|\1$local_repl_loop6|" $pg_hba_confAnyway, if you don’t want to add separate settings (and the dialogues/questions), I’d rather use the following command than 6 commands above. Some might argue that this is less readable—I let you choose whichever suites you best. 😃
sed -i "s|\(local\s*all\s*all\s*\)[deimnprstu5]*$|\1$local_all_auth|;s|\(host\s*all\s*all\s*127\.0\.0\.1/32\s*\)[deimnprstu5]*$|\1$local_all_loop4|;s|\(host\s*all\s*all\s*::1/128\s*\)[deimnprstu5]*$|\1$local_all_loop6|;s|\(local\s*replication\s*all\s*\)[deimnprstu5]*$|\1$local_repl_auth|;s|\(host\s*replication\s*all\s*127\.0\.0\.1/32\s*\)[deimnprstu5]*$|\1$local_repl_loop4|;s|\(host\s*replication\s*all\s*::1/128\s*\)[deimnprstu5]*$|\1$local_repl_loop6|" $pg_hba_conf