diff options
Diffstat (limited to 'community/lxcfs/chownmap')
-rw-r--r-- | community/lxcfs/chownmap | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/community/lxcfs/chownmap b/community/lxcfs/chownmap new file mode 100644 index 0000000000..07e5aea20b --- /dev/null +++ b/community/lxcfs/chownmap @@ -0,0 +1,46 @@ +#!/bin/sh +# author: Mirek Kratochvil +# https://github.com/exaexa/chownmap + +help_exit () { + echo "usage: $0 <from> <to> <length> [ files ] ..." + exit $1 +} + +FROM="$1" +[ -n "$FROM" ] || help_exit 0 +[ "$FROM" -ge 0 ] || help_exit 1 + +TO="$2" +[ -n "$TO" ] || help_exit 0 +[ "$TO" -ge 0 ] || help_exit 1 + +LEN="$3" +[ -n "$LEN" ] || help_exit 0 +[ "$LEN" -gt 0 ] || help_exit 1 + +[ -n "$4" ] || help_exit 0 + +shift 3 + +LAST=$(( FROM + LEN )) +CHANGE=$(( TO - FROM )) +CHOWN_EXTRA_OPTS=${CHOWN_EXTRA_OPTS:-} + +do_dir () { + find "$1" |while read fn ; do + stat "$fn" -c"%u %g" | { + read uid gid + chuid=$uid + chgid=$gid + [[ $chuid -ge $FROM && $chuid -lt $LAST ]] && chuid=$(( chuid + CHANGE )) + [[ $chgid -ge $FROM && $chgid -lt $LAST ]] && chgid=$(( chgid + CHANGE )) + [[ $uid -ne $chuid || $gid -ne $chgid ]] && chown $CHOWN_EXTRA_OPTS -h $chuid:$chgid "$fn" + } + done +} + +while [ -n "$1" ] ; do + do_dir "$1" + shift +done |