#!/bin/bash
# this script once complete should automatically place
# the files to generated a new website, into the virtualhost
# of apache, it should also add the DNS settings and generate
# a generic index file to start the website off.
#first lets check that the user is in superuser
uid=`id -u $USERNAME`
if [ "$uid" == "0" ]
then
echo "user is root"
else
echo "you need to have root access, run again in sudo"
exit 1
fi
echo "starting program"
# -----------------------------
# now that formality is out of the way, lets start by clearing some workspace
clear
# collect website name
echo "please enter the domain name of website address"
echo "without www; in format 'example.com'."
read webname
echo "ok, creating website www.$webname"
echo ""
# create website directory
mkdir /var/www/www.$webname
# create index file for website
echo "<h1>Index file for $webname</h1>
<p>this is the autogenerated index file for www.$webname<br>
there is no content yet, please upload it</p>" > /var/www/www.$webname/index.html
# state that the website has been generated
echo "website files generated"
echo "generating virtual apache webserver files..."
# add the settings for the new virtual server into apache
echo "<VirtualHost *:80>
ServerAdmin webmaster@$webname
ServerName www.$webname
ServerAlias $webname
# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /var/www/www.$webname/
# CGI Directory
ScriptAlias /cgi-bin/ /var/www/www.$webname/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
</VirtualHost>" > /etc/apache2/sites-available/www.$webname
# ---------------------------------------------------------
#
# -- the website-available file has been generated, lets activate it
echo "****running a2ensite****"
a2ensite www.$webname
echo "****completed a2ensite****"
# -- announced that the script has run
echo ""
echo "adding the DNS entries..."
# ----------------------------------------------
echo "zone \"$webname\" {
type master;
file \"/etc/bind/db.$webname\";
};"
# ----------------------------------------------
echo "ammended named.conf.local"
# generate database file
echo "generating database file db.$webname"
echo ";
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA vicci.$webname. root.$webname. (
1001 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
IN A 192.168.1.84
;
@ IN NS ns.$webname.
@ IN A 192.168.1.84
@ IN AAAA ::1
ns IN A 192.168.1.84
" > /etc/bind/db.$webname
echo "database file written, website generation complete!"
# script completed, rebooting daemons
echo "******************"
echo "restarting daemons"
echo "******************"
service bind9 restart
service apache2 reload
service apache2 restart
echo "daemons have been reset,"
echo "it may be necesary to restart your browser or"
echo "reboot your PC in order to view them!"
echo "..if the page still won't load you may need to reboot the server"
Bookmarks