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
34 echo >&2 "dgit-mirror-rsync: $*"; exit 127
37 if [ $# -lt 2 ]; then fail "too few arguments"; fi
44 repos=$distrodir/repos
46 rsync=(rsync -rltH --safe-links --delete)
49 rsyncssh='ssh -o batchmode=yes'
51 . $distrodir/mirror-settings
54 # $queue/$package.n - mirror needed
55 # $queue/$package.a - being attempted, or attempt failed
56 # $queue/$package.lock - lock (with-lock-ex)
57 # $queue/$package.err - stderr from failed (or current) run
58 # $queue/$package.log - stderr from last successful run
63 case "$remoterepos" in
65 '') fail "remoterepos config not set" ;;
66 *) fail "remoterepos config does not match *:/* or /*" ;;
71 --timeout=$rsynctimeout \
73 "$repos/$package.git"/. \
74 "$remoterepos/$package.git"
82 "$0" "$distrodir" "reinvoke$newaction" "$package"
85 check-package-mirrorable () {
86 local repo=$repos/$package.git
87 local mode=$(stat -c%a "$repo")
91 *) echo >&2 "unexpected mode $mode for $repo"; return 1 ;;
96 check-package-mirrorable || return 0
97 reinvoke -locked with-lock-ex -w "$queue/$package.lock"
101 exec >"$queue/$package.err" 2>&1
103 rm "$queue/$package.a"
104 mv -f "$queue/$package.err" "$queue/$package.log"
105 rm "$queue/$package.lock"
107 cat >&2 "$queue/$package.err"
112 lock-and-process-baseof-f () {
114 package=${package%.*}
121 check-package-mirrorable || exit 0
122 touch "$queue/$package.n"
123 reinvoke -timed timeout --foreground $hooktimeout
127 (lock-and-process) >/dev/null 2>&1
135 touch "$queue/$package.a"
136 rm -f "$queue/$package.n"
141 for f in $queue/*.[na]; do
142 lock-and-process-baseof-f
147 for f in [a-z0-9]*.git; do
148 lock-and-process-baseof-f
153 test -d "$queue" || mkdir "$queue"
157 fail "bad action $action"