Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker/add-user.sh: Don't crash on updating when there is a single user #43

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions docker/add-user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -31,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
Expand Down