zmlinkcontent.sh - verify zm temp and log folders

This commit is contained in:
Andrew Bauer 2018-01-17 08:16:15 -06:00
parent 0305dfea92
commit 0ddf9633ed
1 changed files with 132 additions and 9 deletions

View File

@ -4,22 +4,32 @@
# Set the content dir default to be the one supplied to cmake # Set the content dir default to be the one supplied to cmake
ZM_PATH_CONTENT="@ZM_CONTENTDIR@" ZM_PATH_CONTENT="@ZM_CONTENTDIR@"
# Set the zoneminder log dir default to be the one supplied to cmake
ZM_LOGDIR="@ZM_LOGDIR@"
# Set the zoneminder temp dir default to be the one supplied to cmake
ZM_LOGDIR="@ZM_TMPDIR@"
echo "*** This bash script creates the nessecary symlinks for the zoneminder content" echo "*** This bash script creates the nessecary symlinks for the zoneminder content"
echo "*** It can use an existing content folder or create a new one" echo "*** It can use an existing content folder or create a new one"
echo "*** For usage: use -h" echo "*** For usage: use -h"
echo "*** The default content directory is: $ZM_PATH_CONTENT" echo "*** The default content directory is: $ZM_PATH_CONTENT"
echo "*** The default log directory is: $ZM_LOGDIR"
echo "*** The default temp directory is: $ZM_TMPDIR"
echo "" echo ""
usage() usage()
{ {
cat <<EOF cat <<EOF
Usage: $0 [-q] [-z zm.conf] [-w WEB DIRECTORY] [CONTENT DIRECTORY] Usage: $0 [-q] [-z zm.conf] [-w WEB DIRECTORY] [-l LOG DIRECTORY] [-t TMP DIRECTORY] [CONTENT DIRECTORY]
OPTIONS: OPTIONS:
-h Show this message and quit -h Show this message and quit
-z ZoneMinder configuration file -z ZoneMinder configuration file
-w Override the web directory from zm.conf -w Override the web directory from zm.conf
-q Quick mode. Do not change ownership recursively. -q Quick mode. Do not change ownership recursively.
-l Override the zm log folder location
-t Override the zm temp folder location
If the -w option is not used to specify the path to the web directory, If the -w option is not used to specify the path to the web directory,
the script will use the path from zoneminder's configuration file. the script will use the path from zoneminder's configuration file.
@ -30,7 +40,7 @@ If that fails, it will try from /etc/zm.conf
EOF EOF
} }
while getopts "hz:w:q" OPTION while getopts "hz:w:q:l:t" OPTION
do do
case $OPTION in case $OPTION in
h) h)
@ -46,6 +56,12 @@ do
q) q)
QUICK=1 QUICK=1
;; ;;
l)
ZM_LOGDIR_FORCE=$OPTARG
;;
t)
ZM_TMPDIR_FORCE=$OPTARG
;;
esac esac
done done
shift $(( OPTIND - 1 )) shift $(( OPTIND - 1 ))
@ -73,7 +89,7 @@ elif [ -f "/etc/zm.conf" ]; then
echo "Using system zm.conf" echo "Using system zm.conf"
source "/etc/zm.conf" source "/etc/zm.conf"
else else
echo "Failed locating zoneminder configuration file (zm.conf)\nUse the -z option to specify the full path to the zoneminder configuration file" echo -e "Failed locating zoneminder configuration file (zm.conf)\nUse the -z option to specify the full path to the zoneminder configuration file"
exit 45 exit 45
fi fi
@ -82,6 +98,16 @@ if [ -n "$ZM_PATH_WEB_FORCE" ]; then
ZM_PATH_WEB="$(readlink -f $ZM_PATH_WEB_FORCE)" ZM_PATH_WEB="$(readlink -f $ZM_PATH_WEB_FORCE)"
fi fi
# Override the log directory path
if [ -n "$ZM_LOGDIR_FORCE" ]; then
ZM_LOGDIR="$(readlink -f $ZM_LOGDIR_FORCE)"
fi
# Override the tmp directory path
if [ -n "$ZM_TMPDIR_FORCE" ]; then
ZM_TMPDIR="$(readlink -f $ZM_TMPDIR_FORCE)"
fi
# Override the default content path # Override the default content path
if [[ -n "$@" ]]; then if [[ -n "$@" ]]; then
ZM_PATH_CONTENT="$(readlink -f $@)" ZM_PATH_CONTENT="$(readlink -f $@)"
@ -90,6 +116,8 @@ fi
# Print some information # Print some information
echo "Web folder : $ZM_PATH_WEB" echo "Web folder : $ZM_PATH_WEB"
echo "Content folder : $ZM_PATH_CONTENT" echo "Content folder : $ZM_PATH_CONTENT"
echo "Log folder : $ZM_LOGDIR"
echo "Temp folder : $ZM_TMPDIR"
echo "" echo ""
# Verify the web folder is a real directory # Verify the web folder is a real directory
@ -98,7 +126,7 @@ if [ -d "$ZM_PATH_WEB" ]; then
echo "OK" echo "OK"
else else
echo "Failed" echo "Failed"
exit 3 exit 2
fi fi
# Check if the content folder exists, and if not, create it # Check if the content folder exists, and if not, create it
@ -109,6 +137,22 @@ else
echo "No" echo "No"
echo -n "Creating the content folder... " echo -n "Creating the content folder... "
mkdir "$ZM_PATH_CONTENT" mkdir "$ZM_PATH_CONTENT"
if [ "$?" = "0" ]; then
echo "OK"
else
echo "Failed"
exit 3
fi
fi
# Check if the log folder exists, and if not, create the entire folder including its parents
echo -n "Checking if the log folder exists... "
if [ -d "$ZM_LOGDIR" ]; then
echo "Yes"
else
echo "No"
echo -n "Creating the log folder... "
mkdir -p "$ZM_LOGDIR"
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
echo "OK" echo "OK"
else else
@ -116,6 +160,23 @@ else
exit 4 exit 4
fi fi
fi fi
# Check if the temp folder exists, and if not, create the entire folder including its parents
echo -n "Checking if the temp folder exists... "
if [ -d "$ZM_TMPDIR" ]; then
echo "Yes"
else
echo "No"
echo -n "Creating the temp folder... "
mkdir -p "$ZM_TMPDIR"
if [ "$?" = "0" ]; then
echo "OK"
else
echo "Failed"
exit 5
fi
fi
# Check if the content/images folder exists, and if not, create it # Check if the content/images folder exists, and if not, create it
echo -n "Checking if the images folder exists inside the content folder... " echo -n "Checking if the images folder exists inside the content folder... "
if [ -d "$ZM_PATH_CONTENT/images" ]; then if [ -d "$ZM_PATH_CONTENT/images" ]; then
@ -131,6 +192,7 @@ else
exit 6 exit 6
fi fi
fi fi
# Check if the content/events folder exists, and if not, create it # Check if the content/events folder exists, and if not, create it
echo -n "Checking if the events folder exists inside the content folder... " echo -n "Checking if the events folder exists inside the content folder... "
if [ -d "$ZM_PATH_CONTENT/events" ]; then if [ -d "$ZM_PATH_CONTENT/events" ]; then
@ -228,11 +290,32 @@ if [ -n "$QUICK" ]; then
echo "OK" echo "OK"
else else
echo "Failed" echo "Failed"
exit 25 exit 23
fi fi
else else
echo -n "Changing ownership of the events folder recursively to ${ZM_WEB_USER} ${ZM_WEB_GROUP}... " echo -n "Changing ownership of the events folder recursively to ${ZM_WEB_USER} ${ZM_WEB_GROUP}... "
chown -R ${ZM_WEB_USER}:${ZM_WEB_GROUP} "$ZM_PATH_CONTENT/events" chown -R ${ZM_WEB_USER}:${ZM_WEB_GROUP} "$ZM_PATH_CONTENT/events"
if [ "$?" = "0" ]; then
echo "OK"
else
echo "Failed"
exit 24
fi
fi
# change ownership for the log folder. do it recursively unless -q is used
if [ -n "$QUICK" ]; then
echo -n "Changing ownership of the log folder to ${ZM_WEB_USER} ${ZM_WEB_GROUP}... "
chown ${ZM_WEB_USER}:${ZM_WEB_GROUP} "$ZM_LOGDIR"
if [ "$?" = "0" ]; then
echo "OK"
else
echo "Failed"
exit 25
fi
else
echo -n "Changing ownership of the log folder recursively to ${ZM_WEB_USER} ${ZM_WEB_GROUP}... "
chown -R ${ZM_WEB_USER}:${ZM_WEB_GROUP} "$ZM_LOGDIR"
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
echo "OK" echo "OK"
else else
@ -241,6 +324,27 @@ else
fi fi
fi fi
# change ownership for the temp folder. do it recursively unless -q is used
if [ -n "$QUICK" ]; then
echo -n "Changing ownership of the temp folder to ${ZM_WEB_USER} ${ZM_WEB_GROUP}... "
chown ${ZM_WEB_USER}:${ZM_WEB_GROUP} "$ZM_TMPDIR"
if [ "$?" = "0" ]; then
echo "OK"
else
echo "Failed"
exit 27
fi
else
echo -n "Changing ownership of the temp folder recursively to ${ZM_WEB_USER} ${ZM_WEB_GROUP}... "
chown -R ${ZM_WEB_USER}:${ZM_WEB_GROUP} "$ZM_TMPDIR"
if [ "$?" = "0" ]; then
echo "OK"
else
echo "Failed"
exit 28
fi
fi
# Change directory permissions for the images folder # Change directory permissions for the images folder
echo -n "Changing permissions of the images folder to 775... " echo -n "Changing permissions of the images folder to 775... "
chmod 775 "$ZM_PATH_CONTENT/images" chmod 775 "$ZM_PATH_CONTENT/images"
@ -251,7 +355,6 @@ else
exit 30 exit 30
fi fi
# Change directory permissions for the events folder # Change directory permissions for the events folder
echo -n "Changing permissions of the events folder to 775... " echo -n "Changing permissions of the events folder to 775... "
chmod 775 "$ZM_PATH_CONTENT/events" chmod 775 "$ZM_PATH_CONTENT/events"
@ -262,9 +365,9 @@ else
exit 31 exit 31
fi fi
# Link the CakePHP tmp folder to /var/tmp # Change directory permissions for the log folder
echo -n "Linking CakePHP folder to /var/tmp" echo -n "Changing permissions of the log folder to 775... "
ln -sf /var/tmp "$ZM_PATH_WEB/api/app" chmod 775 "$ZM_LOGDIR"
if [ "$?" = "0" ]; then if [ "$?" = "0" ]; then
echo "OK" echo "OK"
else else
@ -272,5 +375,25 @@ else
exit 32 exit 32
fi fi
# Change directory permissions for the temp folder
echo -n "Changing permissions of the temp folder to 775... "
chmod 775 "$ZM_TMPDIR"
if [ "$?" = "0" ]; then
echo "OK"
else
echo "Failed"
exit 33
fi
# Link the CakePHP tmp folder to the zoneminder temp folder
echo -n "Linking CakePHP tmp folder to ${ZM_TMPDIR}... "
ln -sf "$ZM_TMPDIR" "$ZM_PATH_WEB/api/app"
if [ "$?" = "0" ]; then
echo "OK"
else
echo "Failed"
exit 40
fi
echo "" echo ""
echo "All done" echo "All done"