2016-06-14 11:16:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
DATABASE=/tmp/docker-mailserver/postfix-accounts.cf
|
|
|
|
|
|
|
|
function usage {
|
2016-07-12 15:40:08 +00:00
|
|
|
echo 'Usage: addmailuser <user@domain.tld> [password]'
|
2016-06-14 11:16:11 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ ! -z "$1" ]; then
|
|
|
|
USER=$1
|
|
|
|
if [ ! -z "$(grep $USER -i $DATABASE)" ]; then
|
|
|
|
echo "User already exists"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ ! -z "$2" ]; then
|
2016-07-12 15:40:08 +00:00
|
|
|
PASS="$2"
|
2016-06-14 11:16:11 +00:00
|
|
|
else
|
|
|
|
read -s -p "Enter Password: " PASS
|
|
|
|
if [ -z "$PASS" ]; then
|
|
|
|
echo "Password can't be empty"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2016-07-12 15:40:08 +00:00
|
|
|
ENTRY=$(echo "$USER|$(doveadm pw -s SHA512-CRYPT -u "$USER" -p "$PASS")")
|
2016-06-14 11:28:15 +00:00
|
|
|
echo "$ENTRY" >> $DATABASE
|
2016-06-14 11:16:11 +00:00
|
|
|
else
|
|
|
|
usage
|
|
|
|
fi
|