From 59a32fa0c982c04d377be12d358c52bb08f1e421 Mon Sep 17 00:00:00 2001 From: Bruno Cesar Ribas Date: Thu, 23 Aug 2018 11:33:16 -0300 Subject: d/boca-db.{postinst,templates}: New postinst This postinst will prompt the user for a DB password and will configure postgresql accordingly Signed-off-by: Bruno Cesar Ribas --- debian/boca-db.postinst | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 debian/boca-db.postinst (limited to 'debian/boca-db.postinst') diff --git a/debian/boca-db.postinst b/debian/boca-db.postinst new file mode 100644 index 0000000..8a36f55 --- /dev/null +++ b/debian/boca-db.postinst @@ -0,0 +1,66 @@ +#!/bin/bash + +set -e + +. /usr/share/debconf/confmodule + +priority=high + +case "$1" in + configure|reconfigure) + + #Assume DBHOST will be localhost, since this is the package that + #provides postgresql + #XXX future work make it work as a backup DB server + DBHOST=localhost + + db_get boca-common/dbpassword || true + PASSWORD="$RET" + + #If we don't have a password from boca-common 2 things could be + #happened + #1) dpkg cleaned the password already + #2) The user did not provide a password + #So we will ask for a password + if [[ "x$PASSWORD" == "x" ]]; then + db_input critical boca-db/dbpassword || true + db_go || true + db_get boca-db/dbpassword || true + PASSWORD="$RET" + db_reset boca-db/dbpassword + else + db_reset boca-common/dbpassword + fi + + if [[ "x$PASSWORD" == "x" ]]; then + printf "Generating password with makepasswd" + PASSWORD="$(makepasswd --chars 20)" + echo . + echo "Your DB password is '$PASSWORD' take care of it." + fi + export PASSWD="$PASSWORD" + boca-config-dbhost $DBHOST + unset PASSWD + postgresuser=postgres + su - $postgresuser -c "echo drop user bocauser | psql -d template1 >/dev/null 2>/dev/null" + su - $postgresuser -c "echo create user bocauser createdb password \'$PASSWORD\'| psql -d template1" + su - $postgresuser -c "echo alter user bocauser createdb password \'$PASSWORD\'| psql -d template1" + + db_input critical boca-db/createdb || true + db_go || true + + db_get boca-db/createdb || true + + if [[ "$RET" == "Yes" ]]; then + echo YES |php /var/www/boca/src/private/createdb.php + fi + db_reset boca-db/createdb + + ;; + *) + ;; +esac + +service postgresql restart || true + +exit 0 -- cgit v1.2.3 From 9f05ae47d104864162f264fe6415d73797e039bd Mon Sep 17 00:00:00 2001 From: Bruno Cesar Ribas Date: Thu, 23 Aug 2018 23:25:23 -0300 Subject: d/boca-{common,db}.postinst: Avoid asking same question on upgrade From now on the user must remove lines containing 'bdserver' or 'bdcreated in /etc/boca.conf in order to modify the DB password and the DB hostname. Signed-off-by: Bruno Cesar Ribas --- debian/boca-db.postinst | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'debian/boca-db.postinst') diff --git a/debian/boca-db.postinst b/debian/boca-db.postinst index 8a36f55..c4215df 100644 --- a/debian/boca-db.postinst +++ b/debian/boca-db.postinst @@ -9,6 +9,14 @@ priority=high case "$1" in configure|reconfigure) + if [[ -e "/etc/boca.conf" ]]; then + . /etc/boca.conf + if [[ "$bdcreated" != "" ]]; then + echo "If you want to reset DB configuration, please unset \"bdcreated\" in /etc/boca.conf" + exit 0 + fi + fi + #Assume DBHOST will be localhost, since this is the package that #provides postgresql #XXX future work make it work as a backup DB server @@ -53,6 +61,7 @@ case "$1" in if [[ "$RET" == "Yes" ]]; then echo YES |php /var/www/boca/src/private/createdb.php + echo "bdcreated=y" >> /etc/boca.conf fi db_reset boca-db/createdb -- cgit v1.2.3