#!/bin/sh WEBROOT="$HOME/www/" VHOSTDIR="/etc/apache2/sites-available/" NGINXDIR="/etc/nginx/sites-available/" NGINXENABLEDDIR="/etc/nginx/sites-available/" EXTENSION=".conf" RESTARTCMD="/usr/bin/sudo service apache2 reload" RESTARTCMD_NGINX="/usr/bin/sudo service nginx reload" if [ "$1" != '' ]; then if [ ! -f "$VHOSTDIR$1.conf" ]; then sudo cp "$VHOSTDIR/template.conf" "$VHOSTDIR$1$EXTENSION" echo "created $VHOSTDIR$1$EXTENSION" else sudo mv "$VHOSTDIR$1.conf" "$VHOSTDIR$1$EXTENSION.bak" sudo cp "$VHOSTDIR/template.conf" "$VHOSTDIR$1$EXTENSION" echo "created $VHOSTDIR$1$EXTENSION and made a backup of the existing conf" fi sudo find "$VHOSTDIR$1$EXTENSION" -type f -exec sed -i -e "s,SITENAME,$1,g" -e "s,PATH,$WEBROOT,g" {} \; if [ ! -f "$NGINXDIR$1.conf" ]; then sudo cp "$NGINXDIR/template.conf" "$NGINXDIR$1$EXTENSION" echo "created $NGINXDIR$1$EXTENSION" else sudo mv "$NGINXDIR$1.conf" "$NGINXDIR$1$EXTENSION.bak" sudo cp "$NGINXDIR/template.conf" "$NGINXDIR$1$EXTENSION" echo "created $NGINXDIR$1$EXTENSION and made a backup of the existing conf" fi sudo find "$NGINXDIR$1$EXTENSION" -type f -exec sed -i -e "s,SITENAME,$1,g" -e "s,PATH,$WEBROOT,g" {} \; sudo ln -s "$NGINXDIR$1$EXTENSION" "$NGINXENABLEDDIR$1$EXTENSION" if [ ! -d "$WEBROOT$1/" ]; then sudo mkdir -p "$WEBROOT$1/public" sudo chown -R www-data:www-data "$WEBROOT$1/" echo "created $WEBROOT$1/" else echo "$WEBROOT$1/ already exists" fi sudo a2ensite $1 $RESTARTCMD echo "reloaded apache" $RESTARTCMD_NGINX echo "reloaded nginx" elif [ "$1" = 'help' ] || [ "$1" = '' ]; then echo "usage:" echo "sudo addwebsite " echo "example: to create hostname.localhost just run the command 'sudo addwebsite hostname.localhost'" fi sudo chown -R www-data:www-data $WEBROOT # sudo chgrp -R www-data $WEBROOT sudo chmod -R g+rwxs $WEBROOT # sed -i "127.0.0.1 $1.local" /etc/hosts