Created
November 30, 2021 16:06
-
-
Save tomdavidson/72e539a4fced881a9e6c7b2d9abf5c4a to your computer and use it in GitHub Desktop.
snippit to help with scripts that should be run as root
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 | |
if [ $SUDO_USER ]; then | |
realUser=$SUDO_USER | |
else | |
realUser=$(whoami) | |
fi | |
realUserHome=$(bash -c "cd ~$(printf %q "$realUser") && pwd") | |
[ "$(id -u)" == 0 ] || exec sudo -E bash "$0" "$@" | |
! type sudo > /dev/null 2>&1 && apt install sudo && usermod -aG sudo "$(whoami)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment