aboutsummaryrefslogtreecommitdiff
path: root/bin/sue.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/sue.sh')
-rw-r--r--bin/sue.sh26
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" -- "$@"