#!/bin/bash SITENAME=$1 SITEPATH=$2 #PATH="$HOME/bin:$PATH" #check if root if [ $EUID -ne 0 ]; then echo "run with sudo or as root" exit fi #check for 2 params if [ $# != 2 ]; then echo "Require 2 arguments" echo "usage: addsite sitename /path/to/documentroot" exit fi #create config file echo "creating config file" echo " ServerName $SITENAME DocumentRoot $SITEPATH Options Indexes MultiViews AllowOverride All Order allow,deny Allow from all php_value date.timezone America/Toronto " > /etc/apache2/sites-available/$SITENAME #enable site a2ensite -q $SITENAME #add to /etc/hosts if not already existing echo "adding to /etc/hosts" grep "127.0.0.1 $SITENAME" /etc/hosts > /dev/null if [ $? -ne 0 ]; then #echo "adding" echo "127.0.0.1 $SITENAME" >> /etc/hosts fi mkdir -p $SITEPATH #restart apache apache2ctl graceful &>1 echo "done"