1
0
mirror of https://github.com/tomav/docker-mailserver.git synced 2024-06-28 20:21:14 +02:00
docker-mailserver/target/bin/addmailuser
Josef Friedrich 69ee54513e Fix build (#286)
The Refactoring of the scripts 'addmailuser' and 'delmailuser'
destroyed the build process.
2016-08-29 07:13:36 +02:00

30 lines
599 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