2015-08-18 02:03:27 +08:00
#! /bin/sh
set -e
if [ "$1" = "configure" ]; then
2016-04-07 01:45:46 +08:00
. /etc/zm/zm.conf
# The logs can contain passwords, etc... so by setting group root, only www-data can read them, not people in the www-data group
2016-04-07 01:08:30 +08:00
chown www-data:root /var/log/zm
chown www-data:www-data /var/lib/zm
if [ -z "$2" ]; then
2016-04-21 02:38:51 +08:00
chown www-data:www-data /var/cache/zoneminder /var/cache/zoneminder/*
2016-04-07 01:08:30 +08:00
fi
2015-11-10 01:34:24 +08:00
# Do this every time the package is installed or upgraded
2015-12-21 01:23:40 +08:00
if [ "$ZM_DB_HOST" = "localhost" ]; then
2016-04-07 01:45:46 +08:00
if [ -e "/etc/init.d/mysql" ]; then
#
# Get mysql started if it isn't
#
if ! $(/etc/init.d/mysql status >/dev/null 2>&1); then
deb-systemd-invoke start mysql.service || exit $?
2016-04-07 01:08:30 +08:00
fi
2016-04-07 01:45:46 +08:00
if $(/etc/init.d/mysql status >/dev/null 2>&1); then
mysqladmin --defaults-file=/etc/mysql/debian.cnf -f reload
# test if database if already present...
if ! $(echo quit | mysql --defaults-file=/etc/mysql/debian.cnf zm > /dev/null 2> /dev/null) ; then
cat /usr/share/zoneminder/db/zm_create.sql | mysql --defaults-file=/etc/mysql/debian.cnf
# This creates the user.
2016-04-07 03:50:51 +08:00
echo "grant lock tables,alter,select,insert,update,delete,create,index on ${ZM_DB_NAME}.* to '${ZM_DB_USER}'@localhost identified by \"${ZM_DB_PASS}\";" | mysql --defaults-file=/etc/mysql/debian.cnf mysql
2016-04-07 01:45:46 +08:00
else
2016-04-07 03:50:51 +08:00
echo "grant lock tables,alter,select,insert,update,delete,create,index on ${ZM_DB_NAME}.* to '${ZM_DB_USER}'@localhost;" | mysql --defaults-file=/etc/mysql/debian.cnf mysql
2016-04-07 01:45:46 +08:00
fi
# Ensure zoneminder is stopped
deb-systemd-invoke stop zoneminder.service || exit $?
zmupdate.pl --nointeractive
zmupdate.pl --nointeractive -f
deb-systemd-invoke start zoneminder.service || exit $?
2016-04-07 01:08:30 +08:00
2016-04-07 01:45:46 +08:00
else
echo 'NOTE: mysql not running, please start mysql and run dpkg-reconfigure zoneminder when it is running.'
fi
2016-04-07 01:08:30 +08:00
else
2016-04-07 01:45:46 +08:00
echo 'mysql not found, assuming remote server.'
2016-04-07 01:08:30 +08:00
fi
2016-04-07 01:45:46 +08:00
2016-04-07 01:08:30 +08:00
else
2015-12-21 01:23:40 +08:00
echo "Not doing database upgrade due to remote db server ($ZM_DB_HOST)"
2016-04-07 01:08:30 +08:00
fi
2015-11-10 01:34:24 +08:00
2015-08-18 02:03:27 +08:00
fi
#DEBHELPER#