32fee9243288edb59cd74a6f56fa60d784f7b922
[girocco.git] / jobd / update.sh
blob32fee9243288edb59cd74a6f56fa60d784f7b922
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 umask 002
27 [ "$cfg_permission_control" != "Hooks" ] || umask 000
29 proj="$1"
30 cd "$cfg_reporoot/$proj.git"
32 if check_interval lastrefresh $cfg_min_mirror_interval; then
33 progress "= [$proj] update skip (last at $(config_get lastrefresh))"
34 exit 0
36 progress "+ [$proj] update (`date`)"
38 bang_setup
39 bang_once=1
40 bang_action="update"
42 url="$(config_get baseurl)"
43 mail="$(config_get owner)"
44 statusok="$(git config --bool gitweb.statusupdates 2>/dev/null || echo true)"
45 mailaddrs=''
46 [ "$statusok" = "false" -o -z "$mail" ] || mailaddrs="$mail"
47 [ -z "$cfg_admincc" -o "$cfg_admincc" = "0" -o -z "$cfg_admin" ] ||
48 if [ -z "$mailaddrs" ]; then mailaddrs="$cfg_admin"; else mailaddrs="$mailaddrs,$cfg_admin"; fi
50 show_progress=1 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-before
52 case "$url" in
53 svn://* | svn+http://* | svn+https://*)
54 # update the git svn url to match baseurl
55 svnurl="${url#svn+}"
56 svnurl="${svnurl%/}"
57 if [ "$svnurl" != "$(git config --get svn-remote.svn.url || :)" ]; then
58 bang config_set_raw svn-remote.svn.url "$svnurl"
59 bang git config -f svn/.metadata svn-remote.svn.reposRoot "$svnurl"
61 # remove any stale *.lock files greater than 1 hour old in case
62 # git-svn was killed on the last update because it took too long
63 find svn -type f -name '*.lock' -mmin +60 -print0 | xargs -0 rm -f
64 GIT_DIR=. bang git svn fetch --quiet
65 # git svn does not preserve group permissions in the svn subdirectory
66 chmod -R ug+rw,o+r svn
68 darcs://*)
69 httpurl="${url/darcs:\/\//http://}"
70 bang git_darcs_fetch "$httpurl"
72 bzr://*)
73 bzrurl="${url#bzr://}"
74 bang git_bzr_fetch "$bzrurl"
77 [ "$url" = "$(git config --get remote.origin.url || :)" ] || bang config_set_raw remote.origin.url "$url"
78 GIT_SSL_NO_VERIFY=1 bang git remote update
79 bang git remote prune origin
81 esac
83 # The objects subdirectories permissions must be updated now.
84 # In the case of a dump http clone, the permissions will not be correct
85 # (missing group write) despite the core.sharedrepository=1 setting!
86 # The objects themselves seem to have the correct permissions.
87 # This problem appears to have been fixed in the most recent git versions.
88 perms=g+w
89 [ "$cfg_permission_control" != "Hooks" ] || perms=go+w
90 chmod $perms $(find objects -maxdepth 1 -type d) 2>/dev/null || :
92 bang git update-server-info
93 bang config_set lastrefresh "$(date "$datefmt")"
95 # Look at which refs changed and trigger ref-change for these
96 show_progress=1 bang git for-each-ref --format '%(refname) %(objectname)' >.refs-after
97 sockpath="$cfg_chroot/etc/taskd.socket"
98 if [ -S "$sockpath" ] && ! cmp -s .refs-before .refs-after; then
99 join -j 1 .refs-before .refs-after |
100 while read ref old new; do
101 [ "$old" != "$new" ] || continue
102 echo "ref-change %$proj% $proj $old $new $ref" | nc.openbsd -w 1 -U "$sockpath"
103 done
104 join -j 1 -v 1 .refs-before .refs-after |
105 while read ref old; do
106 echo "ref-change %$proj% $proj $old 0000000000000000000000000000000000000000 $ref" | nc.openbsd -w 1 -U "$sockpath"
107 done
108 join -j 1 -v 2 .refs-before .refs-after |
109 while read ref new; do
110 echo "ref-change %$proj% $proj 0000000000000000000000000000000000000000 $new $ref" | nc.openbsd -w 1 -U "$sockpath"
111 done
112 git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')"
115 rm -f .refs-before .refs-after
117 if [ -e .banged ]; then
118 [ -z "$mailaddrs" ] ||
120 echo "$proj update succeeded - failure recovery"
121 echo "this status message may be disabled on the project admin page"
122 } | mail -s "[$cfg_name] $proj update succeeded" "$mailaddrs"
123 rm .banged
126 progress "- [$proj] update (`date`)"