Created
January 4, 2014 22:25
-
-
Save fideloper/8261546 to your computer and use it in GitHub Desktop.
Nginx scripts for enable and disabling a site. This will create or destroy a symlink between a real config file in /etc/nginx/sites-available and a symlink in /etc/nginx/sites-enabled.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ $EUID -ne 0 ]; then | |
echo "You must be root: \"sudo ngxdis\"" | |
exit 1 | |
fi | |
# -z str: Returns True if the length of str is equal to zero. | |
if [ -z "$1" ]; then | |
echo "Please choose a site." | |
exit 1 | |
else | |
echo "Disabling site $1..." | |
# -h filename: True if file exists and is a symbolic link. | |
# -f filename: Returns True if file, filename is an ordinary file. | |
if [ ! -h "/etc/nginx/sites-enabled/$1" ] && [ ! -f "/etc/nginx/sites-enabled/$1" ]; then | |
echo "$1 is not enabled." | |
exit 1 | |
else | |
rm /etc/nginx/sites-enabled/$1 | |
echo "Disabled $1" | |
fi | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ $EUID -ne 0 ]; then | |
echo "You must be root: \"sudo ngxen\"" | |
exit 1 | |
fi | |
# -z str: Returns True if the length of str is equal to zero. | |
if [ -z "$1" ]; then | |
echo "Please choose a site." | |
exit 1 | |
else | |
echo "Enabling site $1..." | |
# -h filename: True if file exists and is a symbolic link. | |
# -f filename: Returns True if file, filename is an ordinary file. | |
if [ -h "/etc/nginx/sites-enabled/$1" ] || [ -f "/etc/nginx/sites-enabled/$1" ]; then | |
echo "$1 is already enabled." | |
exit 1 | |
else | |
if [ ! -f "/etc/nginx/sites-available/$1" ]; then | |
echo "Site $1 does not exist in /etc/nginx/sites-available." | |
exit 1 | |
else | |
ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled/$1 | |
echo "Enabled $1" | |
exit 0 | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you bro!