Created
August 31, 2012 11:53
-
-
Save linuslundahl/3551848 to your computer and use it in GitHub Desktop.
Linode vhost script
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 | |
# | |
# ======================= | |
# Linode vhost script | |
# ======================= | |
function make_vhost | |
{ | |
cat <<- _EOF_ | |
<VirtualHost *:80> | |
ServerAdmin [email protected] | |
ServerName $dname | |
ServerAlias *.$dname | |
DocumentRoot /srv/www/$dname/public_html/ | |
ErrorLog /srv/www/$dname/logs/error.log | |
CustomLog /srv/www/$dname/logs/access.log combined | |
<Directory /srv/www/$dname/public_html/> | |
Options FollowSymLinks | |
AllowOverride All | |
Order allow,deny | |
allow from all | |
</Directory> | |
</VirtualHost> | |
_EOF_ | |
} | |
# ======================= | |
# header | |
# ======================= | |
clear | |
echo "*** Virtual host setup ***" | |
# ======================= | |
# set domain name variable | |
# ======================= | |
echo " " | |
echo -n "Enter domain name: " | |
read dname | |
echo " " | |
echo "Setting up files for $dname" | |
# ======================= | |
# create needed directories | |
# ======================= | |
echo " " | |
mkdir -vp /srv/www/$dname | |
mkdir -vp /srv/www/$dname/public_html | |
mkdir -vp /srv/www/$dname/logs | |
echo " " | |
touch /srv/www/$dname/logs/access.log | |
echo "created /srv/www/$dname/logs/access.log" | |
touch /srv/www/$dname/logs/error.log | |
echo "created /srv/www/$dname/logs/error.log" | |
# ======================= | |
# build vhost config file | |
# ======================= | |
echo " " | |
make_vhost > /etc/apache2/sites-available/$dname | |
echo "created /etc/apache2/sites-available/$dname" | |
cd /srv/www/$dname/public_html | |
# ======================= | |
# add git repo | |
# ======================= | |
echo " " | |
while true; do | |
read -p "Initialize empty Git repository? $" yn | |
case $yn in | |
[Yy]* ) git init; touch README; git add .; git commit -m "Initial commit."; git checkout -b live; break;; | |
[Nn]* ) break;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
# ======================= | |
# enable site | |
# ======================= | |
echo " " | |
while true; do | |
read -p "Enable site? $" yn | |
case $yn in | |
[Yy]* ) a2ensite $dname; service apache2 reload; break;; | |
[Nn]* ) break;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
# ======================= | |
# exit | |
# ======================= | |
echo " " | |
echo "*** Finished setting up files for $dname." | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup
cd ~/bin
wget https://gist.github.com/raw/3551848/2da4ca6592acb9f124e34aeda2c0b3d77c2e93e3/siteup
chmod 755 siteup