Source

Nginx Vhost / generate_vhost

Jon Langevin f26e375 































#!/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 "\nYou typed: $VHOST \n"

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

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

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

echo "\nYou typed: $VHOSTIP \n"

VHOSTPATH="$VHOSTDIR$VHOST"
sudo -u www-data cp -Rf "$VHOSTSKEL" "$VHOSTPATH"
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\""