hooks/post-receive: replace printf with echo
[girocco.git] / gitweb / genindex.sh
blob96e7a98a6d7e000bb9c4d518997874da5d89ca60
1 #!/bin/sh
3 # genindex - Generate gitweb project list from Girocco's
5 # Usage: genindex.sh [project-to-update]
7 # If project-to-update is given, then only that one will be updated
9 . @basedir@/shlib.sh
11 set -e
13 update="${1%.git}"
15 # Use the correct umask so the list file is group-writable, if owning_group set
16 if [ -n "$cfg_owning_group" ]; then
17 umask 002
20 # gitweb calls CGI::Util::unescape on both the path and owner, but the only
21 # character we allow that needs to be escaped is '+' which is allowed in
22 # both the owner email and in the project name. Otherwise '+' will be
23 # displayed as a ' ' in the owner email and will cause a project name
24 # containing it to be omitted from the project list page.
26 if [ -z "$update" ] || [ ! -s "$cfg_projlist_cache_dir/gitproj.list" ]; then
27 # Must read all the owners so don't bother with join at all
28 get_repo_list | while read proj; do
29 echo "$proj $(cd "$cfg_reporoot/$proj.git" && config_get owner)"
30 done | perl -MDigest::MD5=md5_hex -ne \
31 '@_=split;print "$_[0] ",md5_hex(lc($_[1]))," $_[1]\n";' | \
32 LC_ALL=C sort -k 1,1 >/tmp/gitproj.list.$$
33 else
34 get_repo_list | LC_ALL=C sort -k 1,1 | \
35 LC_ALL=C join -a 1 - "$cfg_projlist_cache_dir/gitproj.list" | \
36 while read proj hash owner; do
37 if [ "$proj" = "$update" -o -z "$owner" -o -z "$hash" ]; then
38 echo "$proj recalc $(cd "$cfg_reporoot/$proj.git" && config_get owner)"
39 else
40 echo "$proj $hash $owner"
42 done | perl -MDigest::MD5=md5_hex -ne \
43 '@_=split;print "$_[0] ",$_[1] eq "recalc"?md5_hex(lc($_[2])):$_[1]," $_[2]\n";' | \
44 LC_ALL=C sort -k 1,1 >/tmp/gitproj.list.$$
46 cut -d ' ' -f 1,3- </tmp/gitproj.list.$$ | sed -e 's/ /.git /;s/+/%2B/g' >/tmp/gitweb.list.$$
48 # Set the proper group, if configured, before the move
49 if [ -n "$cfg_owning_group" ]; then
50 chgrp "$cfg_owning_group" /tmp/gitproj.list.$$ /tmp/gitweb.list.$$
53 # Atomically move into place
54 mv -f /tmp/gitproj.list.$$ "$cfg_projlist_cache_dir/gitproj.list"
55 mv -f /tmp/gitweb.list.$$ "$cfg_projlist_cache_dir/gitweb.list"