INSTALL: In theory
[girocco/testingthisout.git] / jobd / update.sh
blob380d4c8adb28e17b166b1bf9efee09c3d70cdea8
1 #!/bin/bash
3 . @basedir@/shlib.sh
5 set -e
7 proj="$1"
8 cd "$cfg_reporoot/$proj.git"
10 if check_interval lastrefresh $cfg_min_mirror_interval; then
11 progress "= [$proj] update skip (last at $(config_get lastrefresh))"
12 exit 0
14 progress "+ [$proj] update (`date`)"
16 bang_setup
17 bang_once=1
18 bang_action="update"
20 url="$(config_get baseurl)"
21 mail="$(config_get owner)"
23 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-before
25 case "$url" in
26 svn://*)
27 GIT_DIR=. bang git svn fetch
28 GIT_DIR=. bang git fetch
31 [ "$url" = "$(config_get remote.origin.url)" ] || bang config_set remote.origin.url "$url"
32 bang git remote update
33 bang git remote prune origin
35 esac
37 bang git update-server-info
38 bang config_set lastrefresh "$(date -R)"
40 # Look at which refs changed and trigger ref-change for these
41 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-after
42 sockpath="$cfg_chroot/etc/taskd.socket"
43 if [ -S "$sockpath" ] && ! cmp -s .refs-before .refs-after; then
45 join -j 1 .refs-before .refs-after |
46 while read ref old new; do
47 [ "$old" != "$new" ] || continue
48 echo "ref-change -1 $proj $old $new $ref"
49 done
50 join -j 1 -v 1 .refs-before .refs-after |
51 while read ref old; do
52 echo "ref-change -1 $proj $old 0000000000000000000000000000000000000000 $ref"
53 done
54 join -j 1 -v 2 .refs-before .refs-after |
55 while read ref new; do
56 echo "ref-change -1 $proj 0000000000000000000000000000000000000000 $new $ref"
57 done
58 } | nc.openbsd -w 1 -U "$sockpath"
61 rm -f .refs-before .refs-after
63 if [ -e .banged ]; then
64 echo "$proj update succeeded - failure recovery" | mail -s "[$cfg_name] $proj update succeeded" "$mail,$cfg_admin"
65 rm .banged
68 progress "- [$proj] update (`date`)"