Skip to content

Instantly share code, notes, and snippets.

@lottspot
Created January 17, 2013 07:13
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 lottspot/4554284 to your computer and use it in GitHub Desktop.
Save lottspot/4554284 to your computer and use it in GitHub Desktop.
A script used to link sites from a sites-available directory to a sites-enabled directory; for use with web server stacks utilizing both nginx and apache.
#!/bin/bash
APACHE_AVAIL_DIR=/etc/httpd/conf/extra/sites-available
APACHE_EN_DIR=/etc/httpd/conf/extra/sites-enabled
NGINX_AVAIL_DIR=/etc/nginx/servers-available
NGINX_EN_DIR=/etc/nginx/servers-enabled
ARGS=$*
enable_site(){
if [[ ! -h ${APACHE_EN_DIR}/${1} && -f ${APACHE_AVAIL_DIR}/${1} && ! -h ${NGINX_EN_DIR}/${1} && -f ${NGINX_AVAIL_DIR}/${1} ]]
then
ln -s ${APACHE_AVAIL_DIR}/${1} ${APACHE_EN_DIR}/${1}
ln -s ${NGINX_AVAIL_DIR}/${1} ${NGINX_EN_DIR}/${1}
echo "${1} enabled successfully"
else
[[ -h ${APACHE_EN_DIR}/${1} && -h ${NGINX_EN_DIR}/${1} ]] && echo "Site is already enabled"
if [[ ! -f ${APACHE_AVAIL_DIR}/${1} && ! -f ${NGINX_AVAIL_DIR}/${1} ]]
then
echo "Site is not available"
else
[[ ! -f ${APACHE_AVAIL_DIR}/${1} ]] && echo "Apache vhost is not available"
[[ ! -f ${NGINX_AVAIL_DIR}/${1} ]] && echo "Nginx server is not available"
fi
fi
}
disable_site(){
if [[ -h ${APACHE_EN_DIR}/${1} && -h ${NGINX_EN_DIR}/${1} ]]
then
rm ${APACHE_EN_DIR}/${1}
rm ${NGINX_EN_DIR}/${1}
echo "${1} disabled successfully"
else
echo "Site not enabled. Check Apache sites-enabled directory and nginx servers-enabled directory."
fi
}
if [[ ${#ARGS[*]} != 2 ]]
then
case "$1" in
enable|en)
enable_site $2
;;
disable|ds)
disable_site $2
;;
*)
echo "Usage: [enable|disable] [site-name]"
;;
esac
else
echo "Usage: [enable|disable] [site-name]"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment