Merge branch 'master' into rorcz
[girocco.git] / jobd / update.sh
blobe57929c99eeee71b8b781903b5c4452ed738c3fc
1 #!/bin/bash
3 . @basedir@/shlib.sh
5 # date -R is linux-only, POSIX equivalent is '+%a, %d %b %Y %T %z'
6 datefmt='+%a, %d %b %Y %T %z'
8 # darcs fast-export | git fast-import with error handling
9 git_darcs_fetch() {
10 "$cfg_basedir"/bin/darcs-fast-export --export-marks=$(pwd)/dfe-marks --import-marks=$(pwd)/dfe-marks "$1" | \
11 git fast-import --export-marks=$(pwd)/gfi-marks --import-marks=$(pwd)/gfi-marks
12 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
13 return $?
16 # bzr fast-export | git fast-import with error handling
17 git_bzr_fetch() {
18 bzr fast-export --export-marks=$(pwd)/dfe-marks --import-marks=$(pwd)/dfe-marks "$1" | \
19 git fast-import --export-marks=$(pwd)/gfi-marks --import-marks=$(pwd)/gfi-marks
20 [ ${PIPESTATUS[0]} = 0 -a ${PIPESTATUS[1]} = 0 ]
21 return $?
23 set -e
24 trap 'if [ $? != 0 ]; then echo "update failed dir: $PWD" >&2; fi; rm -f "$bang_log"' EXIT
26 proj="$1"
27 cd "$cfg_reporoot/$proj.git"
29 if check_interval lastrefresh $cfg_min_mirror_interval; then
30 progress "= [$proj] update skip (last at $(config_get lastrefresh))"
31 exit 0
33 progress "+ [$proj] update (`date`)"
35 bang_setup
36 bang_once=1
37 bang_action="update"
39 url="$(config_get baseurl)"
40 mail="$(config_get owner)"
42 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-before
44 case "$url" in
45 svn://* | svn+http://* | svn+https://*)
46 GIT_DIR=. bang git svn fetch --quiet
47 # git svn does not preserve group permissions in the svn subdirectory
48 chmod -R ug+rw,o+r svn
49 # handle old-style svn setup if it exists
50 if [ -n "$(GIT_DIR=. git config --get remote.origin.url || :)" ]; then
51 GIT_DIR=. bang git fetch
54 darcs://*)
55 httpurl="${url/darcs:\/\//http://}"
56 bang git_darcs_fetch "$httpurl"
58 bzr://*)
59 bzrurl="${url#bzr://}"
60 bang git_bzr_fetch "$bzrurl"
63 [ "$url" = "$(config_get remote.origin.url)" ] || bang config_set_raw remote.origin.url "$url"
64 GIT_SSL_NO_VERIFY=1 bang git remote update
65 bang git remote prune origin
67 esac
69 bang git update-server-info
70 bang config_set lastrefresh "$(date "$datefmt")"
72 # Look at which refs changed and trigger ref-change for these
73 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-after
74 sockpath="$cfg_chroot/etc/taskd.socket"
75 if [ -S "$sockpath" ] && ! cmp -s .refs-before .refs-after; then
76 join -j 1 .refs-before .refs-after |
77 while read ref old new; do
78 [ "$old" != "$new" ] || continue
79 echo "ref-change -1 $proj $old $new $ref" | nc.openbsd -w 1 -U "$sockpath"
80 done
81 join -j 1 -v 1 .refs-before .refs-after |
82 while read ref old; do
83 echo "ref-change -1 $proj $old 0000000000000000000000000000000000000000 $ref" | nc.openbsd -w 1 -U "$sockpath"
84 done
85 join -j 1 -v 2 .refs-before .refs-after |
86 while read ref new; do
87 echo "ref-change -1 $proj 0000000000000000000000000000000000000000 $new $ref" | nc.openbsd -w 1 -U "$sockpath"
88 done
91 rm -f .refs-before .refs-after
93 if [ -e .banged ]; then
94 echo "$proj update succeeded - failure recovery" | mail -s "[$cfg_name] $proj update succeeded" "$mail,$cfg_admin"
95 rm .banged
98 progress "- [$proj] update (`date`)"