Created
May 24, 2017 05:56
-
-
Save subfuzion/a5ace9ece752af98f1fda9edc09dc062 to your computer and use it in GitHub Desktop.
Ensure script can run a command as root
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
#!/bin/sh | |
# Source: https://get.docker.com/ | |
command_exists() { | |
command -v "$@" > /dev/null 2>&1 | |
} | |
sh_c='sh -c' | |
if [ "$user" != 'root' ]; then | |
if command_exists sudo; then | |
sh_c='sudo -E sh -c' | |
elif command_exists su; then | |
sh_c='su -c' | |
else | |
cat >&2 <<-'EOF' | |
Error: this installer needs the ability to run commands as root. | |
We are unable to find either "sudo" or "su" available to make this happen. | |
EOF | |
exit 1 | |
fi | |
fi | |
# now run some command as root | |
$sh_c 'some command...' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment