mktar: Use `wc` instead of `du` in summary message
[sunny256-utils.git] / ga-getnew
blobd43afef055731ca69dce4af8d40e3c3c9327902a
1 #!/usr/bin/env bash
3 #=======================================================================
4 # ga-getnew
5 # File ID: 8af4d956-f358-11e4-b717-000df06acc56
7 # Get new files from the last month (can be overridden) that haven't got
8 # enough copies in git-annex yet, then optionally execute a fast fsck to
9 # check that the files have enough copies.
11 # Author: Øyvind A. Holm <sunny@sunbase.org>
12 # License: GNU General Public License version 2 or later.
13 #=======================================================================
15 progname=ga-getnew
16 VERSION=0.7.0
18 ARGS="$(getopt -o "\
22 s:\
24 " -l "\
25 from:,\
26 fsck,\
27 help,\
28 quiet,\
29 resume,\
30 since:,\
31 verbose,\
32 version,\
33 " -n "$progname" -- "$@")"
34 test "$?" = "0" || exit 1
35 eval set -- "$ARGS"
37 opt_from=''
38 opt_fsck=0
39 opt_help=0
40 opt_quiet=0
41 opt_resume=0
42 opt_since=1.month
43 opt_verbose=0
44 while :; do
45 case "$1" in
46 --from) opt_from="$2"; shift 2 ;;
47 --fsck) opt_fsck=1; shift ;;
48 -h|--help) opt_help=1; shift ;;
49 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
50 -r|--resume) opt_resume=1; shift ;;
51 -s|--since) opt_since="$2"; shift 2 ;;
52 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
53 --version) echo $progname $VERSION; exit 0 ;;
54 --) shift; break ;;
55 *) echo $progname: Internal error >&2; exit 1 ;;
56 esac
57 done
58 opt_verbose=$(($opt_verbose - $opt_quiet))
60 var_disable=ga-getnew.disable
62 if test "$opt_help" = "1"; then
63 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
64 cat <<END
66 Get new files from the last month (can be overridden) that haven't got
67 enough copies in git-annex yet, then optionally execute a fast fsck to
68 check that the files have enough copies.
70 Arguments and options after " -- " are delivered to git-allfiles(1)
71 which delivers them further to "git log".
73 Usage: $progname [options] [ -- options_to_git-allfiles ]
75 Options:
77 --from REMOTE
78 Get new files from Git remote REMOTE.
79 --fsck
80 Execute "ga fsck" after the files are copied.
81 -h, --help
82 Show this help.
83 -q, --quiet
84 Be more quiet. Can be repeated to increase silence.
85 -r, --resume
86 Don't execute an initial "ga sync", resume an earlier interrupted
87 session.
88 -s TIMESPAN, --since TIMESPAN
89 Get new files since TIMESPAN, same syntax as --since in "git log".
90 -v, --verbose
91 Increase level of verbosity. Can be repeated.
92 --version
93 Print version information.
95 If the Git option $var_disable is set to a non-empty value in a repo,
96 the repo is skipped. For example:
98 git config $var_disable 1
101 exit 0
104 msg() {
105 echo
106 echo ==== $progname: $*
109 if test -n "$(git config --get $var_disable)"; then
110 echo $progname: $var_disable is set, skipping repo
111 exit 0
114 toplevel="$(git rev-parse --show-toplevel)"
115 cd "$toplevel" || {
116 echo $progname: $toplevel: Cannot chdir to top of repo >&2
117 exit 1
120 if test "$opt_resume" != "1"; then
121 # Using backslash before { and } to suppress folding when editing this
122 # file.
123 msg ga sync \{\{\{
124 ga sync 2>&1
125 echo $progname: ga sync \}\}\}
128 if test -n "$opt_from"; then
129 from_str=" --from=$opt_from"
130 else
131 from_str=''
134 msg git allfiles --since=$opt_since $*
135 msg ga get --auto$from_str
136 git allfiles --since=$opt_since "$@" |
137 strip-nonexisting |
138 xargs -d \\n --no-run-if-empty ga get --auto$from_str
140 if test "$opt_fsck" = "1"; then
141 msg ga fsck --fast --quiet
142 git allfiles --since=$opt_since "$@" |
143 strip-nonexisting |
144 xargs -d \\n --no-run-if-empty ga fsck --fast --quiet
147 msg ga sync \{\{\{
148 ga sync 2>&1
149 echo $progname: ga sync \}\}\}