Source

Nginx Vhost / generate_vhost

#!/bin/bash
set -e
VHOSTDIR=/var/www
VHOSTSKEL=/var/www/.skel/vhost-default

echo -e "Specify the vhost domain name:"
read VHOST

if [ "$VHOST" = "" ] ; then
	echo "Invalid domain!"
	exit 1;
fi

echo "You typed: $VHOST"

IP=`ifconfig | grep 'inet addr:'| grep -v ':127.*' | grep -v ':192.*' | grep -v ':10.*' | cut -d: -f2 | awk '{ print $1}'`;

echo "Specify the vhost IP from the list of available Public IPs:"
echo -e "$IP"

read VHOSTIP

if [ "$VHOSTIP" = "" ] ; then
        echo "Invalid IP!"
        exit 1;
fi

echo "You typed: $VHOSTIP"

VHOSTPATH="$VHOSTDIR/$VHOST"
sudo -u www-data cp -Rf "$VHOSTSKEL/" "$VHOSTPATH"
sudo -u www-data ack-grep -l VHOSTDIR $VHOSTPATH/conf/* | xargs -t -n 1 sed -i -e "s@VHOSTDIR@$VHOSTDIR@g"
sudo -u www-data ack-grep -l DOMAIN $VHOSTPATH/conf/* | xargs -t -n 1 sed -i -e "s@DOMAIN@$VHOST@g"
sudo -u www-data ack-grep -l SERVERIP $VHOSTPATH/conf/* | xargs -t -n 1 sed -i -e "s@SERVERIP@$VHOSTIP@g"
echo "Skeleton copied to \"$VHOSTPATH\""