-sub new {
- my ($class, $pi_config) = @_;
- my $cgit_bin = $pi_config->{'publicinbox.cgitbin'} ||
- # Debian default location:
- '/usr/lib/cgit/cgit.cgi';
+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;
+ }
+ for (@dirs) {
+ next unless -f "$_/cgit.css";
+ $cgit_data = $_;
+ last;
+ }
+ }
+ ($cgit_bin, $cgit_data);
+}