]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-instaweb.sh
Makefile: Include subdirectories in "make cover" reports
[thirdparty/git.git] / git-instaweb.sh
index 6635fbefdf2a06e556716f91a70181ecf4f3252a..e6f6ecda177c66a79b18359f7bf8cad9c4744c8c 100755 (executable)
@@ -43,7 +43,8 @@ test -z "$port" && port=1234
 
 resolve_full_httpd () {
        case "$httpd" in
-       *apache2*|*lighttpd*)
+       *apache2*|*lighttpd*|*httpd*)
+               # yes, *httpd* covers *lighttpd* above, but it is there for clarity
                # ensure that the apache2/lighttpd command ends with "-f"
                if ! echo "$httpd" | sane_grep -- '-f *$' >/dev/null 2>&1
                then
@@ -56,6 +57,13 @@ resolve_full_httpd () {
                httpd_only="${httpd%% *}" # cut on first space
                return
                ;;
+       *webrick*)
+               # server is started by running via generated webrick.rb in
+               # $fqgitdir/gitweb
+               full_httpd="$fqgitdir/gitweb/webrick.rb"
+               httpd_only="${httpd%% *}" # cut on first space
+               return
+               ;;
        esac
 
        httpd_only="$(echo $httpd | cut -f1 -d' ')"
@@ -187,40 +195,53 @@ GITWEB_CONFIG="$fqgitdir/gitweb/gitweb_config.perl"
 export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
 
 webrick_conf () {
+       # webrick seems to have no way of passing arbitrary environment
+       # variables to the underlying CGI executable, so we wrap the
+       # actual gitweb.cgi using a shell script to force it
+  wrapper="$fqgitdir/gitweb/$httpd/wrapper.sh"
+       cat > "$wrapper" <<EOF
+#!/bin/sh
+# we use this shell script wrapper around the real gitweb.cgi since
+# there appears to be no other way to pass arbitrary environment variables
+# into the CGI process
+GIT_EXEC_PATH=$GIT_EXEC_PATH GIT_DIR=$GIT_DIR GITWEB_CONFIG=$GITWEB_CONFIG
+export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
+exec $root/gitweb.cgi
+EOF
+       chmod +x "$wrapper"
+
+       # This assumes _ruby_ is in the user's $PATH. that's _one_
+       # portable way to run ruby, which could be installed anywhere, really.
        # generate a standalone server script in $fqgitdir/gitweb.
        cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
+#!/usr/bin/env ruby
 require 'webrick'
-require 'yaml'
-options = YAML::load_file(ARGV[0])
-options[:StartCallback] = proc do
-  File.open(options[:PidFile],"w") do |f|
-    f.puts Process.pid
-  end
-end
-options[:ServerType] = WEBrick::Daemon
+require 'logger'
+options = {
+  :Port => $port,
+  :DocumentRoot => "$root",
+  :Logger => Logger.new('$fqgitdir/gitweb/error.log'),
+  :AccessLog => [
+    [ Logger.new('$fqgitdir/gitweb/access.log'),
+      WEBrick::AccessLog::COMBINED_LOG_FORMAT ]
+  ],
+  :DirectoryIndex => ["gitweb.cgi"],
+  :CGIInterpreter => "$wrapper",
+  :StartCallback => lambda do
+    File.open("$fqgitdir/pid", "w") { |f| f.puts Process.pid }
+  end,
+  :ServerType => WEBrick::Daemon,
+}
+options[:BindAddress] = '127.0.0.1' if "$local" == "true"
 server = WEBrick::HTTPServer.new(options)
 ['INT', 'TERM'].each do |signal|
   trap(signal) {server.shutdown}
 end
 server.start
 EOF
-       # generate a shell script to invoke the above ruby script,
-       # which assumes _ruby_ is in the user's $PATH. that's _one_
-       # portable way to run ruby, which could be installed anywhere,
-       # really.
-       cat >"$fqgitdir/gitweb/$httpd" <<EOF
-#!/bin/sh
-exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
-EOF
-       chmod +x "$fqgitdir/gitweb/$httpd"
-
-       cat >"$conf" <<EOF
-:Port: $port
-:DocumentRoot: "$root"
-:DirectoryIndex: ["gitweb.cgi"]
-:PidFile: "$fqgitdir/pid"
-EOF
-       test "$local" = true && echo ':BindAddress: "127.0.0.1"' >> "$conf"
+       chmod +x "$fqgitdir/gitweb/$httpd.rb"
+       # configuration is embedded in server script file, webrick.rb
+       rm -f "$conf"
 }
 
 lighttpd_conf () {
@@ -300,7 +321,13 @@ EOF
 }
 
 apache2_conf () {
-       test -z "$module_path" && module_path=/usr/lib/apache2/modules
+       if test -z "$module_path"
+       then
+               test -d "/usr/lib/httpd/modules" &&
+                       module_path="/usr/lib/httpd/modules"
+               test -d "/usr/lib/apache2/modules" &&
+                       module_path="/usr/lib/apache2/modules"
+       fi
        bind=
        test x"$local" = xtrue && bind='127.0.0.1:'
        echo 'text/css css' > "$fqgitdir/mime.types"
@@ -314,8 +341,10 @@ PidFile "$fqgitdir/pid"
 Listen $bind$port
 EOF
 
-       for mod in mime dir; do
-               if test -e $module_path/mod_${mod}.so; then
+       for mod in mime dir env log_config
+       do
+               if test -e $module_path/mod_${mod}.so
+               then
                        echo "LoadModule ${mod}_module " \
                             "$module_path/mod_${mod}.so" >> "$conf"
                fi
@@ -334,7 +363,7 @@ EOF
                cat >> "$conf" <<EOF
 LoadModule perl_module $module_path/mod_perl.so
 PerlPassEnv GIT_DIR
-PerlPassEnv GIT_EXEC_DIR
+PerlPassEnv GIT_EXEC_PATH
 PerlPassEnv GITWEB_CONFIG
 <Location /gitweb.cgi>
        SetHandler perl-script
@@ -364,6 +393,9 @@ EOF
                        echo "ScriptSock logs/gitweb.sock" >> "$conf"
                fi
                cat >> "$conf" <<EOF
+PassEnv GIT_DIR
+PassEnv GIT_EXEC_PATH
+PassEnv GITWEB_CONFIG
 AddHandler cgi-script .cgi
 <Location /gitweb.cgi>
        Options +ExecCGI
@@ -560,7 +592,7 @@ case "$httpd" in
 *lighttpd*)
        lighttpd_conf
        ;;
-*apache2*)
+*apache2*|*httpd*)
        apache2_conf
        ;;
 webrick)