1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
post_install() {
systemctl daemon-reload
echo
### MariaDB ###
# Initialize MariaDB's default database if it's not already initialized
if [ ! -d /var/lib/mysql/mysql ]
then
systemctl is-active --quiet mariadb && systemctl stop mariadb
# NOTE: This will need to be changed when MariaDB 10.2 hits the repos, as mysql_install_db has been deprecated in favor of mysqld
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql 2> /dev/null
fi
systemctl is-active --quiet mariadb || systemctl start mariadb
# Create ZoneMinder's database & user if they do not exist
if [ ! -d /var/lib/mysql/zm ]
then
# If a database root password is set
if [[ "$(mysql -uroot -e "select * from mysql.user;" 2>&1)" = *"Access denied"* ]]
then
echo \* Secure MariaDB installation found, please enter the database root password when prompted.
echo
mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql
echo
echo \* One more time...
echo
mysql -uroot -p -e "grant select,insert,update,delete,create,alter,index,lock tables on zm.* to 'zmuser'@localhost identified by 'zmpass';"
echo
# If a database root password is not set
else
mysql -uroot < /usr/share/zoneminder/db/zm_create.sql
mysql -uroot -e "grant select,insert,update,delete,create,alter,index,lock tables on zm.* to 'zmuser'@localhost identified by 'zmpass';"
fi
fi
### PHP-FPM ###
# Set local timezone in /etc/php/conf.d/zoneminder.ini
sed -i 's|PLACEHOLDER|'`timedatectl | grep "Time zone" | tr -s ' ' | cut -f4 -d ' '`'|g' /etc/php/conf.d/zoneminder.ini
systemctl is-active --quiet php-fpm && systemctl stop php-fpm
systemctl start php-fpm
### fcgiwrap ###
systemctl is-active --quiet fcgiwrap.socket && systemctl stop fcgiwrap.socket && systemctl stop fcgiwrap
systemctl start fcgiwrap.socket
### Nginx ###
# Configure it with the folder structure used in Debian-based distributions
if [ -f /etc/nginx/nginx.conf ]
then
if ( ! grep -q 'sites-enabled' /etc/nginx/nginx.conf )
then
sed -i 's|http {|http {\'$'\n include sites-enabled/*.conf;|g' /etc/nginx/nginx.conf
fi
systemctl is-active --quiet nginx && systemctl stop nginx
systemctl start nginx
fi
### ZoneMinder
# Also activate the tmpfile to create runtime directories
systemctl is-active --quiet zoneminder && systemctl stop zoneminder
systemd-tmpfiles --create
systemctl start zoneminder
echo Done!
echo
echo ZoneMinder is listening at http://localhost:8095
echo
}
post_upgrade() {
post_install
# Make sure ZoneMinder is running before we attempt to use its updater
if ( systemctl is-active --quiet zoneminder )
then
/usr/bin/zmupdate.pl -f 1> /dev/null
else
echo ---------------
echo
echo Error performing database update, zoneminder.service could not be started. Please fix any issues and manually run \'/usr/bin/zmupdater.pl -f\'
echo
fi
}
post_remove() {
systemctl daemon-reload && systemctl is-active --quiet zoneminder && systemctl stop zoneminder
echo
echo ZoneMinder\'s database and user have been left intact. You can remove them by running the following:
echo
echo mysql -uroot -p -e \"drop database zm\;\"
echo mysql -uroot -p -e \"drop user \'zmuser\'@localhost\;\"
echo
echo If you haven\'t yet configured a password for the database root user, omit the \'-p\' option.
echo
}
|