#!/bin/sh
# Nico Schottelius
# SSA
#

. `dirname $0`/sub.defaults

case $# in
   3)
      TLD="$1"
      SLD="$2"
      VUSER="$3"
      DOMAIN=${SLD}.${TLD}
      ;;
   4) 
      TLD="$1"
      SLD="$2"
      SUBDOMAIN="$3"
      VUSER="$4"
      DOMAIN=${SUBDOMAIN}.${SLD}.${TLD}
      ;;
   *)
      echo $0: 'TLD SLD [SUBDOMAIN] VUSER'
      exit 1
      ;;
esac

DOTDOMAIN=`echo $DOMAIN | sed 's/\./:/g'`

echo -n "adding qmail entry $DOMAIN for $VUSER ... "

echo "$DOMAIN"  >> $RCPTHOSTS
echo "$DOMAIN:$VUSER-$DOMAIN"  >> $VDOMAINS

# default handling
echo "&$VUSER@$QMAIL_HOST" > /home/user/$VUSER/.qmail-$DOTDOMAIN-default

# moi
echo "&nico@$QMAIL_HOST" > /home/user/$VUSER/.qmail-$DOTDOMAIN-postmaster
echo "&nico@$QMAIL_HOST" > /home/user/$VUSER/.qmail-$DOTDOMAIN-mailer-daemon
echo "&nico@$QMAIL_HOST" > /home/user/$VUSER/.qmail-$DOTDOMAIN-root

# perms
chown $VUSER /home/user/$VUSER/.qmail-$DOTDOMAIN-*

echo -n restarting qmail...

# restart
killall -HUP qmail-send

echo done.