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 ### 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) # control seafile services (systemd)
seafSvc () { seafSvc () {
if [ "$1" = "start" ]; then if [ "$1" = "start" ]; then
@ -90,7 +104,7 @@ while [ $# -gt 0 ]; do
logFile="${2%/}" logFile="${2%/}"
shift shift
else else
badParam "$@" badParam empty "$@"
fi fi
;; ;;
-v|--verbose) -v|--verbose)
@ -101,10 +115,14 @@ while [ $# -gt 0 ]; do
-c|--config|--details) -c|--config|--details)
# location of config details file # location of config details file
if [ -n "$2" ]; then if [ -n "$2" ]; then
configDetails="${2%/}" if [ -f "$2" ]; then
shift configDetails="${2%/}"
shift
else
badParam dne "$@"
fi
else else
badParam "$@" badParam empty "$@"
fi fi
;; ;;
-5|--503) -5|--503)
@ -114,7 +132,7 @@ while [ $# -gt 0 ]; do
err503File="${2##*/}" err503File="${2##*/}"
shift shift
else else
badParam "$@" badParam empty "$@"
fi fi
;; ;;
-w|--webroot) -w|--webroot)
@ -123,7 +141,7 @@ while [ $# -gt 0 ]; do
webroot="${2%/}" webroot="${2%/}"
shift shift
else else
badParam "$@" badParam empty "$@"
fi fi
;; ;;
-p|--seaf|--seafdir) -p|--seaf|--seafdir)
@ -132,7 +150,7 @@ while [ $# -gt 0 ]; do
seafDir="${2%/}" seafDir="${2%/}"
shift shift
else else
badParam "$@" badParam empty "$@"
fi fi
;; ;;
-d|--data|--datadir|--seafdata) -d|--data|--datadir|--seafdata)
@ -141,7 +159,7 @@ while [ $# -gt 0 ]; do
seafData="${2%/}" seafData="${2%/}"
shift shift
else else
badParam "$@" badParam empty "$@"
fi fi
;; ;;
-o|--offline) -o|--offline)
@ -154,7 +172,7 @@ while [ $# -gt 0 ]; do
seafUser="${2%/}" seafUser="${2%/}"
shift shift
else else
badParam "$@" badParam empty "$@"
fi fi
;; ;;
*) *)