Return to Snippet

Revision: 20274
at November 11, 2009 04:18 by jfoucher


Initial Code
#!/bin/bash
CMDLN_ARGS="$@" # Command line arguments for this script
export CMDLN_ARGS

# Run this script as root if not already.
chk_root () {

 if [ ! $( id -u ) -eq 0 ]; then
   echo "Please enter your password."
   exec sudo su -c "${0} ${CMDLN_ARGS}" # Call this prog as root
   exit ${?}  # sice we're 'execing' above, we wont reach this exit
              # unless something goes wrong.
 fi

}
chk_root
FILE=$(cat /etc/hosts)
echo $FILE |grep -o "test$";

if [ `echo $FILE |grep -o "\$1$"` ];
then
  echo "/etc/hosts file is ok"
else
  echo "127.0.0.1         $1" >> /etc/hosts  #ça c'est ok
fi
cp /etc/apache2/sites-available/timetracker /etc/apache2/sites-available/$1
cat /etc/apache2/sites-available/$1 | sed "s/timetracker/$1/g" |cat > /etc/apache2/sites-available/$1
ln -s /etc/apache2/sites-available/$1 /etc/apache2/sites-enabled/$1
if [ -d /home/jonathan/html/$1 ];
then
  echo "host directory exists";
else
  echo "creating directory"
  mkdir "/home/jonathan/html/$1"
fi
chown jonathan /home/jonathan/html/$1
chgrp jonathan /home/jonathan/html/$1
/etc/init.d/apache2 restart

Initial URL

                                

Initial Description

                                

Initial Title
Script to create Apache virtual hosts automatically

Initial Tags
apache

Initial Language
Bash