skiqqy.xyz/nginxd
2020-10-14 23:47:47 +02:00

49 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
# @Auther skiqqy
# This script is best run as root inside the root of this repo.
# 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."
echo -e "h\t->\tShows this message."
}
error () {
# error [message] [exit code]
echo "[ERROR] $1"
exit $2
}
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
}
while getopts "he:d:" opt
do
case $opt in
h)
help_menu
;;
e | d)
[ ! -z $unit ] && error "Unit <$unit> already set." 1
[[ $opt == "e" ]] && oper=e || oper=d
unit="$OPTARG"
;;
*)
exit 2
;;
esac
done
# Available units
units=( git blog wiki irc proj all )
# Check that a valid unit was given.
[[ ! " ${units[@]} " =~ " ${unit} " ]] && error "The unit <$unit> does not exist." 1 \
|| echo "Unit <$unit> found!"