Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
c63ba175
Unverified
Commit
c63ba175
authored
Jan 11, 2022
by
Marc Cornellà
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(installer): simplify `user_can_sudo` check
parent
a0a949de
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
install.sh
tools/install.sh
+6
-6
No files found.
tools/install.sh
View file @
c63ba175
...
...
@@ -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 provid
ed
# 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 requir
ed
#
# 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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment