Update zm.conf file in package which provide it

This commit is contained in:
Emmanuel Papin 2014-12-19 15:49:40 +01:00
parent 27ca8f7ee4
commit ae1bf955e5
3 changed files with 60 additions and 60 deletions

View File

@ -6,20 +6,61 @@ set -e
# Source the debconf stuff # Source the debconf stuff
. /usr/share/debconf/confmodule . /usr/share/debconf/confmodule
# Source the config file if exists # Source the config file
CONFIGFILE=/etc/zm/zm.conf CONFIGFILE=/etc/zm/zm.conf
if [ -e $CONFIGFILE ]; then . $CONFIGFILE
. $CONFIGFILE
fi
# Do this when the package is installed, upgraded or reconfigured # Do this when the package is installed, upgraded or reconfigured
if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ]; then 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 # Set some file permissions
chown $ZM_WEB_USER:$ZM_WEB_GROUP /var/log/zm chown $ZM_WEB_USER:$ZM_WEB_GROUP /var/log/zm
if [ -z "$2" ]; then if [ -z "$2" ]; then
chown $ZM_WEB_USER:$ZM_WEB_GROUP -R /var/cache/zoneminder chown $ZM_WEB_USER:$ZM_WEB_GROUP -R /var/cache/zoneminder
fi fi
# As requested by the Debian Webapps Policy Manual §3.2.1
chown root:${ZM_WEB_GROUP} $CONFIGFILE
chmod 640 $CONFIGFILE
fi fi
#DEBHELPER# #DEBHELPER#

View File

@ -9,16 +9,26 @@ set -e
# Set the first version in which dbconfig-common was introduced in the package # Set the first version in which dbconfig-common was introduced in the package
dbc_first_version="1.28.0" dbc_first_version="1.28.0"
# Source the config file if exists
CONFIGFILE=/etc/zm/zm.conf CONFIGFILE=/etc/zm/zm.conf
if [ -e $CONFIGFILE ]; then if [ -e $CONFIGFILE ]; then
# Source the config file if exists
. $CONFIGFILE . $CONFIGFILE
# Re-use data from ZM config file elif [ -e ${CONFIGFILE}.dpkg-new ]; then
dbc_dbserver="$ZM_DB_HOST" # If no config file, source the config file which is going to be installed
dbc_dbname="$ZM_DB_NAME" # by the core package
dbc_dbuser="$ZM_DB_USER" . ${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 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 if [ -f /usr/share/dbconfig-common/dpkg/config ]; then
# Default use dbconfig-common # Default use dbconfig-common

View File

@ -6,12 +6,6 @@ set -e
# Source the debconf stuff # Source the debconf stuff
. /usr/share/debconf/confmodule . /usr/share/debconf/confmodule
# Source the config file if exists
CONFIGFILE=/etc/zm/zm.conf
if [ -e $CONFIGFILE ]; then
. $CONFIGFILE
fi
mysql_update() { mysql_update() {
# Source the dbconfig stuff # Source the dbconfig stuff
@ -78,51 +72,6 @@ if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ]; then
# Update the default admin account and database version # Update the default admin account and database version
mysql_update 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 fi
# Do this every time the package is installed or upgraded # Do this every time the package is installed or upgraded