zoneminder/distros/debian8/zoneminder-database.config

143 lines
4.7 KiB
Plaintext
Raw Permalink Normal View History

2014-12-01 00:55:26 +08:00
#!/bin/sh
2014-12-02 07:58:18 +08:00
# config maintainer script for zoneminder
2014-12-01 00:55:26 +08:00
2014-12-12 20:04:17 +08:00
set -e
2014-12-01 00:55:26 +08:00
2014-12-02 07:58:18 +08:00
# Source the debconf stuff
2014-12-01 00:55:26 +08:00
. /usr/share/debconf/confmodule
# Set the first version in which dbconfig-common was introduced in the package
dbc_first_version="1.28.0"
2014-12-01 00:55:26 +08:00
2014-12-12 20:04:17 +08:00
CONFIGFILE=/etc/zm/zm.conf
2014-12-02 07:58:18 +08:00
if [ -e $CONFIGFILE ]; then
# Source the config file if exists
2014-12-12 20:04:17 +08:00
. $CONFIGFILE
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
2014-12-12 20:04:17 +08:00
# Default use dbconfig-common
dbc_install="true"
# Currently we only support mysql database
dbc_dbtypes="mysql"
# Set authentication method to password
dbc_authmethod_user="password"
# Source the dbconfig-common stuff
. /usr/share/dbconfig-common/dpkg/config
fi
2014-12-12 20:04:17 +08:00
# Do this when the package is installed, upgraded or reconfigured
# Most of answers are cached so the questions will not be asked again
if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ]; then
2014-12-12 20:04:17 +08:00
# Ask the user if the database shall be installed locally or remotely
db_input high zoneminder/debconf_dblocation || true
db_go || true
db_get zoneminder/debconf_dblocation
if [ "$RET" = "local" ]; then
if [ ! -e "/usr/sbin/mysqld" ]; then
# Display a message and exit if the user want a local database but
# no database server is available
db_input high zoneminder/debconf_dblocalmissingerror || true
db_go || true
exit 0
else
# Set the database server to localhost
dbc_dbserver="localhost"
fi
else
2014-12-12 20:04:17 +08:00
# Source the dbconfig main configuration file
if [ -f /etc/dbconfig-common/config ]; then
. /etc/dbconfig-common/config
fi
if [ "$dbc_remote_questions_default" = "false" ]; then
# Display a message and exit if the dbconfig configuration does not
# allow installation of remote databases
# Note: To overcome this issue, we could think to override the
# default setting by using dbc_remote_questions_default='true' in
# maintainer scripts but unfortunately this does not work due to
# current dbconfig design
# More information here:
# https://bugs.launchpad.net/ubuntu/+source/dbconfig-common/+bug/1065331
db_input high zoneminder/debconf_dbconfigerror || true
db_go || true
exit 0
fi
fi
2014-12-01 00:55:26 +08:00
2014-12-12 20:04:17 +08:00
# Ask the user for all database settings
dbc_go zoneminder $@
2014-12-02 07:58:18 +08:00
2014-12-08 23:57:37 +08:00
# Ask the user for the password of the database administrator if the user
2014-12-12 20:04:17 +08:00
# has not yet answered to this question.
# This situation may occur if the user skipped the database creation step
# when reconfiguring the package.
2014-12-08 23:57:37 +08:00
RET=""
db_get zoneminder/mysql/admin-pass
if [ -z "$RET" ]; then
db_input high zoneminder/mysql/admin-pass || true
db_go || true
fi
2014-12-12 20:04:17 +08:00
# Do this only when not upgrading the package (no old version in argument)
if [ -z "$2" ]; then
# Ask for the password of 'admin' user
while :; do
RET=""
db_input high zoneminder/admin_password || true
db_go || true
db_get zoneminder/admin_password
# If password isn't empty we ask for password verification
if [ -z "$RET" ]; then
db_fset zoneminder/admin_password seen false
db_fset zoneminder/admin_password_again seen false
break
fi
ROOT_PW="$RET"
db_input high zoneminder/admin_password_again || true
db_go || true
db_get zoneminder/admin_password_again
if [ "$RET" = "$ROOT_PW" ]; then
ROOT_PW=""
break
fi
db_fset zoneminder/password_mismatch seen false
db_input critical zoneminder/password_mismatch || true
db_set zoneminder/admin_password ""
db_set zoneminder/admin_password_again ""
db_go || true
done
else
# If we are upgrading the package, set an empty password to disable
# password update in ZoneMinder database
2014-12-08 23:57:37 +08:00
db_set zoneminder/admin_password ""
2014-12-12 20:04:17 +08:00
fi
# Set the seen flag to not ask this question again if no password is
# provided
db_fset zoneminder/admin_password seen true
2014-12-08 23:57:37 +08:00
fi
2014-12-02 07:58:18 +08:00
#DEBHELPER#
2014-12-01 00:55:26 +08:00
exit 0