Girocco/Config.pm: update for dev.repo.or.cz support
[girocco.git] / gitweb / genindex.sh
blob8b731679652d7fed95c75c702321ec84eb60c6cc
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 GIROCCO_REPOROOT="$cfg_reporoot" && export GIROCCO_REPOROOT
27 if [ -z "$update" ] || [ ! -s "$cfg_projlist_cache_dir/gitproj.list" ]; then
28 # Must read all the owners so don't bother with join at all
29 get_repo_list |
30 perl -I@basedir@ -MDigest::MD5=md5_hex -MCwd=realpath -MGirocco::ConfigUtil \
31 -n -e 'BEGIN{$reporoot=$ENV{GIROCCO_REPOROOT};}' 2>/tmp/gitdir.listu.$$ -e \
32 'chomp; my $p = $_; defined($p) && $p ne "" or next; my $o = "";
33 my $cf = read_config_file_hash("$reporoot/$p.git/config");
34 defined($cf->{"gitweb.owner"}) and $o = $cf->{"gitweb.owner"};
35 print "$p ",md5_hex(lc($o))," $o\n";
36 my $rp = realpath("$reporoot/$p.git");
37 defined($rp) && $rp ne "" and print STDERR "$p $rp\n";' |
38 LC_ALL=C sort -k 1,1 >/tmp/gitproj.list.$$
39 test $? -eq 0
40 LC_ALL=C sort -k 1,1 </tmp/gitdir.listu.$$ >/tmp/gitdir.list.$$
41 rm -f /tmp/gitdir.listu.$$
42 else
43 GIROCCO_UPDATE="$update" && export GIROCCO_UPDATE
44 get_repo_list | LC_ALL=C sort -k 1,1 >/tmp/gitproj.srt.$$
45 LC_ALL=C join -a 1 /tmp/gitproj.srt.$$ "$cfg_projlist_cache_dir/gitproj.list" |
46 perl -I@basedir@ -MDigest::MD5=md5_hex -MGirocco::ConfigUtil \
47 -n -e 'BEGIN{$reporoot=$ENV{GIROCCO_REPOROOT};$update=$ENV{GIROCCO_UPDATE};}' -e \
48 'BEGIN{$mt5=md5_hex("");}
49 chomp; my @f=split(" ",$_,3); push(@f, "") while @f < 3; $f[0] ne "" or next;
50 my $r = $f[0] eq $update || $f[1] eq "" || ($f[2] eq "" && $f[1] ne $mt5);
51 if ($r) {
52 my $o = "";
53 my $cf = read_config_file_hash("$reporoot/$f[0].git/config");
54 defined($cf->{"gitweb.owner"}) and $o = $cf->{"gitweb.owner"};
55 $f[1] = md5_hex(lc($o)); $f[2]=$o;
57 print "$f[0] $f[1] $f[2]\n";' |
58 LC_ALL=C sort -k 1,1 >/tmp/gitproj.list.$$
59 test $? -eq 0
60 LC_ALL=C join -a 1 -t ' ' /tmp/gitproj.srt.$$ "$cfg_projlist_cache_dir/gitdir.list" |
61 perl -MCwd=realpath \
62 -n -e 'BEGIN{$reporoot=$ENV{GIROCCO_REPOROOT};$update=$ENV{GIROCCO_UPDATE};}' -e \
63 'chomp; my @f=split(" ",$_,2); push(@f, "") while @f < 2; $f[0] ne "" or next;
64 my $r = $f[0] eq $update || $f[1] eq "";
65 $r and $f[1] = realpath("$reporoot/$f[0].git");
66 defined($f[1]) && $f[1] ne "" and print "$f[0] $f[1]\n";' |
67 LC_ALL=C sort -k 1,1 >/tmp/gitdir.list.$$
68 test $? -eq 0
69 rm -f /tmp/gitproj.srt.$$
71 cut -d ' ' -f 1,3- </tmp/gitproj.list.$$ | sed -e 's/ /.git /;s/+/%2B/g' >/tmp/gitweb.list.$$
73 # Make sure we are on the correct device before the atomic move
74 rm -f \
75 "$cfg_projlist_cache_dir/gitproj.list.$$" \
76 "$cfg_projlist_cache_dir/gitdir.list.$$" \
77 "$cfg_projlist_cache_dir/gitweb.list.$$"
78 cat /tmp/gitproj.list.$$ >"$cfg_projlist_cache_dir/gitproj.list.$$"
79 cat /tmp/gitdir.list.$$ >"$cfg_projlist_cache_dir/gitdir.list.$$"
80 cat /tmp/gitweb.list.$$ >"$cfg_projlist_cache_dir/gitweb.list.$$"
81 rm -f /tmp/gitproj.list.$$ /tmp/gitdir.list.$$ /tmp/gitweb.list.$$
83 # Set the proper group, if configured, before the move
84 if [ -n "$cfg_owning_group" ]; then
85 chgrp "$cfg_owning_group" \
86 "$cfg_projlist_cache_dir/gitproj.list.$$" \
87 "$cfg_projlist_cache_dir/gitdir.list.$$" \
88 "$cfg_projlist_cache_dir/gitweb.list.$$"
91 # Atomically move into place
92 mv -f "$cfg_projlist_cache_dir/gitproj.list.$$" "$cfg_projlist_cache_dir/gitproj.list"
93 mv -f "$cfg_projlist_cache_dir/gitdir.list.$$" "$cfg_projlist_cache_dir/gitdir.list"
94 mv -f "$cfg_projlist_cache_dir/gitweb.list.$$" "$cfg_projlist_cache_dir/gitweb.list"