#!/bin/sh # Author: Tony Perrie # File: statcreate.sh # Description: Creates virtualhost and awstats.conf for # new domain name script_filename="/home/jperrie/bin/$1.statgen.sh" httpd_conf_filename="/etc/httpd/conf.d/$1.conf" outputdir=/var/www/html/stats-$1 cronfile=/home/jperrie/cron/jperrie.$(date +%s).cron awstatsconffile=/home/jperrie/awstats/awstats.www.$1.conf if [ -e $outputdir ]; then echo "Error 1: Output Directory: $outputdir already exists." exit fi if [ -e $httpd_conf_filename ]; then echo "Error 2: Configuration File: $httpd_conf_filename already exists." exit fi if [ -e $script_filename ]; then echo "Error 3: Cron Script: $script_filename already exists." exit fi if [ -e $cronfile ]; then echo "Error 7: Crontab: $cronfile already exists." exit fi mkdir $outputdir if [ ! -d $outputdir ]; then echo "Error 6: $outputdir not created" exit fi chgrp apache $outputdir chmod g+rx $outputdir chown jperrie $outputdir cat < $script_filename #!/bin/sh cd ~jperrie/awstats perl /home/jperrie/awstats/awstats.pl -config=www.$1 -update /home/jperrie/awstats/tools/awstats_buildstaticpages.pl -config=www.$1 -dir=$outputdir awstatsprog=/home/jperrie/awstats/awstats.pl ln -fs $outputdir/awstats.www.$1.html $outputdir/index.html EOF if [ ! -e $script_filename ]; then echo "Error 4: Cron Script: $script_filename was not created" exit; fi chown jperrie $script_filename chmod u+wrx $script_filename chmod go-wrx $script_filename cat <>$httpd_conf_filename DocumentRoot /var/www/html/dkstats ServerName stats.$1 ErrorLog logs/$1-error_log CustomLog logs/$1-access_log combined Options All Allow from all deny from none AuthName "restricted stuff" AuthType Basic AuthUserFile /etc/httpd/conf/users require valid-user DirectoryIndex index.htm index.html index.php index.php3 index.php4 EOF if [ ! -e $httpd_conf_filename ]; then echo "Error 5: Httpd Configuration File: $httpd_conf_filename not created." exit fi chgrp apache $httpd_conf_filename chown jperrie $httpd_conf_filename chmod g+r $httpd_conf_filename chmod o-wr $httpd_conf_filename chmod u+rw $httpd_conf_filename /sbin/service httpd stop sleep 2 /sbin/service httpd start cp -f /home/jperrie/cron/jperrie.cron /home/jperrie/cron/jperrie.cron.$(date +%s).backup cat /home/jperrie/cron/jperrie.cron > $cronfile cronheader=$(perl -e " print int(rand(59)).' '.(int(rand(3)+1).' * * *');") echo "$cronheader $script_filename" >>$cronfile crontab $cronfile mv $cronfile /home/jperrie/cron/jperrie.cron chown jperrie /home/jperrie/cron/jperrie.cron chmod go-wrx /home/jperrie/cron/jperrie.cron chmod u+wr /home/jperrie/cron/jperrie.cron cp /home/jperrie/awstats/awstats.example.conf $awstatsconffile arg1=$1 perl -p -i -e "s/#TEMPLATE#/$arg1/g; s/#TEMPLATE1#/$arg1 www.$arg1/g; s/#TEMPLATE2#/$arg1/" $awstatsconffile if [ ! -e $awstatsconffile ]; then echo "Error 8: AWStats Config File: $awstatsconffile could not be created." exit fi chown jperrie $awstatsconffile chmod u+wr $awstatsconffile chmod go-wrx $awstatsconffile