3 # Mirror script for use as a dgit-repos-server mirror hook
5 # In addition to updated-hook (invoked by dgit-repos-server),
6 # this script also supports the following ACTIONs:
7 # MIRROR-HOOK-SCRIPT ... setup [...] create queue dir etc.
8 # MIRROR-HOOK-SCRIPT ... backlog [...] do all packages which need it
9 # MIRROR-HOOK-SCRIPT ... all [...] do all packages
10 # MIRROR-HOOK-SCRIPT ... mirror PACKAGE [...] do just that, longer timeout
12 # DISTRO-DIR must contain a file `mirror-settings' which is a bash
13 # script fragment assigning the following variables:
14 # remoterepos for rsync, in form user@host:/dir
16 # hooktimeout default 30 [sec]
17 # rsynctimeout default 900 [sec]
18 # rsyncssh default 'ssh -o batchmode=yes'
19 # rsync array, default (rsync -rltH --safe-links --delete)
20 # repos default DISTRO-DIR/repos
21 # (optional settings are all set before mirror-settings is included,
22 # so you can modify them with += or some such)
28 case "$DGIT_DRS_DEBUG" in
38 repos=$distrodir/repos
40 rsync=(rsync -rltH --safe-links --delete)
43 rsyncssh='ssh -o batchmode=yes'
45 . $distrodir/mirror-settings
48 # $queue/$package.n - mirror needed
49 # $queue/$package.a - being attempted, or attempt failed
50 # $queue/$package.lock - lock (with-lock-ex)
51 # $queue/$package.err - stderr from failed (or current) run
52 # $queue/$package.log - stderr from last successful run
58 echo >&2 "dgit-mirror-rsync: $*"; exit 127
61 case "$remoterepos" in
63 '') fail "remoterepos config not set" ;;
64 *) fail "remoterepos config does not match *:/* or /*" ;;
69 --timeout=$rsynctimeout \
71 "$repos/$package.git"/. \
72 "$remoterepos/$package.git"
80 "$0" "$distrodir" "reinvoke$newaction" "$package"
83 check-package-mirrorable () {
84 local repo=$repos/$package.git
85 local mode=$(stat -c%a "$repo")
89 *) echo >&2 "unexpected mode $mode for $repo"; return 1 ;;
94 check-package-mirrorable || return 0
95 reinvoke -locked with-lock-ex -w "$queue/$package.lock"
99 exec >"$queue/$package.err" 2>&1
101 rm "$queue/$package.a"
102 mv -f "$queue/$package.err" "$queue/$package.log"
103 rm "$queue/$package.lock"
105 cat >&2 "$queue/$package.err"
110 lock-and-process-baseof-f () {
112 package=${package%.*}
119 check-package-mirrorable || exit 0
120 touch "$queue/$package.n"
121 reinvoke -timed timeout --foreground $hooktimeout
125 (lock-and-process) >/dev/null 2>&1
133 touch "$queue/$package.a"
134 rm -f "$queue/$package.n"
139 for f in $queue/*.[na]; do
140 lock-and-process-baseof-f
145 for f in [a-z0-9]*.git; do
146 lock-and-process-baseof-f
151 test -d "$queue" || mkdir "$queue"
155 fail "bad action $action"