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