func badParam to handle missing or invalid params

This commit is contained in:
Asif Bacchus 2019-05-23 21:24:29 -06:00
parent 2f8271e636
commit 5e985f941e

View File

@ -18,6 +18,20 @@ mag="\e[95m"
### functions
# bad parameter passed to script
badParam () {
if [ "$1" = "empty" ]; then
printf "${err}\nError: '%s' cannot have a NULL (empty) value.\n" "$2"
printf "${cyan}Please use '--help' for assistance${normal}\n\n"
exit 1
elif [ "$1" = "dne" ]; then
printf "${err}\nError: '%s %s'\n" \
"$2" "$3"
printf "file or directory does not exist.\n\n"
exit 1
fi
}
# control seafile services (systemd)
seafSvc () {
if [ "$1" = "start" ]; then
@ -90,7 +104,7 @@ while [ $# -gt 0 ]; do
logFile="${2%/}"
shift
else
badParam "$@"
badParam empty "$@"
fi
;;
-v|--verbose)
@ -101,10 +115,14 @@ while [ $# -gt 0 ]; do
-c|--config|--details)
# location of config details file
if [ -n "$2" ]; then
configDetails="${2%/}"
shift
if [ -f "$2" ]; then
configDetails="${2%/}"
shift
else
badParam dne "$@"
fi
else
badParam "$@"
badParam empty "$@"
fi
;;
-5|--503)
@ -114,7 +132,7 @@ while [ $# -gt 0 ]; do
err503File="${2##*/}"
shift
else
badParam "$@"
badParam empty "$@"
fi
;;
-w|--webroot)
@ -123,7 +141,7 @@ while [ $# -gt 0 ]; do
webroot="${2%/}"
shift
else
badParam "$@"
badParam empty "$@"
fi
;;
-p|--seaf|--seafdir)
@ -132,7 +150,7 @@ while [ $# -gt 0 ]; do
seafDir="${2%/}"
shift
else
badParam "$@"
badParam empty "$@"
fi
;;
-d|--data|--datadir|--seafdata)
@ -141,7 +159,7 @@ while [ $# -gt 0 ]; do
seafData="${2%/}"
shift
else
badParam "$@"
badParam empty "$@"
fi
;;
-o|--offline)
@ -154,7 +172,7 @@ while [ $# -gt 0 ]; do
seafUser="${2%/}"
shift
else
badParam "$@"
badParam empty "$@"
fi
;;
*)