Posts Tagged ‘Rapid Deployment Tips’

Shell Script to add a project to your local webserver

Friday, June 12th, 2009

Just finished a fun script, basically everytime I have to create a project on my apache2 localhost (debian based linux mint 64 ) I’ve had to copy over the scripts I use all the time, my normal layout etc.. well now I’ve developed my own rapid create tool.

I’ve built a shell script that prompts for the project name, then the project home folder and based on those answers creates the directory, creates an image dir, a scripts dir with subdirectories of php and js then copies those related scripts. After copying files it then creates a template index.html with calls to the copied scripts, and the touched stylesheet.

Once the script is done copying and creating files, it then adds the new address to my /etc/hosts file and creates an /etc/apache2/sites-available/host.rob file ( all my local addresses are .rob instead of .com ) and then makes the symbolic link to sites-enabled and finally restarts my webserver.

Here is the script

#!/bin/sh

tempp=”/var/www/template”

echo “Project Name:”
read pname

echo “Project Home Dir: (/var/www/) no spaces ”
read ppath

mkdir /var/www/$ppath
mkdir /var/www/$ppath/scripts
mkdir /var/www/$ppath/scripts/js
mkdir /var/www/$ppath/scripts/js/jquery
mkdir /var/www/$ppath/scripts/php
mkdir /var/www/$ppath/scripts/php/php_mailer
mkdir /var/www/$ppath/images
mkdir /var/www/$ppath/bak

cp $tempp/jquery.js /var/www/$ppath/scripts/js/jquery
cp $tempp/email.js /var/www/$ppath/scripts/js
cp -r $tempp/php_mailer/* /var/www/$ppath/scripts/php/php_mailer
cp $tempp/index.html /var/www/$ppath/
cp $tempp/styles.css /var/www/$ppath/
cp $tempp/sendmail.php /var/www/$ppath
cp $tempp/.htaccess /var/www/$ppath
cp $tempp/png-img.php /var/www/$ppath/scripts/php

echo “Root Password\a”
su -c “echo Running as root”

echo “127.0.1.1 $ppath.rob” | sudo tee -a /etc/hosts
echo “127.0.1.1 www.$ppath.rob” | sudo tee -a /etc/hosts

touch /etc/apache2/sites-available/$ppath.rob

echo “<VirtualHost *:80>” | sudo tee -a /etc/apache2/sites-available/$ppath.rob
echo ” ServerAdmin rob@robertsandusky.com” | sudo tee -a /etc/apache2/sites-available/$ppath.rob
echo ” ServerName $ppath.rob” | sudo tee -a /etc/apache2/sites-available/$ppath.rob
echo ” ServerAlias www.$ppath.rob” | sudo tee -a /etc/apache2/sites-available/$ppath.rob
echo ” DocumentRoot /var/www/$ppath” | sudo tee -a /etc/apache2/sites-available/$ppath.rob
echo “</VirtualHost>” | sudo tee -a /etc/apache2/sites-available/$ppath.rob

sudo ln -s /etc/apache2/sites-available/$ppath.rob /etc/apache2/sites-enabled/

sudo /etc/init.d/apache2 restart

echo “Project $pname has been created succesfully visit $ppath.rob to begin”