54 lines
1.3 KiB
Bash
Executable file
54 lines
1.3 KiB
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 1
|
|
fi
|
|
|
|
user=$1
|
|
email=$2
|
|
|
|
# Check if already existing user
|
|
if grep -q -e ^$user: /etc/passwd ; then
|
|
|
|
echo Target : $user
|
|
|
|
# Del account from members ML
|
|
echo -n "Deleting mail from member list..."
|
|
pos=$(grep --line-number $user /etc/postfix/virtual_members | cut -d ":" -f 1)
|
|
|
|
if [ -n $pos ] && [ "$pos" -eq "$pos" ] ; then
|
|
echo Found at pos $pos
|
|
sed -i "${pos}d" /etc/postfix/virtual_members
|
|
postmap /etc/postfix/virtual_members
|
|
echo "[OK]"
|
|
fi
|
|
|
|
# Del account from any redirect (if exist)
|
|
echo -n "Deleting mail from member list..."
|
|
pos=$(grep --line-number $user /etc/postfix/virtual_redirect | cut -d ":" -f 1)
|
|
if [ -n $pos ] && [ "$pos" -eq "$pos" ] ; then
|
|
echo Found at pos $pos
|
|
sed -i "${pos}d" /etc/postfix/virtual_redirect
|
|
postmap /etc/postfix/virtual_redirect
|
|
echo "[OK]"
|
|
fi
|
|
|
|
# Del user
|
|
echo -n "Deleting POSIX account \"$user\"..."
|
|
userdel -rf $user
|
|
echo "[OK]"
|
|
|
|
|
|
echo -n "Reloading postfix..."
|
|
postfix reload
|
|
echo "[OK]"
|
|
|
|
$SCRIPTPATH/sendmail_deletion.sh $user $email
|
|
|
|
exit
|
|
fi
|
|
echo User \"$user\" not in base.
|
|
exit 1
|