#!/bin/sh # interface to add email address to postfix/courier-imap # written and copyright by Mads Joergensen (software@mads.sulau.dk) # a hot summer day in spring 2004 # published under the GPL license (see: gpl.txt) # Perl would had been a better choise of language tho, but # the script just evolved out of nowhere # discard path PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin # configuration options # home basedir - no tailing slash MAIL_BASE="/home/vmail" POSTFIX_VIRTUAL="/usr/local/etc/postfix/virtual" POSTFIX_VIRTUAL_MAPS="/usr/local/etc/postfix/virtual_mailbox_maps" COURIER_USERDB="/usr/local/etc/userdb" MAIL_UID=1003 MAIL_GID=1003 # usage - duh if [ -z "$1" ]; then echo "Usage: ${0} " exit 1 fi # split the email adresse - ugly yes couldent figure out how to # do it another way USER=`echo "$1" | { IFS=@ read user domain; echo $user; }` DOMAIN=`echo "$1" | { IFS=@ read user domain; echo $domain; }` HOME="${MAIL_BASE}/${DOMAIN}/${USER}/" POSTFIX_HOME="${DOMAIN}\/${USER}\/" # check that the user does not exist if [ ! -z "`grep -e "^$USER" $POSTFIX_VIRTUAL`" ]; then echo "User exists allready" exit fi # add user to postfix virtual sed -i -e "s/^#$DOMAIN.*---$/&\\ $1 $1/g" $POSTFIX_VIRTUAL # add user to postfix virtual_mailbox_maps sed -i -e "s/^#$DOMAIN.*---$/&\\ $1 $POSTFIX_HOME/g" $POSTFIX_VIRTUAL_MAPS # add user to courier userdb -f ${COURIER_USERDB} "${1}" set home=$HOME mail=$HOME uid=${MAIL_UID} gid=${MAIL_GID} # set the password echo "Setting imap password" userdbpw | userdb -f ${COURIER_USERDB} "${1}" set imappw echo "Rebuilding files ..." makeuserdb postmap $POSTFIX_VIRTUAL_MAPS postmap $POSTFIX_VIRTUAL echo "Reloading postfix" postfix reload # send user a mail so postfix can create the user's homedir echo "Welcome to ${DOMAIN}" | mail -s "welcome to ${DOMAIN}" ${1} echo "Done"