Created
June 26, 2023 18:55
-
-
Save mnordhoff/c232138f31696d7d3b14c3be571d5bac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_checkSudo() { | |
if [ -z "__INTERACTIVE" ]; then | |
#don't check if it's not in an interactive shell | |
return 0 | |
fi | |
if [ "$SUDO_GID" ] && [ "$SUDO_COMMAND" ] && [ "$SUDO_USER" ] && [ "$SUDO_UID" ]; then | |
if [ "$SUDO_USER" = "root" ] && [ "$SUDO_UID" = "0" ]; then | |
#it's root using sudo, no matter it's using sudo or not, just fine | |
return 0 | |
fi | |
if [ -n "$SUDO_COMMAND" ]; then | |
#it's a normal user doing "sudo su", or `sudo -i` or `sudo -s`, or `sudo su acmeuser1` | |
_endswith "$SUDO_COMMAND" /bin/su || _contains "$SUDO_COMMAND" "/bin/su " || grep "^$SUDO_COMMAND\$" /etc/shells >/dev/null 2>&1 | |
return $? | |
fi | |
#otherwise | |
return 1 | |
fi | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment