diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-04-05 20:06:39 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-04-05 20:46:47 +1200 |
commit | c8ab406749124d2e762ad5cf53963070113afd0f (patch) | |
tree | 54c9721a06957ebe7098a211eea803b0230c0f5d /bin/sue.sh | |
parent | Handle POSIX correctness in ~/.bash_profile (diff) | |
download | dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.tar.gz dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.zip |
Apply runtime shebanging to POSIX shell
Diffstat (limited to 'bin/sue.sh')
-rw-r--r-- | bin/sue.sh | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/bin/sue.sh b/bin/sue.sh new file mode 100644 index 00000000..654c041f --- /dev/null +++ b/bin/sue.sh @@ -0,0 +1,26 @@ +# Run sudoedit(8) with an appropriate user on a set of files + +# Blank out the user variable +user= + +# Iterate over the given files +for file ; do + + # Get the file's owner, or bail + file_owner=$(stat -c %U -- "$file") || exit + + # Check that this file has the same owner as all previously checked files, + # if any + case $user in + "$file_owner"|'') + user=$file_owner + ;; + *) + printf >&2 'sue: Files do not share a common owner\n' + exit 1 + ;; + esac +done + +# Run sudoedit(8) as the user that owns all the files +sudoedit -u "$user" -- "$@" |