Skip to content

Instantly share code, notes, and snippets.

@linuslundahl
Created August 31, 2012 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linuslundahl/3551848 to your computer and use it in GitHub Desktop.
Save linuslundahl/3551848 to your computer and use it in GitHub Desktop.
Linode vhost script
#! /bin/bash
#
# =======================
# Linode vhost script
# =======================
function make_vhost
{
cat <<- _EOF_
<VirtualHost *:80>
ServerAdmin linus@unwi.se
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
@linuslundahl
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment