diff --git a/utils/docker/entrypoint.sh b/utils/docker/entrypoint.sh index a3a45511b..cc01216ce 100755 --- a/utils/docker/entrypoint.sh +++ b/utils/docker/entrypoint.sh @@ -6,6 +6,72 @@ # SUBROUTINES # ############### +# Find ciritical files and perform sanity checks +initialze () { + + # Check to see if this script has access to all the commands it needs + for CMD in mysqladmin sed usermod service; do + type $CMD &> /dev/null + + if [ $? -ne 0 ]; then + echo + echo "ERROR: The script cannot find the required command \"${CMD}\"." + echo + exit 1 + fi + done + + # Look in common places for the zoneminder config file - zm.conf + for FILE in "/etc/zm.conf" "/etc/zm/zm.conf" "/usr/local/etc/zm.conf" "/usr/local/etc/zm/zm.conf"; do + if [ -f $FILE ]; then + ZMCONF=$FILE + break + fi + done + + # Look in common places for the zoneminder startup perl script - zmpkg.pl + for FILE in "/usr/bin/zmpkg.pl" "/usr/local/bin/zmpkg.pl"; do + if [ -f $FILE ]; then + ZMPKG=$FILE + break + fi + done + + # Look in common places for the zoneminder dB creation script - zm_create.sql + for FILE in "/usr/share/zoneminder/db/zm_create.sql" "/usr/local/share/zoneminder/db/zm_create.sql"; do + if [ -f $FILE ]; then + ZMCREATE=$FILE + break + fi + done + + # Look in common places for the php.ini relevant to zoneminder - php.ini + # Search order matters here because debian distros commonly have multiple php.ini's + for FILE in "/etc/php/7.0/apache2/php.ini" "/etc/php5/apache2/php.ini" "/etc/php.ini" "/usr/local/etc/php.ini"; do + if [ -f $FILE ]; then + PHPINI=$FILE + break + fi + done + + for FILE in $ZMCONF $ZMPKG $ZMCREATE $PHPINI; do + if [ -z $FILE ]; then + echo + echo "FATAL: This script was unable to determine one or more cirtical files. Cannot continue." + echo + echo "VARIABLE DUMP" + echo "-------------" + echo + echo "Path to zm.conf: ${ZMCONF}" + echo "Path to zmpkg.pl: ${ZMPKG}" + echo "Path to zm_create.sql: ${ZMCREATE}" + echo "Path to php.ini: ${PHPINI}" + echo + exit 98 + fi + done +} + start_mysql () { service mysql start # Give MySQL time to wake up @@ -37,34 +103,34 @@ close_mysql () { ################ echo +initialize # Configure then start Mysql if [ -n "$MYSQL_SERVER" ] && [ -n "$MYSQL_USER" ] && [ -n "$MYSQL_PASSWORD" ] && [ -n "$MYSQL_DB" ]; then - sed -i -e "s/ZM_DB_NAME=zm/ZM_DB_NAME=$MYSQL_USER/g" /etc/zm.conf - sed -i -e "s/ZM_DB_USER=zmuser/ZM_DB_USER=$MYSQL_USER/g" /etc/zm.conf - sed -i -e "s/ZM_DB_PASS=zm/ZM_DB_PASS=$MYSQL_PASS/g" /etc/zm.conf - sed -i -e "s/ZM_DB_HOST=localhost/ZM_DB_HOST=$MYSQL_SERVER/g" /etc/zm.conf + sed -i -e "s/ZM_DB_NAME=zm/ZM_DB_NAME=$MYSQL_USER/g" $ZMCONF + sed -i -e "s/ZM_DB_USER=zmuser/ZM_DB_USER=$MYSQL_USER/g" $ZMCONF + sed -i -e "s/ZM_DB_PASS=zm/ZM_DB_PASS=$MYSQL_PASS/g" $ZMCONF + sed -i -e "s/ZM_DB_HOST=localhost/ZM_DB_HOST=$MYSQL_SERVER/g" $ZMCONF start_mysql else usermod -d /var/lib/mysql/ mysql start_mysql - mysql -u root < /usr/local/share/zoneminder/db/zm_create.sql + mysql -u root < $ZMCREATE mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'zmuser'@'localhost' IDENTIFIED BY 'zmpass';" fi # Ensure we shut down mysql cleanly later: trap close_mysql SIGTERM # Configure then start Apache -if [ -n "$TZ" ]; then - echo "date.timezone = $TZ" >> /etc/php/7.0/apache2/php.ini -else - echo "date.timezone = UTC" >> /etc/php/7.0/apache2/php.ini +if [ -z "$TZ" ]; then + $TZ = UTC fi +echo "date.timezone = $TZ" >> $PHPINI service apache2 start # Start ZoneMinder echo " * Starting ZoneMinder video surveillance recorder" -/usr/local/bin/zmpkg.pl start +$ZMPKG start echo " ...done." # Stay in a loop to keep the container running