mdisk: Avoid delay when mounting disks with a `/.dontsleep/` directory
[sunny256-utils.git] / sunnyrights
blobd4b34158f3c69cb22918ab7f90d9bc92975d550e
1 #!/usr/bin/env bash
3 #=======================================================================
4 # sunnyrights
5 # File ID: 9b90e1dc-5d45-11df-8c34-90e6ba3022ac
7 # Change file ownership of a subdirectory tree to "sunny" and set the
8 # sticky bit on directories so he (I) will continue to own new files.
9 # Mainly used for .git directories.
11 # Author: Øyvind A. Holm <sunny@sunbase.org>
12 # License: GNU General Public License version 2 or later.
13 #=======================================================================
15 progname=sunnyrights
16 VERSION=0.1.4
18 ARGS="$(getopt -o "\
22 " -l "\
23 help,\
24 quiet,\
25 verbose,\
26 version,\
27 " -n "$progname" -- "$@")"
28 test "$?" = "0" || exit 1
29 eval set -- "$ARGS"
31 opt_help=0
32 opt_quiet=0
33 opt_verbose=0
34 while :; do
35 case "$1" in
36 -h|--help) opt_help=1; shift ;;
37 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
38 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
39 --version) echo $progname $VERSION; exit 0 ;;
40 --) shift; break ;;
41 *) echo $progname: Internal error >&2; exit 1 ;;
42 esac
43 done
44 opt_verbose=$(($opt_verbose - $opt_quiet))
46 if test "$opt_help" = "1"; then
47 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
48 cat <<END
50 Change file ownership of a subdirectory tree to "sunny" and set the
51 sticky bit on directories so he (I) will continue to own new files.
52 Mainly used for .git directories.
54 Usage: $progname [options] DIRECTORY [DIRECTORIES [...]]
56 Options:
58 -h, --help
59 Show this help.
60 -q, --quiet
61 Be more quiet. Can be repeated to increase silence.
62 -v, --verbose
63 Increase level of verbosity. Can be repeated.
64 --version
65 Print version information.
67 END
68 exit 0
71 if test "$1" = ""; then
72 echo "$progname: No directory specified" >&2
73 exit 1
76 abort=0
77 for ft in "$@"; do
78 test -d "$ft" || {
79 echo "$progname: $ft: Directory not found" >&2
80 abort=1
82 done
83 test "$abort" = "1" && { echo "$progname: Aborting." >&2; exit 1; }
84 chown -Rc sunny.sunny "$@"
85 find "$@" -type d -print0 | xargs -0 chmod -c +s