%%prettify 
{{{
#!/bin/bash

if [ "$#" -lt 3 ] ; then
   echo ""
   echo "Usage : addvirtual dominio utente database"
   echo ""
   exit 0
fi

if [ -f /etc/apache2/conf.d/vhost.d/www.$1.conf ] ; then
   echo ""
   echo "Il virtual server esiste gia'"
   echo ""
   exit 0
fi

if [ -d /home/www/www.$1 ] ; then
   echo ""
   echo "La directory sotto /home/www esiste gia'"
   echo ""
   exit 0
fi

if [  ! -f /opt/template/virtual.conf ] ; then
   echo ""
   echo "Il file /opt/template/virtual.conf non  esiste"
   echo ""
   exit 0
fi

if [ -f /etc/apache2/conf.d/vhost.xml/$1.xml ] ; then
   echo ""
   echo "Il file /etc/apache2/conf.d/vhost.xml/$1.xml esiste gia'"
   echo ""
   exit 0
fi

if [ ! -f /opt/template/template.xml ] ; then
   echo ""
   echo "Il file /opt/template/template.xml non esiste"
   echo ""
   exit 0
fi

# Controllo se l'utente esiste
cat /etc/passwd | grep $2 > /dev/null && echo "L'utente esiste gia'" && exit 0

# Crea il file di configurazione per http
sed -e s/LLLL/$1/g /opt/template/virtual.conf > /etc/apache2/conf.d/vhost.d/www.$1.conf

# Crea il file di configurazione per xml
sed -e s/LLLL/$1/g /opt/template/template.xml | sed -e s/DDDD/$3/g - > /etc/apache2/conf.d/vhost.xml/$1.xml

# Crea le directory di lavoro
cp -a /home/www/skel /home/www/www.$1

# Crea il file di configurazione per Webalizer
sed -e s/LLLL/$1/g /opt/template/webalizer.conf > /home/www/www.$1/logs/webalizer.$1.conf
}}}
/%