Last active
December 31, 2015 16:39
-
-
Save mjf/8015344 to your computer and use it in GitHub Desktop.
editfacl - Edit POSIX.1e ACL information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# editfacl - Edit POSIX.1e ACL information | |
# Copyright (C) 2013 Matous J. Fialka, <http://mjf.cz/> | |
# Released under the terms of The MIT License | |
EDITOR="${EDITOR:-vi}" | |
TMPDIR="${TMPDIR:-/tmp}" | |
GETFACLOPT="$GETFACLOPT" | |
SETFACLOPT="$SETFACLOPT" | |
if [ $# -eq 0 ] | |
then | |
${PAGER:-cat} <<- EOT | |
NAME | |
editfacl - View/Edit POSIX.1e ACL information | |
SYNOPSIS | |
editfacl [file ...] | |
file Path to filesystem object(s) | |
ENVIRONMENT VARIABLES | |
EDITOR Editor to view/edit ACL information | |
PAGER Pager to view help information | |
TMPDIR Temporary directory to work with | |
GETFACLOPT Program getfacl(1) extra options | |
SETFACLOPT Program setfacl(1) extra options | |
EXIT CODES | |
0 No failure | |
1 Creating temporary file failed | |
2 Getting ACL information failed | |
3 Viewing/Editing temporary file failed | |
4 Testing new ACL information unexpectedly failed | |
5 Testing new ACL information failed | |
6 Setting ACL information failed | |
SIGNAL HANDLER TRAPPING EXIT CODES | |
101 Trapping SIGHUP signal failed | |
102 Trapping SIGINT signal failed | |
103 Trapping SIGQUIT signal failed | |
113 Trapping SIGPIPE signal failed | |
115 Trapping SIGTERM signal failed | |
SIGNAL HANDLER CODES | |
131 Signal SIGHUP caught | |
132 Signal SIGINT caught | |
133 Signal SIGQUIT caught | |
143 Signal SIGPIPE caught | |
145 Signal SIGTERM caught | |
EXAMPLES | |
## | |
# Normal use | |
# | |
export EDITOR='ed' | |
export GETFACLOPT='-p' | |
editfacl ~/public_html | |
## | |
# Auto-edit use - USE WITH EXTREME CAUTION | |
# | |
export EDITOR='sed -f script.sed -i' | |
export GETFACLOPT='-R -p' | |
editfacl ~ | |
## | |
# Auto-edit use - sane version | |
# | |
export EDITOR='sed -f script.sed -i' | |
ls *.pdf > pdf.txt | |
editfacl - < pdf.txt | |
## | |
# Debug use - nothing is changed | |
# | |
export EDITOR='cat' | |
editfacl ~/.* | |
AUTHOR | |
Copyright (C) 2013 Matous J. Fialka, <http://mjf.cz/> | |
LICENSE | |
Released under the term of The MIT License | |
EOT | |
exit 0 | |
fi | |
if ! TMPFILE=`mktemp -p "$TMPDIR" editfacl.XXXXXXXXXXXXXXXX` | |
then | |
exit 1 | |
fi | |
TMPFILEORIG="$TMPFILE.orig" | |
clean_up() | |
{ | |
rm -f "$TMPFILE" "$TMPFILEORIG" | |
return 0 | |
} | |
signal_handler() | |
{ | |
clean_up | |
trap - 2 | |
kill -2 $$ | |
exit $((130 + $1)) | |
} | |
for _sig in 1 2 3 13 15 | |
do | |
if ! trap "signal_handler $_sig" $_sig | |
then | |
clean_up | |
exit $((100 + _sig)) | |
fi | |
done | |
unset _sig | |
if ! getfacl $GETFACLOPT -- $@ | tee "$TMPFILE" > "$TMPFILEORIG" | |
then | |
clean_up | |
exit 2 | |
fi | |
if ! $EDITOR "$TMPFILE" | |
then | |
clean_up | |
exit 3 | |
fi | |
if ! cmp -s "$TMPFILE" "$TMPFILEORIG" | |
then | |
echo editfacl: ACL information is possibly changed | |
if ! setfacl --test --restore="$TMPFILE" $SETFACLOPT | |
then | |
if getfacl $GETFACLOPT -- $@ | diff -e - "$TMPFILE" | |
then | |
clean_up | |
exit 4 | |
else | |
clean_up | |
exit 5 | |
fi | |
else | |
if ! setfacl --restore="$TMPFILE" $SETFACLOPT | |
then | |
clean_up | |
exit 6 | |
else | |
echo editfacl: ACL information is changed | |
clean_up | |
exit 0 | |
fi | |
fi | |
else | |
echo editfacl: ACL information is unchanged | |
clean_up | |
exit 0 | |
fi | |
# vi:ft=sh:tw=72 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DOCUMENTATION