docker-mailserver/target/bin/addmailuser
Jack Twilley 6d2d9dd738 Handle missing files more gracefully. (#265)
* Wrote functional tests for desired behavior.

Redoing the pull request, starting from current master.

The tests now fail where expected.

* Updated commands to handle missing files better.

The functional tests now pass.
2016-08-24 10:06:59 +02:00

30 lines
571 B
Bash
Executable file

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