aboutsummaryrefslogtreecommitdiff
path: root/bin/sue.sh
blob: 34343e4ad877e97fbe8d449265ea3955928384e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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" -- "$@"