+use PublicInbox::WwwStatic qw(r);
+
+sub locate_cgit ($) {
+ my ($pi_cfg) = @_;
+ my $cgit_bin = $pi_cfg->{'publicinbox.cgitbin'};
+ my $cgit_data = $pi_cfg->{'publicinbox.cgitdata'};
+
+ # /var/www/htdocs/cgit is the default install path from cgit.git
+ # /usr/{lib,share}/cgit is where Debian puts cgit
+ # TODO: check other distros for common paths
+ unless (defined $cgit_bin) {
+ foreach (qw(/var/www/htdocs/cgit /usr/lib/cgit)) {
+ my $x = "$_/cgit.cgi";
+ next unless -x $x;
+ $cgit_bin = $x;
+ last;
+ }
+ }
+ unless (defined $cgit_data) {
+ my @dirs = qw(/var/www/htdocs/cgit /usr/share/cgit);
+
+ # local installs of cgit from source have
+ # CGIT_SCRIPT_PATH==CGIT_DATA_PATH by default,
+ # so we can usually infer the cgit_data path from cgit_bin
+ if (defined($cgit_bin) && $cgit_bin =~ m!\A(.+?)/[^/]+\z!) {
+ unshift @dirs, $1 if -d $1;
+ }
+ foreach my $d (@dirs) {
+ my $f = "$d/cgit.css";
+ next unless -f $f;
+ $cgit_data = $d;
+ last;
+ }
+ }
+ ($cgit_bin, $cgit_data);
+}