diff --git a/distros/debian8/zoneminder-core.postinst b/distros/debian8/zoneminder-core.postinst index 37ebe25e9..1f047536b 100644 --- a/distros/debian8/zoneminder-core.postinst +++ b/distros/debian8/zoneminder-core.postinst @@ -6,20 +6,61 @@ set -e # Source the debconf stuff . /usr/share/debconf/confmodule -# Source the config file if exists +# Source the config file CONFIGFILE=/etc/zm/zm.conf -if [ -e $CONFIGFILE ]; then - . $CONFIGFILE -fi +. $CONFIGFILE # Do this when the package is installed, upgraded or reconfigured if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ]; then + # Retrieve data from dbconfig (inputs from user) + . /etc/dbconfig-common/zoneminder.conf + + # ZoneMinder config file handling + # Inspired by: http://manpages.debian.org/cgi-bin/man.cgi?query=debconf-devel&sektion=7 + + # Backup the config file + cp -a -f $CONFIGFILE ${CONFIGFILE}.postinst.bak + + # Redeclare variables if missing in config file + test -z $dbc_dbserver || grep -Eq "^ *ZM_DB_HOST=" $CONFIGFILE \ + || echo "ZM_DB_HOST=" >> ${CONFIGFILE}.postinst.bak + test -z $dbc_dbname || grep -Eq "^ *ZM_DB_NAME=" $CONFIGFILE \ + || echo "ZM_DB_NAME=" >> ${CONFIGFILE}.postinst.bak + test -z $dbc_dbuser || grep -Eq "^ *ZM_DB_USER=" $CONFIGFILE \ + || echo "ZM_DB_USER=" >> ${CONFIGFILE}.postinst.bak + test -z $dbc_dbpass || grep -Eq "^ *ZM_DB_PASS=" $CONFIGFILE \ + || echo "ZM_DB_PASS=" >> ${CONFIGFILE}.postinst.bak + + # Prevent ZM_DB_HOST to be empty if user selected the 'unix socket' method + if test -z $dbc_dbserver; then + dbc_dbserver_override="localhost" + else + dbc_dbserver_override=$dbc_dbserver + fi + + # Update variables in config file + sed -i "s/^ *ZM_DB_HOST=.*/ZM_DB_HOST=$dbc_dbserver_override/" \ + ${CONFIGFILE}.postinst.bak + test -z $dbc_dbname || sed -i "s/^ *ZM_DB_NAME=.*/ZM_DB_NAME=$dbc_dbname/" \ + ${CONFIGFILE}.postinst.bak + test -z $dbc_dbuser || sed -i "s/^ *ZM_DB_USER=.*/ZM_DB_USER=$dbc_dbuser/" \ + ${CONFIGFILE}.postinst.bak + test -z $dbc_dbpass || sed -i "s/^ *ZM_DB_PASS=.*/ZM_DB_PASS=$dbc_dbpass/" \ + ${CONFIGFILE}.postinst.bak + + # Clean-up backup file + mv -f ${CONFIGFILE}.postinst.bak $CONFIGFILE + + # Set some file permissions chown $ZM_WEB_USER:$ZM_WEB_GROUP /var/log/zm if [ -z "$2" ]; then chown $ZM_WEB_USER:$ZM_WEB_GROUP -R /var/cache/zoneminder fi + # As requested by the Debian Webapps Policy Manual §3.2.1 + chown root:${ZM_WEB_GROUP} $CONFIGFILE + chmod 640 $CONFIGFILE fi #DEBHELPER# diff --git a/distros/debian8/zoneminder-database.config b/distros/debian8/zoneminder-database.config index e03153ce8..5c5b0afe5 100644 --- a/distros/debian8/zoneminder-database.config +++ b/distros/debian8/zoneminder-database.config @@ -9,16 +9,26 @@ set -e # Set the first version in which dbconfig-common was introduced in the package dbc_first_version="1.28.0" -# Source the config file if exists CONFIGFILE=/etc/zm/zm.conf if [ -e $CONFIGFILE ]; then + # Source the config file if exists . $CONFIGFILE - # Re-use data from ZM config file - dbc_dbserver="$ZM_DB_HOST" - dbc_dbname="$ZM_DB_NAME" - dbc_dbuser="$ZM_DB_USER" +elif [ -e ${CONFIGFILE}.dpkg-new ]; then + # If no config file, source the config file which is going to be installed + # by the core package + . ${CONFIGFILE}.dpkg-new +else + # If no config file is going to be installed, set some default values + ZM_DB_HOST= + ZM_DB_NAME="zm" + ZM_DB_USER="zmuser" fi +# Set some variables for the dbconfig-common stuff +dbc_dbserver="$ZM_DB_HOST" +dbc_dbname="$ZM_DB_NAME" +dbc_dbuser="$ZM_DB_USER" + if [ -f /usr/share/dbconfig-common/dpkg/config ]; then # Default use dbconfig-common diff --git a/distros/debian8/zoneminder-database.postinst b/distros/debian8/zoneminder-database.postinst index f6582da26..6faf28a58 100644 --- a/distros/debian8/zoneminder-database.postinst +++ b/distros/debian8/zoneminder-database.postinst @@ -6,12 +6,6 @@ set -e # Source the debconf stuff . /usr/share/debconf/confmodule -# Source the config file if exists -CONFIGFILE=/etc/zm/zm.conf -if [ -e $CONFIGFILE ]; then - . $CONFIGFILE -fi - mysql_update() { # Source the dbconfig stuff @@ -78,51 +72,6 @@ if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ]; then # Update the default admin account and database version mysql_update - - # Retrieve data from dbconfig (inputs from user) - . /etc/dbconfig-common/zoneminder.conf - - # ZoneMinder config file handling - # Inspired by: http://manpages.debian.org/cgi-bin/man.cgi?query=debconf-devel&sektion=7 - - # Backup the config file - cp -a -f $CONFIGFILE ${CONFIGFILE}.postinst.bak - - # Redeclare variables if missing in config file - test -z $dbc_dbserver || grep -Eq "^ *ZM_DB_HOST=" $CONFIGFILE \ - || echo "ZM_DB_HOST=" >> ${CONFIGFILE}.postinst.bak - test -z $dbc_dbname || grep -Eq "^ *ZM_DB_NAME=" $CONFIGFILE \ - || echo "ZM_DB_NAME=" >> ${CONFIGFILE}.postinst.bak - test -z $dbc_dbuser || grep -Eq "^ *ZM_DB_USER=" $CONFIGFILE \ - || echo "ZM_DB_USER=" >> ${CONFIGFILE}.postinst.bak - test -z $dbc_dbpass || grep -Eq "^ *ZM_DB_PASS=" $CONFIGFILE \ - || echo "ZM_DB_PASS=" >> ${CONFIGFILE}.postinst.bak - - # Prevent ZM_DB_HOST to be empty if user selected the 'unix socket' method - if test -z $dbc_dbserver; then - dbc_dbserver_override="localhost" - else - dbc_dbserver_override=$dbc_dbserver - fi - - # Update variables in config file - sed -i "s/^ *ZM_DB_HOST=.*/ZM_DB_HOST=$dbc_dbserver_override/" \ - ${CONFIGFILE}.postinst.bak - test -z $dbc_dbname || sed -i "s/^ *ZM_DB_NAME=.*/ZM_DB_NAME=$dbc_dbname/" \ - ${CONFIGFILE}.postinst.bak - test -z $dbc_dbuser || sed -i "s/^ *ZM_DB_USER=.*/ZM_DB_USER=$dbc_dbuser/" \ - ${CONFIGFILE}.postinst.bak - test -z $dbc_dbpass || sed -i "s/^ *ZM_DB_PASS=.*/ZM_DB_PASS=$dbc_dbpass/" \ - ${CONFIGFILE}.postinst.bak - - # Clean-up backup file - mv -f ${CONFIGFILE}.postinst.bak $CONFIGFILE - - - # As requested by the Debian Webapps Policy Manual §3.2.1 - chown root:$ZM_WEB_GROUP /etc/zm/zm.conf - chmod 640 /etc/zm/zm.conf - fi # Do this every time the package is installed or upgraded