mdisk: Use color, red for error messages and green for success
[sunny256-utils.git] / annex-cmd
blob87c8fa34d561f733ca382f39f045a8ab4030e050
1 #!/usr/bin/env bash
3 #==============================================================================
4 # annex-cmd
5 # File ID: f1ca60b4-d33a-11e2-a3c0-0800274013ad
7 # Execute command in all local git-annex repositories
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #==============================================================================
13 progname=annex-cmd
14 VERSION=0.4.0
16 if test "$1" = "--version"; then
17 echo $progname $VERSION
18 exit 0
21 if test "$1" = "-h" -o "$1" = "--help"; then
22 cat <<END
24 Execute command in all local git-annex repositories
26 Usage: $progname [options]
28 Options:
30 --annex
31 Execute git-update-dirs in the **/annex directories instead of the
32 actual annexes.
33 --count-loose
34 Display the number of loose objects in annex repositories in sorted
35 order.
36 -D X
37 Only run git-update-dirs in annex repositories named X.
38 --find-extra
39 List files in all annexes that have more copies than necessary.
40 Lists locations too, to get only the file names with number of
41 copies, filter through "grep ^whereis".
42 --gadu
43 Execute ./lag_gadu-local * in all top annex/ directories. Uses
44 gadu(1).
45 --get
46 Loop through all local annexes under /media/*/annex/, sorted by
47 descending free space, and run "make getnew" there, i.e. ga-getnew
48 on all directories with new changes, i.e. "ga get --auto", i.e. "git
49 annex get --auto". 😉
50 -h, --help
51 Show this help.
52 --version
53 Print version information.
55 END
56 exit 0
59 annex_free() {
60 dir="$1"
62 cd "$dir" || {
63 echo $progname: $dir: chdir error >&2
64 return 1
66 ga info --fast --bytes | grep "^available local disk space:" |
67 awk '{print($5)}'
71 if [ "$1" = "--gadu" ]; then
72 git update-dirs ~/annex /media/*/annex \
73 -e "ga sync" \
74 -e "sess ./lag_gadu-local *" \
75 -e "git add .gadu-local" \
76 -e "git ci -av" \
77 -e "ga sync"
78 exit
81 wildc='*'
82 if [ "$1" = "--annex" ]; then
83 unset wildc
84 shift
86 if [ "$1" = "-D" ]; then
87 test -z "$2" && {
88 echo annex-cmd: Missing argument for -D >&2
89 exit 1
91 wildc="$2"
92 shift 2
95 if [ "$1" = "--get" ]; then
96 shift
97 for f in /media/*/annex; do
98 test -d "$f" || continue
99 free_space="$(annex_free "$f")"
100 test -z "$free_space" && {
101 echo $progname: $f: No annex information found >&2
102 continue
104 test $free_space -le 4096 && {
105 echo -n "$progname: $f: Skipping annex, " >&2
106 echo only $free_space bytes free >&2
107 continue
109 echo $free_space $f
110 done | sort -rn | cut -f 2- -d ' ' | while read d; do
112 echo >&2
113 echo $progname: Get files to $d >&2
114 cd "$d" && make getnew || exit 1
116 done
117 exit
120 if [ "$1" = "--count-loose" ]; then
121 git update-dirs /media/*/annex/$wildc $HOME/annex/$wildc \
122 -qq \
123 -E 'pwd >&2' \
124 -e 'echo $(
125 find .git/objects -type f | grep -v -e pack -e info | wc -l
126 ) $(pwd)' \
127 | sort -n
128 exit
131 if [ "$1" = "--find-extra" ]; then
132 git update-dirs ~/annex/$wildc \
133 -q \
134 -E 'pwd >&2' \
135 -e 'git update-dirs -Fg . >/dev/null' \
136 -e 'ga whereis --copies=semitrusted+:$(
137 echo $(ga numcopies) + 1 | bc
139 exit
142 git update-dirs /media/*/annex/$wildc $HOME/annex/$wildc "$@"
144 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :