More error checking

This commit is contained in:
Stephen Cochrane 2020-10-14 23:54:48 +02:00
parent 364cc3122a
commit 8407cc7373
1 changed files with 6 additions and 1 deletions

7
nginxd
View File

@ -7,6 +7,7 @@ help_menu () {
echo "Welcome!" echo "Welcome!"
echo -e "e\t->\tEnable a unit." echo -e "e\t->\tEnable a unit."
echo -e "d\t->\tDisable a unit." echo -e "d\t->\tDisable a unit."
echo -e "u\t->\tSpecify the path to the units directory"
echo -e "h\t->\tShows this message." echo -e "h\t->\tShows this message."
} }
@ -23,7 +24,7 @@ link () {
ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/$1 ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/$1
} }
while getopts "he:d:" opt while getopts "he:d:u:" opt
do do
case $opt in case $opt in
h) h)
@ -34,6 +35,9 @@ do
[[ $opt == "e" ]] && oper=e || oper=d [[ $opt == "e" ]] && oper=e || oper=d
unit="$OPTARG" unit="$OPTARG"
;; ;;
u)
[ -d "$OPTARG" ] && unitsd="$OPTARG" || error "Not <$OPTARG> a valid directory" 1
;;
*) *)
exit 2 exit 2
;; ;;
@ -42,6 +46,7 @@ done
# Available units # Available units
units=( git blog wiki irc proj all ) units=( git blog wiki irc proj all )
unitsd=${unitsd-"./units"}
# Check that a valid unit was given. # Check that a valid unit was given.
[[ ! " ${units[@]} " =~ " ${unit} " ]] && error "The unit <$unit> does not exist." 1 \ [[ ! " ${units[@]} " =~ " ${unit} " ]] && error "The unit <$unit> does not exist." 1 \