Skip to content

Instantly share code, notes, and snippets.

@michaelbunch
Created May 21, 2014 15:21
Show Gist options
  • Save michaelbunch/d4840dd1332ef83c4c10 to your computer and use it in GitHub Desktop.
Save michaelbunch/d4840dd1332ef83c4c10 to your computer and use it in GitHub Desktop.
#!/bin/bash
if test -z "$1"
then
echo 'Please supply an action. (add)'
exit 0
else
if [[ "$1" -ne "add" ]] || [[ $1 -ne "scaffold" ]]; then
echo 'Please supply a valid action. [add]'
exit 0
fi
fi
if test -z "$2"
then
echo 'Please supply a domain. [sample.app]'
exit 0
fi
ACTION=$1
HOST=$2
create_vhost()
{
VHOST=/etc/apache2/sites-available/${HOST//./_}.conf
if [[ -e "$VHOST" ]]; then
echo 'This VirtualHost already exists.'
exit 0
fi
touch $VHOST
echo "<VirtualHost $HOST:80>" >> $VHOST
echo " DocumentRoot /srv/www/$HOST/public" >> $VHOST
echo " ServerName $HOST" >> $VHOST
echo " ServerAdmin admin@$HOST" >> $VHOST
echo " " >> $VHOST
echo " <Directory \"/srv/www/$HOST/public\">" >> $VHOST
echo " Options Indexes FollowSymLinks Includes ExecCGI" >> $VHOST
echo " AllowOverride All" >> $VHOST
echo " Order Allow,Deny" >> $VHOST
echo " Allow from all" >> $VHOST
echo " Require all granted" >> $VHOST
echo " </Directory>" >> $VHOST
echo "</VirtualHost>" >> $VHOST
}
create_site()
{
SITEROOT=/srv/www/$HOST
if [[ -d "$SITEROOT" ]]; then
echo "This site already exists."
exit 0
fi
mkdir $SITEROOT
mkdir $SITEROOT/public
}
if [[ "$ACTION" -eq "add" ]]; then
create_vhost
fi
if [[ "$ACTION" -eq "scaffold" ]]; then
create_vhost
create_site
fi
a2ensite ${HOST//./_}.conf
service apache2 reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment