instaweb: fix WEBrick server support

This has been broken since commit be5347b ("httpd logs in a
"$httpd_only" subdirectory").

Since WEBrick has no other way of preserving environment
variables needed for gitweb, we create a shell script wrapper
that sets the environment variables as our CGI interpreter
to run gitweb.cgi.

Signed-off-by: Eric Wong <normalperson@yhbt.net>
This commit is contained in:
Eric Wong 2010-08-04 09:51:25 +00:00
Родитель 721e76cbfa
Коммит 422bff2802
1 изменённых файлов: 27 добавлений и 2 удалений

Просмотреть файл

@ -57,6 +57,13 @@ resolve_full_httpd () {
httpd_only="${httpd%% *}" # cut on first space httpd_only="${httpd%% *}" # cut on first space
return return
;; ;;
*webrick*)
# server is started by running via generated webrick.sh in
# $fqgitdir/gitweb
full_httpd="$fqgitdir/gitweb/webrick.sh"
httpd_only="${httpd%% *}" # cut on first space
return
;;
esac esac
httpd_only="$(echo $httpd | cut -f1 -d' ')" httpd_only="$(echo $httpd | cut -f1 -d' ')"
@ -188,6 +195,23 @@ GITWEB_CONFIG="$fqgitdir/gitweb/gitweb_config.perl"
export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
webrick_conf () { 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. # generate a standalone server script in $fqgitdir/gitweb.
cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
require 'webrick' require 'webrick'
@ -209,17 +233,18 @@ EOF
# which assumes _ruby_ is in the user's $PATH. that's _one_ # which assumes _ruby_ is in the user's $PATH. that's _one_
# portable way to run ruby, which could be installed anywhere, # portable way to run ruby, which could be installed anywhere,
# really. # really.
cat >"$fqgitdir/gitweb/$httpd" <<EOF cat >"$fqgitdir/gitweb/$httpd.sh" <<EOF
#!/bin/sh #!/bin/sh
exec ruby "$fqgitdir/gitweb/$httpd.rb" \$* exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
EOF EOF
chmod +x "$fqgitdir/gitweb/$httpd" chmod +x "$fqgitdir/gitweb/$httpd.sh"
cat >"$conf" <<EOF cat >"$conf" <<EOF
:Port: $port :Port: $port
:DocumentRoot: "$root" :DocumentRoot: "$root"
:DirectoryIndex: ["gitweb.cgi"] :DirectoryIndex: ["gitweb.cgi"]
:PidFile: "$fqgitdir/pid" :PidFile: "$fqgitdir/pid"
:CGIInterpreter: "$wrapper"
EOF EOF
test "$local" = true && echo ':BindAddress: "127.0.0.1"' >> "$conf" test "$local" = true && echo ':BindAddress: "127.0.0.1"' >> "$conf"
} }