aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-01 10:06:07 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-01 10:06:07 +1200
commitb79fc0e5e82d18bb3d2c7ed95ad4b01057ee2880 (patch)
tree216a2678140a4225b8e8dd82fdd779c503e5c5a5
parentSwitch to slightly faster cf(1) method (diff)
downloaddotfiles-b79fc0e5e82d18bb3d2c7ed95ad4b01057ee2880.tar.gz
dotfiles-b79fc0e5e82d18bb3d2c7ed95ad4b01057ee2880.zip
Change sue(8) to POSIX sh
-rwxr-xr-xbin/sue70
1 files changed, 12 insertions, 58 deletions
diff --git a/bin/sue b/bin/sue
index 260a19d9..8c4b8910 100755
--- a/bin/sue
+++ b/bin/sue
@@ -1,62 +1,16 @@
-#!/usr/bin/env bash
-
-#
-# sue(8) -- Run sudoedit(8) with an appropriate user on a set of files
-#
-# Author: Tom Ryder
-# Copyright: 2015
-# License: Public domain
-#
-
-# Name self
-self=sue
-
-# Define a function to show usage
-usage() {
- printf 'USAGE: %s FILE1 [FILE2 ...]\n' \
- "$self"
-}
-
-# Test the first argument
-case $1 in
-
- # Give help on stdout if requested
- -h|--help|-\?)
- usage
- exit
- ;;
-
- # If no file was given, give help on stderr and bail
- '')
- usage >&2
- exit 1
- ;;
-esac
-
-# Iterate through the files and check they all have the same owner
+#!/bin/sh
+# Run sudoedit(8) with an appropriate user on a set of files
user=
for file ; do
-
- # Use stat(1) to get the file owner
- if ! file_owner=$(stat -c %U -- "$file") ; then
- printf '%s: Failed to run stat(1) on file %s\n' \
- "$self" "$file" >&2
- exit 1
- fi
-
- # If this is the first file, we'll use its owner as our user
- if [[ -z $user ]] ; then
- user=$file_owner
-
- # If not, and the user we're going to use and this file's owner don't
- # match, bail with an error
- elif [[ $user != $file_owner ]] ; then
- printf '%s: Files do not share a common owner\n' \
- "$self" >&2
- exit 1
- fi
+ file_owner=$(stat -c %U -- "$file") || exit
+ case $user in
+ "$file_owner"|'')
+ user=$file_owner
+ ;;
+ *)
+ printf >&2 'sue: Files do not share a common owner\n'
+ exit 1
+ ;;
+ esac
done
-
-# If we got this far, there's at least one file and all the files are owned by
-# the same user; we can safely edit them
exec sudoedit -u "$user" -- "$@"