Last active
December 22, 2017 02:39
-
-
Save yoander/a35620c7c38431e56b2c414a0d789b0b to your computer and use it in GitHub Desktop.
Script to detect if one user has root privileges
This file contains hidden or 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 | |
userdo= | |
echo Testing if you have root access! | |
if [[ 'root' == whoami ]]; then | |
is_root=true | |
else | |
is_root=false | |
fi | |
if [[ $is_root == false ]]; then | |
userdo=$(which sudo) | |
if [[ $userdo != '' ]]; then | |
$userdo ls /root/ &>/dev/null && is_root=true | |
fi | |
fi | |
if [[ $is_root == true ]]; then | |
echo 'Root access detected ( ͡° ͜ʖ ͡°)' | |
else | |
echo This script requires root access | |
echo Bye! | |
exit 2 | |
fi | |
# User can install pkg1 pkg2 | |
# $userdo pm -y install pkg1 pkg2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment