skiqqy.xyz/nginxd

54 lines
1.2 KiB
Plaintext
Raw Normal View History

2020-10-14 21:28:25 +00:00
#!/bin/bash
# @Auther skiqqy
2020-10-14 21:47:47 +00:00
# This script is best run as root inside the root of this repo.
2020-10-14 21:28:25 +00:00
# This script allows me to enable/disable certain sections of my website.
help_menu () {
echo "Welcome!"
echo -e "e\t->\tEnable a unit."
echo -e "d\t->\tDisable a unit."
2020-10-14 21:54:48 +00:00
echo -e "u\t->\tSpecify the path to the units directory"
2020-10-14 21:28:25 +00:00
echo -e "h\t->\tShows this message."
}
error () {
2020-10-14 21:47:47 +00:00
# error [message] [exit code]
2020-10-14 21:28:25 +00:00
echo "[ERROR] $1"
exit $2
}
2020-10-14 21:47:47 +00:00
link () {
# links available site to enabled.
# link [unit]
[ ! -f /etc/nginx/sites-available/$1 ] && error "The unit <$1> file cannot be linked" 1
ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/$1
}
2020-10-14 21:54:48 +00:00
while getopts "he:d:u:" opt
2020-10-14 21:28:25 +00:00
do
case $opt in
h)
help_menu
;;
e | d)
2020-10-14 21:47:47 +00:00
[ ! -z $unit ] && error "Unit <$unit> already set." 1
2020-10-14 21:28:25 +00:00
[[ $opt == "e" ]] && oper=e || oper=d
unit="$OPTARG"
;;
2020-10-14 21:54:48 +00:00
u)
[ -d "$OPTARG" ] && unitsd="$OPTARG" || error "Not <$OPTARG> a valid directory" 1
;;
2020-10-14 21:28:25 +00:00
*)
exit 2
;;
esac
done
2020-10-14 21:47:47 +00:00
# Available units
units=( git blog wiki irc proj all )
2020-10-14 21:54:48 +00:00
unitsd=${unitsd-"./units"}
2020-10-14 21:47:47 +00:00
# Check that a valid unit was given.
[[ ! " ${units[@]} " =~ " ${unit} " ]] && error "The unit <$unit> does not exist." 1 \
|| echo "Unit <$unit> found!"