From f695f80d52486bd0106e1e45602164277b13add0 Mon Sep 17 00:00:00 2001 From: Michael Wagner Date: Thu, 18 Feb 2021 17:57:14 +0100 Subject: [PATCH] epic-ts --- debian/kivitendo.postinst | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/debian/kivitendo.postinst b/debian/kivitendo.postinst index 4f9364a42..f2174890b 100755 --- a/debian/kivitendo.postinst +++ b/debian/kivitendo.postinst @@ -14,13 +14,46 @@ fi # test DB login if ! su postgres -c "psql -c '\du'" | grep kivitendo >/dev/null then - echo "No user named 'kivitendo' found. It is now created. Use the same password!" - su postgres -c "createuser -dPs kivitendo" + echo "No user named 'kivitendo' found. It is now created." + if [ -n "$a" ] + then + # password is given + su postgres -c "createuser -ds kivitendo ; psql -c 'ALTER USER kivitendo WITH PASSWORD \"$a\";'" + else + su postgres -c "createuser -dPs kivitendo" + fi fi main=$(ls -d /etc/postgresql/*/main/) if ! grep kivitendo $main/pg_hba.conf >/dev/null then - echo "local all kivitendo md5" >> $main/pg_hba.conf + echo "adding kivitendo user access to $main/pg_hba.conf" + awk 'BEGIN { + found=0; } + /# "local/ { + if (found == 0) { + print; + print "local all kivitendo md5"; + found=1; + next; + }} + /^local.*all.*all/ { + if (found == 0) { + print "local all kivitendo md5"; + print; + found=1; + next; + }} + /^host/ { + if (found == 0) { + print "local all kivitendo md5"; + print; + found=1; + next; + }} + {print;} + ' $main/pg_hba.conf > /tmp/pg_hba.conf + mv /tmp/pg_hba.conf $main/pg_hba.conf + chown postgres:postgres $main/pg_hba.conf systemctl reload postgresql fi -- 2.20.1