-
Notifications
You must be signed in to change notification settings - Fork 60
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
Conversation
Hi! Thank you for sending this! While using I am worried that what makes the change work for you could be the removal of the So I think I need to understand the problem better. Can you send the contents of the users file the current script is failing on? How did you generate it? Thank you! |
b556f70
to
9157305
Compare
Here is an example repro script: #!/bin/bash -x
set -e
# prelude setting up /data/dovecot/users
sudo mkdir -p /data/dovecot/
sudo chown -R $(whoami) /data
cat <<EOF > /data/dovecot/users
[email protected]:{CRYPT}$2y$05$gTTsE0TKRLke8d8H/qIKhfyQf0HCdZ17mh975LdHfTMZbPhmVQ/56::::
EOF
[email protected]
# code from add-users.sh
mkdir -p /data/dovecot
touch /data/dovecot/users
if grep -q "^${EMAIL}:" /data/dovecot/users; then
cp /data/dovecot/users /data/dovecot/users.old
# the next command will fail
grep -v "^${EMAIL}:" /data/dovecot/users.old \
> /data/dovecot/users
fi
echo "success" # this line never runs Basically the The removal of the |
Thank you for the details!
Oooohhhh I see, the problem is the exit value of
Thank you, now I get where the problem is. I'll have one comment inline on the patch, but this seems fine to me, thank you!
Great, thanks! Glad to rule that out too. |
docker/add-user.sh
Outdated
grep -v "^${EMAIL}:" /data/dovecot/users.old \ | ||
> /data/dovecot/users | ||
fi | ||
sed -i "/^${EMAIL}:/d" /data/dovecot/users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use sed --in-place=.old
instead of sed -i
, so it leaves the previous file around just in case there are issues?
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
docker/add-user.sh
Outdated
@@ -7,15 +7,14 @@ | |||
|
|||
set -e | |||
|
|||
read -r -p "Email (full user@domain format): " EMAIL | |||
test -n "${EMAIL:-}" || read -r -p "Email (full user@domain format): " EMAIL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you replace this with:
if test -z "${EMAIL}"; then
read -r -p "Email (full user@domain format): " EMAIL
fi
It should be the same effect, and I am okay with the change, I just find this form more readable in this case.
Is that okay with you? What do you think?
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
9157305
to
a937900
Compare
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.
a937900
to
f89bb2b
Compare
…bles This patch extends docker/add-user.sh to support getting the email and password from environment variables. That way, docker/add-user.sh can be used in scripts. #43 Amended-by: Alberto Bertogli <[email protected]> Minor edits to the commit message.
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. #43 Amended-by: Alberto Bertogli <[email protected]> Minor edits to the commit message.
docker/add-user.sh
: Don't crash on updating when there is a single user
Looks great to me. Thanks for the quick response. |
When a single dovecot user exists and their password is updated,
the
grep -v
command intended to remove the user's old passwordwill not match any lines and fail, causing the entire script to fail.