From b770e18e706ba151d3b6af5fa646b50420b83485 Mon Sep 17 00:00:00 2001 From: Ernesto Alfonso Date: Sat, 28 Oct 2023 23:21:34 -0400 Subject: [PATCH 1/2] Add scripting support by optionally reading email, password from environment. --- docker/add-user.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docker/add-user.sh b/docker/add-user.sh index 8bf78be..b2aedf6 100755 --- a/docker/add-user.sh +++ b/docker/add-user.sh @@ -7,16 +7,19 @@ set -e -read -r -p "Email (full user@domain format): " EMAIL +if test -z "${EMAIL:-}"; then + read -r -p "Email (full user@domain format): " EMAIL +fi if ! echo "${EMAIL}" | grep -q @; then echo "Error: email should have '@'." exit 1 fi - -read -r -p "Password: " -s PASSWORD -echo +if test -z "${PASSWORD:-}"; then + read -r -p "Password: " -s PASSWORD + echo +fi DOMAIN=$(echo echo "${EMAIL}" | cut -d '@' -f 2) From f89bb2b565944b428938b383c1b1b18bd83e1c18 Mon Sep 17 00:00:00 2001 From: Ernesto Alfonso Date: Sat, 28 Oct 2023 23:28:05 -0400 Subject: [PATCH 2/2] Fix failing when the sole dovecot user is updated. When a single dovecot user exists and their password is updated, the `grep -v` command intended to remove the user's old password will not match any lines and fail, causing the entire script to fail. --- docker/add-user.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/docker/add-user.sh b/docker/add-user.sh index b2aedf6..9974b1c 100755 --- a/docker/add-user.sh +++ b/docker/add-user.sh @@ -34,11 +34,7 @@ ENCPASS=$(doveadm pw -u "${EMAIL}" -p "${PASSWORD}") # Edit dovecot users: remove user if it exits. mkdir -p /data/dovecot touch /data/dovecot/users -if grep -q "^${EMAIL}:" /data/dovecot/users; then - cp /data/dovecot/users /data/dovecot/users.old - grep -v "^${EMAIL}:" /data/dovecot/users.old \ - > /data/dovecot/users -fi +sed --in-place=.old "/^${EMAIL}:/d" /data/dovecot/users # Edit dovecot users: add user. echo "${EMAIL}:${ENCPASS}::::" >> /data/dovecot/users