Skip to content

Instantly share code, notes, and snippets.

@h8rt3rmin8r
Created October 31, 2020 21:36
Show Gist options
  • Save h8rt3rmin8r/1c66c2f543c1572745978afa40365e8e to your computer and use it in GitHub Desktop.
Save h8rt3rmin8r/1c66c2f543c1572745978afa40365e8e to your computer and use it in GitHub Desktop.
Run a quick test for access to "sudo"
#!/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 (161803398@email.tg)
#>
#> 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