2022-08-23 13:27:55 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
trap stop SIGTERM SIGINT SIGQUIT SIGHUP ERR
|
|
|
|
|
|
|
|
start(){
|
|
|
|
|
2021-11-28 12:08:23 +01:00
|
|
|
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
2022-08-23 13:27:55 +02:00
|
|
|
dpkg-reconfigure --frontend noninteractive tzdata
|
|
|
|
|
|
|
|
#install from package
|
|
|
|
echo "Check ZoneMinder version"
|
2024-10-30 15:02:54 +01:00
|
|
|
RESULT=$(dpkg -l | grep '^ii' | grep zoneminder |grep 1.36.35)
|
2022-08-23 13:27:55 +02:00
|
|
|
if [ "$RESULT" == "" ]; then
|
|
|
|
echo "Installing new version"
|
2024-10-30 15:02:54 +01:00
|
|
|
dpkg -i /zoneminder_1.36.35~20241030.27-bullseye_amd64.deb
|
2022-08-23 13:27:55 +02:00
|
|
|
a2enmod ssl \
|
|
|
|
&& a2enmod rewrite \
|
2022-08-30 11:14:11 +02:00
|
|
|
&& a2enmod headers \
|
|
|
|
&& a2enmod expires \
|
2022-08-23 13:27:55 +02:00
|
|
|
&& a2enconf zoneminder \
|
|
|
|
&& a2ensite default-ssl.conf
|
|
|
|
else
|
|
|
|
echo "Already up to date"
|
|
|
|
fi
|
2021-01-12 18:33:21 +01:00
|
|
|
|
2021-02-07 10:26:49 +01:00
|
|
|
echo "Configuring MariaDBPath"
|
|
|
|
if [ ! -d /config/mysql ]; then
|
|
|
|
mkdir -p /config/mysql
|
|
|
|
rsync -a -v -q --ignore-existing /var/lib/mysql/ /config/mysql/
|
2021-03-02 22:34:51 +01:00
|
|
|
echo "MariaDBPath configuration done"
|
2021-02-07 10:26:49 +01:00
|
|
|
else
|
|
|
|
echo "MariaDBPath already configured"
|
|
|
|
fi
|
|
|
|
sed -i -e 's,/var/lib/mysql,/config/mysql,g' /etc/mysql/mariadb.conf.d/50-server.cnf
|
2022-08-08 15:38:20 +02:00
|
|
|
echo 'innodb_file_per_table = ON' >> /etc/mysql/mariadb.conf.d/50-server.cnf
|
|
|
|
echo 'innodb_buffer_pool_size = 256M' >> /etc/mysql/mariadb.conf.d/50-server.cnf
|
|
|
|
echo 'innodb_log_file_size = 32M' >> /etc/mysql/mariadb.conf.d/50-server.cnf
|
2021-01-12 18:33:21 +01:00
|
|
|
|
2021-02-07 10:26:49 +01:00
|
|
|
echo "Check MariaDB config"
|
2022-08-23 13:27:55 +02:00
|
|
|
/etc/init.d/mariadb start
|
2021-03-02 10:52:23 +01:00
|
|
|
while ! mysqladmin ping --silent; do
|
|
|
|
echo "Waiting mysql startup..."
|
2022-08-23 13:27:55 +02:00
|
|
|
sleep 3
|
2021-03-02 10:52:23 +01:00
|
|
|
done
|
|
|
|
|
2021-01-12 18:33:21 +01:00
|
|
|
RESULT=$(mysqlshow --user=zmuser --password=zmpass zm| grep -v Wildcard | grep -o Tables)
|
2021-02-07 10:26:49 +01:00
|
|
|
if [ "$RESULT" != "Tables" ]; then
|
2021-01-12 18:33:21 +01:00
|
|
|
|
|
|
|
#configure mysql
|
|
|
|
echo "USE mysql;" > timezones.sql && mysql_tzinfo_to_sql /usr/share/zoneinfo >> timezones.sql
|
|
|
|
mysql -u root < timezones.sql
|
|
|
|
rm timezones.sql
|
|
|
|
mysql -u root < /usr/share/zoneminder/db/zm_create.sql
|
|
|
|
mysql -u root -e "grant all on zm.* to 'zmuser'@localhost identified by 'zmpass';"
|
|
|
|
mysqladmin -u root reload
|
|
|
|
|
|
|
|
#secure mysql
|
|
|
|
secret=$(openssl rand -base64 14)
|
|
|
|
mysql_secure_installation <<EOF
|
|
|
|
|
|
|
|
y
|
|
|
|
$secret
|
|
|
|
$secret
|
|
|
|
y
|
|
|
|
y
|
|
|
|
y
|
|
|
|
y
|
|
|
|
EOF
|
|
|
|
|
2022-08-30 10:25:56 +02:00
|
|
|
/etc/init.d/mariadb restart
|
2021-03-02 10:52:23 +01:00
|
|
|
while ! mysqladmin ping --silent; do
|
|
|
|
echo "Waiting mysql restart"
|
|
|
|
sleep 3
|
|
|
|
done
|
2022-08-23 13:27:55 +02:00
|
|
|
echo "MariaDB configuration done"
|
2021-02-07 10:26:49 +01:00
|
|
|
else
|
2022-08-23 13:27:55 +02:00
|
|
|
echo "MariaDB already configured"
|
2021-02-07 10:26:49 +01:00
|
|
|
fi
|
|
|
|
|
2022-08-08 15:38:20 +02:00
|
|
|
#echo "Checking Timezones"
|
|
|
|
#RESULT=$(cat /etc/mysql/my.cnf| grep default-time-zone)
|
|
|
|
#if [ "$RESULT" != "default-time-zone=$(cat /etc/timezone)" ]; then
|
|
|
|
# echo "Set Mysql timezone"
|
|
|
|
# printf "[mysqld]\n default-time-zone=$(cat /etc/timezone)" >> /etc/mysql/my.cnf
|
|
|
|
# /etc/init.d/mysql restart
|
|
|
|
# while ! mysqladmin ping --silent; do
|
|
|
|
# echo "Waiting mysql restart..."
|
|
|
|
# sleep 3
|
|
|
|
# done
|
|
|
|
#fi
|
2021-02-07 10:26:49 +01:00
|
|
|
|
|
|
|
RESULT=$(cat /etc/php/*/apache2/php.ini| grep "date.timezone =")
|
2022-08-23 13:27:55 +02:00
|
|
|
if [ "$RESULT" = ";date.timezone =" ]; then
|
2021-02-07 10:26:49 +01:00
|
|
|
echo "Set Php timezone"
|
2022-08-23 13:27:55 +02:00
|
|
|
printf "date.timezone = $(cat /etc/timezone)" >> /etc/php/*/apache2/php.ini
|
2021-02-07 10:26:49 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Checking MSMTP configuration"
|
|
|
|
if [ ! -f /config/msmtprc ]; then
|
|
|
|
printf "defaults
|
|
|
|
auth on
|
|
|
|
tls on
|
|
|
|
tls_trust_file /etc/ssl/certs/ca-certificates.crt
|
|
|
|
logfile ~/.msmtp.log
|
|
|
|
account gmail
|
|
|
|
host smtp.gmail.com
|
|
|
|
port 587
|
|
|
|
from username@gmail.com
|
|
|
|
user username
|
|
|
|
password password
|
|
|
|
account default : gmail
|
|
|
|
" > /config/msmtprc
|
|
|
|
fi
|
2021-01-12 18:33:21 +01:00
|
|
|
|
2021-02-07 10:26:49 +01:00
|
|
|
if [ ! -f /etc/msmtprc ]; then
|
2022-08-23 13:27:55 +02:00
|
|
|
ln -s /config/msmtprc /etc/msmtprc
|
2021-01-12 18:33:21 +01:00
|
|
|
fi
|
|
|
|
|
2021-02-07 10:26:49 +01:00
|
|
|
if [ "$SELFSIGNED" = "0" ]; then
|
2022-08-23 13:27:55 +02:00
|
|
|
echo "Linking to SWAG"
|
|
|
|
sed -i -e 's,/etc/ssl/certs/ssl-cert-snakeoil.pem,/sslcert/live/'$FQDN'/cert.pem,g' /etc/apache2/sites-available/default-ssl.conf
|
|
|
|
sed -i -e 's,/etc/ssl/private/ssl-cert-snakeoil.key,/sslcert/live/'$FQDN'/privkey.pem,g' /etc/apache2/sites-available/default-ssl.conf
|
2021-02-07 10:26:49 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
RESULT=$(cat /etc/apache2/apache2.conf| grep ServerName)
|
|
|
|
if [ "$RESULT" = "" ]; then
|
|
|
|
echo "Set ServerName"
|
|
|
|
echo "ServerName "$FQDN >> /etc/apache2/apache2.conf
|
|
|
|
fi
|
|
|
|
|
2022-08-23 13:27:55 +02:00
|
|
|
echo "Setting /var/cache subfolders"
|
2021-02-07 10:26:49 +01:00
|
|
|
mkdir -p /var/cache/zoneminder/cache && chown www-data:www-data /var/cache/zoneminder/cache
|
|
|
|
mkdir -p /var/cache/zoneminder/events && chown www-data:www-data /var/cache/zoneminder/events
|
|
|
|
mkdir -p /var/cache/zoneminder/images && chown www-data:www-data /var/cache/zoneminder/images
|
|
|
|
mkdir -p /var/cache/zoneminder/temp && chown www-data:www-data /var/cache/zoneminder/temp
|
|
|
|
|
|
|
|
echo "Starting"
|
2021-01-12 18:33:21 +01:00
|
|
|
#start
|
|
|
|
/etc/init.d/apache2 start
|
|
|
|
/usr/bin/zmpkg.pl start
|
2021-02-07 10:26:49 +01:00
|
|
|
|
2022-08-23 13:27:55 +02:00
|
|
|
RESULT=$(tail -n2 /var/log/zm/zmpkg.log |grep "Version mismatch")
|
2021-02-07 10:26:49 +01:00
|
|
|
if [ "$RESULT" != "" ]; then
|
2022-08-23 13:27:55 +02:00
|
|
|
echo "WARNING: DB version mismatch found!"
|
|
|
|
echo "auto align.."
|
|
|
|
/usr/bin/zmpkg.pl stop
|
|
|
|
/usr/bin/zmupdate.pl -nointeractive
|
|
|
|
/usr/bin/zmupdate.pl -f
|
|
|
|
/usr/bin/zmpkg.pl start
|
|
|
|
echo "done"
|
2021-02-07 10:26:49 +01:00
|
|
|
fi
|
|
|
|
|
2022-08-30 14:06:57 +02:00
|
|
|
mysql -e "update zm.Config set Value = '$TZ' where Name = 'ZM_TIMEZONE';"
|
|
|
|
|
2022-08-23 13:27:55 +02:00
|
|
|
tail -f /var/log/apache2/error.log & wait ${!}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stop(){
|
|
|
|
|
|
|
|
echo "Shutdown requested"
|
|
|
|
kill ${!};
|
|
|
|
|
|
|
|
echo "Stopping apache"
|
|
|
|
/etc/init.d/apache2 stop
|
|
|
|
echo "Stopping zoneminder"
|
|
|
|
/usr/bin/zmpkg.pl stop
|
|
|
|
echo "Stopping mariadb"
|
|
|
|
/etc/init.d/mariadb stop
|
|
|
|
|
|
|
|
echo "Shutdown completed"
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
|
|
|
start
|