summarylogtreecommitdiffstats
path: root/zoneminder.install
diff options
context:
space:
mode:
Diffstat (limited to 'zoneminder.install')
-rw-r--r--zoneminder.install125
1 files changed, 75 insertions, 50 deletions
diff --git a/zoneminder.install b/zoneminder.install
index 0c7a838ca24..a1c83c9eaef 100644
--- a/zoneminder.install
+++ b/zoneminder.install
@@ -3,73 +3,78 @@ post_install() {
systemctl daemon-reload
- ### Apache ###
- if [ -f /usr/lib/systemd/system/httpd.service ]
- then
- # Check if the main conf file is present
- if [ -f /etc/httpd/conf/httpd.conf ]
- then
- # Enable mod_proxy
- sed -i 's|#LoadModule proxy_module modules/mod_proxy.so|LoadModule proxy_module modules/mod_proxy.so|g' /etc/httpd/conf/httpd.conf
- # Enable mod_proxy_fcgi
- sed -i 's|#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so|LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so|g' /etc/httpd/conf/httpd.conf
- # Enable mod_rewrite
- sed -i 's|#LoadModule rewrite_module modules/mod_rewrite.so|LoadModule rewrite_module modules/mod_rewrite.so|g' /etc/httpd/conf/httpd.conf
- # Enable mod_cgid
- sed -i 's|#LoadModule cgid_module modules/mod_cgid.so|LoadModule cgid_module modules/mod_cgid.so|g' /etc/httpd/conf/httpd.conf
-
- # Enable ZoneMinder's VirtualHost
- if ( ! grep -q 'zoneminder.conf' /etc/httpd/conf/httpd.conf )
- then
- echo "Include conf/extra/zoneminder.conf" >> /etc/httpd/conf/httpd.conf
- fi
- fi
-
- # Check if Nginx is running and if not (re)start Apache
- if [ "$(systemctl is-active nginx)" != "active" ]
- then
- systemctl is-active --quiet httpd && systemctl stop httpd
- systemctl start httpd
- fi
- fi
+ ### Nginx & Apache ###
- ### Nginx ###
- if [ -f /usr/lib/systemd/system/nginx.service ]
+ # If Nginx is installed and either is active, or is inactive but Apache is not installed, we prefer Nginx.
+ if [[ "$(pacman -Qs nginx)" = *"local/nginx"* ]] && { [ "$(systemctl is-active nginx)" = "active" ] || [[ "$(pacman -Qs apache)" != *"local/apache"* ]] ; }
then
- # Check if the main conf file is present
- if [ -f /etc/nginx/nginx.conf ]
+ # Ensure the main conf file is present
+ if [ -f /etc/nginx/nginx.conf ]
then
- # Configure it with the folder structure used in Debian-based distributions
+ # Configure Nginx with the folder structure used in Debian-based distributions
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
- # Enable ZoneMinder's server block
+ # Create the sites-enabled folder if it's not already created
if [ ! -d /etc/nginx/sites-enabled ]
then
mkdir -p /etc/nginx/sites-enabled
fi
+ # Enable ZoneMinder's server block if it's not already enabled
if [ ! -f /etc/nginx/sites-enabled/zoneminder.conf ]
then
- ln -s /etc/nginx/sites-{available,enabled}/zoneminder.conf
+ ln -sf /etc/nginx/sites-{available,enabled}/zoneminder.conf
fi
- fi
-
- # Check if Apache is running and if not (re)start Nginx
- if [ "$(systemctl is-active httpd)" != "active" ]
- then
+
+ # (Re)start Nginx
systemctl is-active --quiet nginx && systemctl stop nginx
systemctl start nginx
+ else
+ echo "ERROR: Nginx was detected but file '/etc/nginx/nginx.conf' was not found. Something seems broken."
+ echo
fi
+ # Else, if Nginx either is not installed, or is installed and inactive but Apache is also installed, we prefer Apache.
+ elif [[ "$(pacman -Qs apache)" = *"local/apache"* ]]
+ then
+ # Ensure the main conf file is present
+ if [ -f /etc/httpd/conf/httpd.conf ]
+ then
+ # Enable mod_proxy
+ sed -i 's|#LoadModule proxy_module modules/mod_proxy.so|LoadModule proxy_module modules/mod_proxy.so|g' /etc/httpd/conf/httpd.conf
+ # Enable mod_proxy_fcgi
+ sed -i 's|#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so|LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so|g' /etc/httpd/conf/httpd.conf
+ # Enable mod_rewrite
+ sed -i 's|#LoadModule rewrite_module modules/mod_rewrite.so|LoadModule rewrite_module modules/mod_rewrite.so|g' /etc/httpd/conf/httpd.conf
+ # Enable mod_cgid
+ sed -i 's|#LoadModule cgid_module modules/mod_cgid.so|LoadModule cgid_module modules/mod_cgid.so|g' /etc/httpd/conf/httpd.conf
+
+ # Enable ZoneMinder's VirtualHost if it's not already enabled
+ if ( ! grep -q 'zoneminder.conf' /etc/httpd/conf/httpd.conf )
+ then
+ echo "Include conf/extra/zoneminder.conf" >> /etc/httpd/conf/httpd.conf
+ fi
+
+ # (Re)start Apache
+ systemctl is-active --quiet httpd && systemctl stop httpd
+ systemctl start httpd
+ else
+ echo "ERROR: Apache was detected but file '/etc/httpd/conf/httpd.conf' was not found. Something seems broken."
+ echo
+ fi
+ # Else, if neither of them is installed, we inform the user that something is seriously messed up.
+ else
+ echo "ERROR: Neither Nginx nor Apache were detected in your system. I hope you know what you're doing."
+ echo
fi
### fcgiwrap ###
- if [ -f /usr/lib/systemd/system/fcgiwrap.service ]
+ if [[ "$(pacman -Qs fcgiwrap)" = *"local/fcgiwrap"* ]]
then
systemctl is-active --quiet fcgiwrap.socket && systemctl stop fcgiwrap.socket
systemctl is-active --quiet fcgiwrap && systemctl stop fcgiwrap
@@ -78,10 +83,11 @@ post_install() {
### 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
- if [ -f /usr/lib/systemd/system/php-fpm.service ]
+ if [[ "$(pacman -Qs php-fpm)" = *"local/php-fpm"* ]]
then
systemctl is-active --quiet php-fpm && systemctl stop php-fpm
systemctl start php-fpm
@@ -90,16 +96,19 @@ post_install() {
### MariaDB ###
- if [ -f /usr/lib/systemd/system/mariadb.service ]
+ # If MariaDB is installed
+ if [[ "$(pacman -Qs mariadb)" = *"local/mariadb "* ]]
then
# Initialize MariaDB's default database if it's not already initialized
if [ ! -d /var/lib/mysql/mysql ]
then
+ # Stop MariaDB if it's active
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
+ # Start MariaDB if it's not already active
systemctl is-active --quiet mariadb || systemctl start mariadb
# Create ZoneMinder's database & user if they do not exist
@@ -109,11 +118,11 @@ post_install() {
if [[ "$(mysql -uroot -e "select * from mysql.user;" 2>&1)" = *"Access denied"* ]]
then
# If a database root password is set
- echo \* Secure MariaDB installation found, please enter the database root password when prompted.
+ echo \* Secure MariaDB installation found, please enter the database root password.
echo
mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql
echo
- echo \* One more time...
+ echo \* Enter the password 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
@@ -135,7 +144,14 @@ post_install() {
echo ---------------
echo
- echo ZoneMinder is listening at http://localhost:8095
+
+ if [[ "$(systemctl is-active nginx)" = active ]] || [[ "$(systemctl is-active httpd)" = active ]]
+ then
+ echo ZoneMinder is listening at http://localhost:8095
+ else
+ echo WARNING: No web server has been configured.
+ fi
+
echo
}
@@ -144,11 +160,20 @@ post_upgrade() {
echo ---------------
echo
- echo The ZoneMinder updater will now run.
- # Make sure ZoneMinder is *not* running before we attempt to use its updater
+ echo The ZoneMinder updater will now run.
+
+ # Make sure ZoneMinder is *not* running before we attempt to use the updater
systemctl is-active --quiet zoneminder && systemctl stop zoneminder
- /usr/bin/zmupdate.pl -f
+
+ # Make sure MariaDB *is* running before we attempt to use the updater
+ # NOTE: We probably don't want this in a Multi Server setup because MariaDB will not be running locally,
+ # but since it will simply generate a harmless error and the updater will still run, for now I'm leaving it as is
+ systemctl is-active --quiet mariadb || systemctl start mariadb
+
+ # Run the updater
+ /usr/bin/zmupdate.pl
+
systemctl start zoneminder
echo