Skip to content

Instantly share code, notes, and snippets.

@aldavigdis
Last active September 4, 2020 14:11
Show Gist options
  • Save aldavigdis/895a2c166b66bc61bfd637a165a57324 to your computer and use it in GitHub Desktop.
Save aldavigdis/895a2c166b66bc61bfd637a165a57324 to your computer and use it in GitHub Desktop.
Run a command as the owner of the current directory
#!/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