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