make_vhost.sh

My original "make vhost" script for creating new virtual hosts on my web server at home.

#!/bin/bash
# Raoul's Make Virtual Host script
# Copyright (c) 2006-2009 Raoul Snyman
# Licensed under the GNU GPL v2.0

# Script variables
DOMAIN="lan"
WEBROOT="/home/www-data"
FWDZONE="/etc/bind/zones/lan.zone"
REVZONE="/etc/bind/zones/1.168.192.in-addr.arpa.zone"
SKELFILE="/etc/apache2/skel/skel.domain"
SITESDIR="/etc/apache2/sites-available"
WEBUSER="www-data"
WEBGROUP="www-data"
FWDIP="192.168.1.254"
REVIP="254"
DNSRELOAD="/etc/init.d/bind9 reload"
WEBRELOAD="/etc/init.d/apache2 reload"

# Make our directories
mkdir $WEBROOT/$1
mkdir $WEBROOT/$1/www
mkdir $WEBROOT/$1/logs
mkdir $WEBROOT/$1/cgi-bin
chown -R $WEBUSER:$WEBGROUP $WEBROOT/$1

# Copy the skeleton file and enable it
sed s/skel/$1/ $SKELFILE | sed s/domain/$DOMAIN/ > $SITESDIR/$1.$DOMAIN
a2ensite $1.$DOMAIN

# Create the entry in the forward zone file
echo ";" >> $FWDZONE
echo "; `date`" >> $FWDZONE
echo "$1   IN    A    $FWDIP" >> $FWDZONE

# Create the entry in the reverse zone file
echo ";" >> $REVZONE
echo "; `date`" >> $REVZONE
echo "$REVIP    IN    PTR    $1" >> $REVZONE

#Restart the services
$DNSRELOAD 
$WEBRELOAD