Skip to content

Instantly share code, notes, and snippets.

@BytewaveMLP
Created December 24, 2017 20:54
Show Gist options
  • Save BytewaveMLP/44c177e441e484b00dc2b53023c1f57e to your computer and use it in GitHub Desktop.
Save BytewaveMLP/44c177e441e484b00dc2b53023c1f57e to your computer and use it in GitHub Desktop.
#/bin/bash
op="$1"
site="$2"
script="$0"
error_exit() {
echo "$(basename "$script"): $1" >&2
exit $2
}
case "$op" in
"enable")
if [ ! -f "/etc/nginx/sites-available/$site" ]; then
error_exit "invalid site: $site" 2
fi
if [ -f "/etc/nginx/sites-enabled/$site" ]; then
error_exit "site already enabled: $site" 2
fi
sudo ln -s "/etc/nginx/sites-available/$site" "/etc/nginx/sites-enabled/$site"
error_exit "site enabled: $site" 0
;;
"disable")
if [ ! -f "/etc/nginx/sites-enabled/$site" ]; then
error_exit "invalid site: $site" 2
fi
sudo rm "/etc/nginx/sites-enabled/$site"
error_exit "site disabled: $site" 0
;;
*)
error_exit "invalid operation: $op" 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment