mail/scripts/add_full_member.sh

42 lines
848 B
Bash
Executable File

#!/bin/bash
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
if [ $# -ne 2 ] ; then
echo -e "Params:\t<username> <contact@email>" >&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 base
exit
fi
# Add user
echo -n "Creating POSIX account \"$user\"..."
useradd $user -m -s /bin/bash
echo "[OK]"
# Set default password
echo -n "Setting default password.."
password=$(pwgen -A -B -0 8 1)
echo "$user:$password" | chpasswd
echo "[OK]"
# Add account to members ML
echo -n "Adding mail to member list..."
echo " $user" >> /etc/postfix/virtual_members
postmap /etc/postfix/virtual_members
echo "[OK]"
echo -n "Reloading postfix..."
postfix reload > /dev/null 2>&1
echo "[OK]"
$SCRIPTPATH/sendmail_account.sh $user $email $password