COPYING: New file with the GPLv2 licence text to clarify the legal situation
[girocco.git] / jobd / update.sh
bloba191b188d7567359df4f83d9d0ef154d028a3daf
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
25 proj="$1"
26 cd "$cfg_reporoot/$proj.git"
28 if check_interval lastrefresh $cfg_min_mirror_interval; then
29 progress "= [$proj] update skip (last at $(config_get lastrefresh))"
30 exit 0
32 progress "+ [$proj] update (`date`)"
34 bang_setup
35 bang_once=1
36 bang_action="update"
38 url="$(config_get baseurl)"
39 mail="$(config_get owner)"
41 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-before
43 case "$url" in
44 svn://* | svn+http://* | svn+https://*)
45 GIT_DIR=. bang git svn fetch
46 GIT_DIR=. bang git fetch
48 darcs://*)
49 httpurl="${url/darcs:\/\//http://}"
50 bang git_darcs_fetch "$httpurl"
52 bzr://*)
53 bzrurl="${url#bzr://}"
54 bang git_bzr_fetch "$bzrurl"
57 [ "$url" = "$(config_get remote.origin.url)" ] || bang config_set_raw remote.origin.url "$url"
58 GIT_SSL_NO_VERIFY=1 bang git remote update
59 bang git remote prune origin
61 esac
63 bang git update-server-info
64 bang config_set lastrefresh "$(date "$datefmt")"
66 # Look at which refs changed and trigger ref-change for these
67 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-after
68 sockpath="$cfg_chroot/etc/taskd.socket"
69 if [ -S "$sockpath" ] && ! cmp -s .refs-before .refs-after; then
70 join -j 1 .refs-before .refs-after |
71 while read ref old new; do
72 [ "$old" != "$new" ] || continue
73 echo "ref-change -1 $proj $old $new $ref" | nc.openbsd -w 1 -U "$sockpath"
74 done
75 join -j 1 -v 1 .refs-before .refs-after |
76 while read ref old; do
77 echo "ref-change -1 $proj $old 0000000000000000000000000000000000000000 $ref" | nc.openbsd -w 1 -U "$sockpath"
78 done
79 join -j 1 -v 2 .refs-before .refs-after |
80 while read ref new; do
81 echo "ref-change -1 $proj 0000000000000000000000000000000000000000 $new $ref" | nc.openbsd -w 1 -U "$sockpath"
82 done
85 rm -f .refs-before .refs-after
87 if [ -e .banged ]; then
88 echo "$proj update succeeded - failure recovery" | mail -s "[$cfg_name] $proj update succeeded" "$mail,$cfg_admin"
89 rm .banged
92 progress "- [$proj] update (`date`)"