From a0f09308ed2e29c1585e2bc3c7b7a26f5241008d Mon Sep 17 00:00:00 2001 From: Ernesto Alfonso Date: Sat, 28 Oct 2023 23:28:05 -0400 Subject: [PATCH] docker/add-user.sh: Don't crash on updating when there is a single user When a single dovecot user exists and their password is being updated via docker/add-user.sh, the `grep -v` command intended to remove the user's old password will not match any lines and exit with error code 1, causing the entire script to fail. This patch fixes it by replacing the if-grep logic with a simpler sed invocation. https://github.com/albertito/chasquid/pull/43 Amended-by: Alberto Bertogli Minor edits to the commit message. --- 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