Created
May 21, 2014 15:21
-
-
Save michaelbunch/d4840dd1332ef83c4c10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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