Last active
September 4, 2020 14:11
-
-
Save aldavigdis/895a2c166b66bc61bfd637a165a57324 to your computer and use it in GitHub Desktop.
Run a command as the owner of the current directory
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
#!/bin/bash | |
if [[ -z "$RUNAS" ]]; then | |
runas=$(stat -c '%U' .) | |
else | |
runas=$RUNAS | |
fi | |
if [[ $runas == 'root' ]]; then | |
if [[ -z $( command -v cowsay ) ]]; then | |
echo 'DO NOT RUN THIS AS ROOT!' | |
else | |
cowsay -f 'sheep' 'DO NOT RUN THIS AS ROOT!' | |
fi | |
else | |
sudo -u $runas -- $@ | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment