Skip to content

Instantly share code, notes, and snippets.

@yoander
Last active December 22, 2017 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoander/a35620c7c38431e56b2c414a0d789b0b to your computer and use it in GitHub Desktop.
Save yoander/a35620c7c38431e56b2c414a0d789b0b to your computer and use it in GitHub Desktop.
Script to detect if one user has root privileges
#!/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