apache.conf.in: redirect git.or.cz traffic
[girocco.git] / hooks / post-receive
blob98fb15d90238f340096da0e389a87e69c3f2b626
1 #!/bin/sh
3 # Keep lastactivity and personal mob (if enabled) up-to-date
4 # We use receive.updateserverinfo=true so no need to run update-server-info
5 # Send notification through the taskd socket if it exists and not personal mob push
7 # Beware, we MAY be running in a chroot!
9 set -e
11 # Make sure the current directory is where we expect to be
12 [ "${GIT_DIR+set}" != "set" ] || { [ -n "$GIT_DIR" ] && [ -d "$GIT_DIR" ]; } || unset GIT_DIR
13 [ -n "$GIT_DIR" ] || GIT_DIR="$(git rev-parse --git-dir)"
14 [ -n "$GIT_DIR" ] && cd -P "${GIT_DIR:-.}" || exit 1
15 case "${PWD%/*}" in */worktrees)
16 # Gah!
18 # But it COULD just be a coincidence...
19 [ -s commondir ] && [ -s HEAD ] &&
20 _cmndir= && read -r _cmndir <commondir 2>/dev/null &&
21 [ -n "$_cmndir" ] && [ -d "$_cmndir" ]
22 then
23 # ...it is not, fix it!
24 cd -P "$_cmndir" || exit 1
26 esac
27 GIT_DIR="." GIT_PREFIX= && export GIT_DIR
29 # Get out of the mob
30 case "$PWD" in *?/mob)
31 cd ..
32 GIROCCO_PERSONAL_MOB=1
33 esac
35 mob=@mob@
36 autogchack=@autogchack@
37 umask 002
38 git config gitweb.lastchange "$(date '+%a, %d %b %Y %T %z')" || :
39 git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \
40 --count=1 refs/heads >info/lastactivity || :
41 ! [ -d htmlcache ] || { >htmlcache/changed; } 2>/dev/null || :
42 rm -f .delaygc .allowgc
43 if [ "$mob" = "mob" ] && [ -d mob ]; then
44 git for-each-ref --format='%(objectname) %(refname)' >packed-refs.mob.$$ || :
45 mv -f packed-refs.mob.$$ packed-refs.mob
46 rm -f packed-refs.mob.$$
49 sockpath=/etc/taskd.socket
50 authuser="$LOGNAME"
51 if [ -x @perlbin@ ]; then
52 # Not in chroot...
53 . @basedir@/shlib.sh
55 sockpath="$cfg_chroot$sockpath"
56 v_get_proj_from_dir projname
58 # authuser needs to be set if not running in the chroot.
59 # Currently that can only be the case with https push in
60 # which case REMOTE_USER will contain the user name (possibly prefixed
61 # with "/UID=" and suffixed with "/dnQualifier=...").
62 # Fallback is the mirror_user if REMOTE_USER is not set.
63 authuser="${REMOTE_USER#/UID=}"
64 authuser="${authuser#UID = }"
65 authuser="${authuser%/dnQualifier=*}"
66 authuser="${authuser%, dnQualifier = *}"
67 [ -n "$authuser" ] || authuser="%$cfg_mirror_user%"
68 else
69 # In chroot...
70 reporoot=/@jailreporoot@
71 reporoot="$(cd "$reporoot" && pwd -P)"
72 cwd="$(pwd -P)"
73 projname="${cwd#$reporoot/}"
75 nc_openbsd() { /bin/nc.openbsd "$@"; }
79 [ "${autogchack:-0}" != "0" ] &&
80 { [ "$cfg_autogchack" != "mirror" ] || ! [ -e .nofetch ]; } &&
81 [ "$(git config --get --bool girocco.autogchack 2>/dev/null)" != "false" ]
82 then
83 git for-each-ref --format '%(refname) %(objectname)' | LC_ALL=C sort -b -k1,1 >.refs-new.$$
84 mv -f .refs-new.$$ .refs-last
85 rm -f .refs.new.$$
88 if [ -n "$GIROCCO_PERSONAL_MOB" ] || ! [ -S "$sockpath" ]; then
89 # We never run the ref update notification part on a personal mob push
90 # Read the incoming refs, but just ignore them (git doesn't like SIGPIPE)
91 while read -r line; do
93 done
94 else
95 trap ':' PIPE
97 echo "ref-changes $authuser ${projname%.git}" || :
98 while read -r line; do
99 echo "$line" || :
100 done
101 git for-each-ref --format='%(objectname) %(objectname) %(refname)' refs/heads || :
102 echo "done ref-changes $authuser ${projname%.git}" || :
103 ) 2>/dev/null | { nc_openbsd -w 15 -U "$sockpath" || :; } || :
104 trap - PIPE
107 exit 0