[vox-tech] script for adding virtual domain to web/mail server

Nick Schmalenberger nschmalenberger at fastmail.fm
Fri Feb 24 03:37:32 PST 2006


list,
I have written this script for adding a virtual domain to a web/mail
server and I'd like some comments or suggestions.


#!/bin/sh

if (($#==0)); then echo -e "Usage: vdomadd USERNAME DOMAIN
[PASSWORD]\nIf password field is 'auto', password will be generated, if
no argument is given login will be disabled, else PASSWORD will be set
as the parameter. If set, the user password is also the postmaster
password for that domain."; exit; fi

USERDIRS=home
USERWEBROOT=$2

if grep $1 /etc/passwd > /dev/null ; then echo -e "Invalid, user
exists."; else
# makes the new account and user web directory
adduser --disabled-login $1
if (($#==3)) 
        if expr $3 : auto; then newpw=`pwgen`
        else newpw=$3
        echo "$1's password is: $newpw"
        echo "$1:$newpw" | chpasswd
else echo "Password parameter blank, login disabled."
mkdir /$USERDIRS/$1/$USERWEBROOT
chown -R $1:$1 /$USERDIRS/$1

#adds new line to /etc/hosts
echo -e "`getip.pl` $2 www.$2 mail.$2" >> /etc/hosts

# makes the apache virtual domain file
echo -e "#virtual domain configuration for $1
<VirtualHost www.$2>
ServerName www.$2
ServerAlias $2
DocumentRoot /$USERDIRS/$1/$USERWEBROOT/
TransferLog /var/log/apache2/$2/www/access.log
LogFormat combined
</VirtualHost>

<VirtualHost mail.$2>
ServerName mail.$2
DocumentRoot /usr/share/squirrelmail/
TransferLog /var/log/apache2/$2/mail/access.log
LogFormat combined
</VirtualHost>
" > /etc/apache2/sites-available/$2
mkdir /var/log/apache2/$2/www/
mkdir /var/log/apache2/$2/mail/
a2ensite $2
/etc/init.d/apache2 reload

touch /var/log/apache2/$2/www/access.log.0
mkdir /$USERDIRS/$1/$USERWEBROOT/stats/
# makes the webalizer configuration file
echo -e "#webalizer configuration for $2 virtual domain
LogFile /var/log/apache2/$2/www/access.log.0
OutputDir /$USERDIRS/$1/$USERWEBROOT/stats/
Hostname www.$2
" > /etc/webalizer.d/$2.conf

# adds domain to qmail
/home/vpopmail/bin/vadddomain $2 $newpw

fi


Thanks,
Nick

-- 
http://www.fastmail.fm - IMAP accessible web-mail



More information about the vox-tech mailing list