Skip to content

Instantly share code, notes, and snippets.

@insane-dev
Created May 5, 2016 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insane-dev/135e025f7de98ec145c73e6e6c91aa19 to your computer and use it in GitHub Desktop.
Save insane-dev/135e025f7de98ec145c73e6e6c91aa19 to your computer and use it in GitHub Desktop.
Command that removes domain dir and its nginx config
#!/bin/bash
# Removedomain command
# ---
# script can run with the domain as a command line input
# `sudo ./nginx_domain.sh my_domain.com` or without and
# the script will prompt the user for input
#
# BTW: You can make it global e.g. by:
# sudo ln -s /opt/delagics/removedomain.sh /usr/bin/removedomain
# Configiguration
web_root='/var/www'
config_dir='/etc/nginx'
if [ -z "$1" ]
then
echo -e "Enter domain name:"
read DOMAIN
echo "Removing Nginx domain settings for: $DOMAIN"
if [ -z "$DOMAIN" ]
then
echo "Domain required"
exit 1
fi
fi
if [ -z "$DOMAIN" ]
then
DOMAIN=$1
fi
sudo unlink $config_dir/sites-enabled/$DOMAIN.conf
sudo rm -f $config_dir/sites-available/$DOMAIN.conf
echo "Removing web directories (recursively)"
sudo rm -rf $web_root/"$DOMAIN"
sudo /etc/init.d/nginx reload
echo "Nginx - reload"
echo "$DOMAIN has been removed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment