scripts: purge use of test '-a' and '-o' ops and clean up
[girocco.git] / gitweb / genindex.sh
blob99e24dae234218413136324de84c7749d6c25442
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 test $? -eq 0
34 else
35 get_repo_list | LC_ALL=C sort -k 1,1 |
36 LC_ALL=C join -a 1 - "$cfg_projlist_cache_dir/gitproj.list" |
37 while read proj hash owner; do
38 if [ "$proj" = "$update" ] || [ -z "$owner" ] || [ -z "$hash" ]; then
39 echo "$proj recalc $(cd "$cfg_reporoot/$proj.git" && config_get owner)"
40 else
41 echo "$proj $hash $owner"
43 done | perl -MDigest::MD5=md5_hex -ne \
44 '@_=split;print "$_[0] ",$_[1] eq "recalc"?md5_hex(lc($_[2])):$_[1]," $_[2]\n";' |
45 LC_ALL=C sort -k 1,1 >/tmp/gitproj.list.$$
46 test $? -eq 0
48 cut -d ' ' -f 1,3- </tmp/gitproj.list.$$ | sed -e 's/ /.git /;s/+/%2B/g' >/tmp/gitweb.list.$$
50 # Set the proper group, if configured, before the move
51 if [ -n "$cfg_owning_group" ]; then
52 chgrp "$cfg_owning_group" /tmp/gitproj.list.$$ /tmp/gitweb.list.$$
55 # Atomically move into place
56 mv -f /tmp/gitproj.list.$$ "$cfg_projlist_cache_dir/gitproj.list"
57 mv -f /tmp/gitweb.list.$$ "$cfg_projlist_cache_dir/gitweb.list"