#!/bin/bash SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" if [ $# -ne 2 ] ; then echo -e "Params:\t " >&2 exit fi user=$1 email=$2 # Check if already existing user if grep -q -e ^$user: /etc/passwd ; then echo User \"$user\" already in posix DB exit fi if grep -q -e "^$user\s" /etc/postfix/virtual_redirect ; then echo User \"$user\" already in redirect DB exit fi # Add user echo -n "Creating POSIX account \"$user\"..." useradd $user -m -s /bin/bash echo "[OK]" # Set default password echo -n "Disabling account" echo "$user:password" | chpasswd passwd -l $user > /dev/null echo "[OK]" # Add account to members ML echo -n "Add account to the member list..." echo " $user" >> /etc/postfix/virtual_members postmap /etc/postfix/virtual_members echo "[OK]" echo -n "Add redirection from $user to $email..." echo " $user $email" >> /etc/postfix/virtual_redirect postmap /etc/postfix/virtual_redirect echo "[OK]" echo -n "Reloading postfix..." postfix reload > /dev/null 2>&1 echo "[OK]" $SCRIPTPATH/sendmail_redirect.sh $user $email