diff options
author | Marc Cornellà <hello@mcornella.com> | 2022-01-11 19:53:50 +0100 |
---|---|---|
committer | Marc Cornellà <hello@mcornella.com> | 2022-01-11 19:53:50 +0100 |
commit | c63ba17525b0b4344729762253c9d9e1c0823d49 (patch) | |
tree | 2d74c4e49abc65b199f0fd2ea08bf290f2f7fe65 /tools/install.sh | |
parent | a0a949de56f7bc63403c521bfb1d7426843ec5b7 (diff) | |
download | zsh-c63ba17525b0b4344729762253c9d9e1c0823d49.tar.gz zsh-c63ba17525b0b4344729762253c9d9e1c0823d49.tar.bz2 zsh-c63ba17525b0b4344729762253c9d9e1c0823d49.zip |
refactor(installer): simplify `user_can_sudo` check
Diffstat (limited to 'tools/install.sh')
-rwxr-xr-x | tools/install.sh | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/tools/install.sh b/tools/install.sh index b7498fa64..d3f1ee640 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -64,18 +64,18 @@ user_can_sudo() { # • without privilege: exits with error code 1 and prints the message: # Sorry, user <username> may not run sudo on <hostname> # - # 2. Pass `-S` to `sudo` to tell it to get the password from stdin - # instead of from a tty, and pipe `true` to `sudo`, since it doesn't - # output anything. This will make sudo exit with error code 1 and print - # the message: - # sudo: no password was provided + # 2. Pass `-n` to `sudo` to tell it to not ask for a password. If the + # password is not required, the command will finish with exit code 0. + # If one is required, sudo will exit with error code 1 and print the + # message: + # sudo: a password is required # # 3. Check for the words "may not run sudo" in the output to really tell # whether the user has privileges or not. For that we have to make sure # to run `sudo` in the default locale (with `LANG=`) so that the message # stays consistent regardless of the user's locale. # - true | LANG= sudo -v -S 2>&1 | grep -q "may not run sudo" + LANG= sudo -n -v 2>&1 | grep -q "may not run sudo" } # The [ -t 1 ] check only works when the function is not called from |