install script for ubuntu and debian

usage: install_drupal user pass domain dbpass pdname

This script will create a user, apache2 configuration, dns configuration and a user file system read to invoke the Drupal install script;

echo user=$1
echo password=$2
echo domain=$3
echo dbpass=$4
echo dbname=$5
useradd $1 -p `mkpasswd $2` 
mkdir /home/$1
mkdir /home/$1/public_html
cd /home/$1/public_html
tar xzvf drupal-6.6.tar.gz
mv drupal-6.6 $3
mkdir /home/$1/public_html/$3/sites/all/modules
mkdir /home/$1/public_html/$3/sites/all/themes
mkdir /home/$1/public_html/$3/sites/default/files
chmod -R 777 /home/$1/public_html/$3/sites/default/files
cp /home/$1/public_html/$3/sites/default/default.settings.php /home/$1/public_html/$3/sites/default/settings.php
chmod 777 /home/$1/public_html/$3/sites/default/settings.php
chown -R $1.$1 /home/$1
mysql -uroot -p$4 -e "DROP USER '$1'@'localhost';"
mysql -uroot -p$4 -e "DROP DATABASE IF EXISTS $5;"
mysql -uroot -p$4 -e "CREATE USER '$1'@'localhost' IDENTIFIED BY '$2';"
mysql -uroot -p$4 -e "CREATE DATABASE IF NOT EXISTS $5;"
mysql -uroot -p$4 -e "GRANT USAGE ON $5.* TO '$1'@'localhost' IDENTIFIED BY '$2';"
mysql -uroot -p$4 -e "GRANT ALL PRIVILEGES ON $5.* TO '$1'@'localhost';"
mysql -uroot -p$4 -e "flush privileges;"
echo "<VirtualHost *>" >/etc/apache2/sites-available/$3
echo "  DocumentRoot /home/$1/public_html/$3" >>/etc/apache2/sites-available/$3
echo "  ServerName $3" >>/etc/apache2/sites-available/$3
echo "  <Directory /home/$1/public_html/$3>" >>/etc/apache2/sites-available/$3
echo "    allow from all" >>/etc/apache2/sites-available/$3
echo "    AllowOverride AuthConfig FileInfo Indexes Limit Options" >>/etc/apache2/sites-available/$3
echo "    Options FollowSymLinks SymLinksIfOwnerMatch +Indexes" >>/etc/apache2/sites-available/$3
echo "  </Directory>" >>/etc/apache2/sites-available/$3
echo "  ServerAlias www.$3" >>/etc/apache2/sites-available/$3
echo "</VirtualHost>" >>/etc/apache2/sites-available/$3
a2ensite $3
echo "\$TTL 86400" >/etc/bind/$3
echo "$3.	IN	SOA	www.$3. root.$3. (" >>/etc/bind/$3
echo "    `date +%Y%m%d`00" >>/etc/bind/$3
echo "    8H" >>/etc/bind/$3
echo "    2H" >>/etc/bind/$3
echo "    4W" >>/etc/bind/$3
echo "    1D)" >>/etc/bind/$3
echo "    IN NS `hostname`"  >>/etc/bind/$3
echo "$3 A `ifconfig|awk '/Bcast:/ {print $2}'|cut -d":" -f2`" >>/etc/bind/$3
echo "www.$3 A `ifconfig|awk '/Bcast:/ {print $2}'|cut -d":" -f2`" >>/etc/bind/$3
echo "zone \"$3\" {" >>/etc/bind/named.conf.local
echo "  type master;" >>/etc/bind/named.conf.local
echo "  file \"/etc/bind/$3\";" >>/etc/bind/named.conf.local
echo "  };" >>/etc/bind/named.conf.local
echo " $3" >>/etc/hosts
/etc/init.d/bind9 reload
/etc/init.d/apache2 force-reload