Created
October 31, 2020 21:36
-
-
Save h8rt3rmin8r/1c66c2f543c1572745978afa40365e8e to your computer and use it in GitHub Desktop.
Run a quick test for access to "sudo"
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
#!/usr/bin/env bash | |
#>------------------------------------------------------------------------------ | |
#> | |
#> [ root-test ] | |
#> | |
#> Run a quick test for access to "sudo" | |
#> | |
#> No inputs are required when invoking this function. Outputs are printed | |
#> to STDOUT as either "PASS" or "FAIL" and corresponding exit codes are | |
#> emitted. | |
#> | |
#> USAGE: | |
#> | |
#> ./root-test <OPTION> | |
#> | |
#> where "OPTION" is an optional input; and where "OPTION" is one of the | |
#> following: | |
#> | |
#> | | |
#> -h, --help | Print this help text to the terminal | |
#> | | |
#> -s, --silent | Suppress verbosity messages (only exit codes are emitted) | |
#> | | |
#> | |
#> ATTRIBUTION: | |
#> | |
#> Created on 20201031 by h8rt3rmin8r ([email protected]) | |
#> | |
#> Source: | |
#> https://gist.github.com/h8rt3rmin8r/1c66c2f543c1572745978afa40365e8e | |
#> | |
#>------------------------------------------------------------------------------ | |
function _help() { | |
cat "${0}" \ | |
| grep -E '^#[>]' \ | |
| sed 's/^..//' | |
return $? | |
} | |
output="/dev/stderr" | |
case "${1//[-]}" in | |
h|H|help) | |
_help | |
exit $? | |
;; | |
s|S|silent) | |
output="/dev/null" | |
;; | |
esac | |
if (( $EUID != 0 )); then | |
echo "FAIL" &>${output} | |
exit 1 | |
else | |
echo "PASS" &>${output} | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment