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>
Eric Wong committed
Aug 4, 2010 at 09:51 UTC
422bff280297b55aff6542cc5df1c078f37ab673
1 file changed
+27
-2
git-instaweb.sh
+27
-2
@@ -57,6 +57,13 @@ resolve_full_httpd () {
57
httpd_only="${httpd%% *}" # cut on first space
58
return
59
;;
60
+ *webrick*)
61
+ # server is started by running via generated webrick.sh in
62
+ # $fqgitdir/gitweb
63
+ full_httpd="$fqgitdir/gitweb/webrick.sh"
64
+ httpd_only="${httpd%% *}" # cut on first space
65
+ return
66
+ ;;
67
esac
68
69
httpd_only="$(echo $httpd | cut -f1 -d' ')"
@@ -188,6 +195,23 @@ GITWEB_CONFIG="$fqgitdir/gitweb/gitweb_config.perl"
195
export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
196
197
webrick_conf () {
198
+ # webrick seems to have no way of passing arbitrary environment
199
+ # variables to the underlying CGI executable, so we wrap the
200
+ # actual gitweb.cgi using a shell script to force it
201
+ wrapper="$fqgitdir/gitweb/$httpd/wrapper.sh"
202
+ cat > "$wrapper" <<EOF
203
+#!/bin/sh
204
+# we use this shell script wrapper around the real gitweb.cgi since
205
+# there appears to be no other way to pass arbitrary environment variables
206
+# into the CGI process
207
+GIT_EXEC_PATH=$GIT_EXEC_PATH GIT_DIR=$GIT_DIR GITWEB_CONFIG=$GITWEB_CONFIG
208
+export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
209
+exec $root/gitweb.cgi
210
+EOF
211
+ chmod +x "$wrapper"
212
+
213
+ # This assumes _ruby_ is in the user's $PATH. that's _one_
214
+ # portable way to run ruby, which could be installed anywhere, really.
215
# generate a standalone server script in $fqgitdir/gitweb.
216
cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
217
require 'webrick'
@@ -209,17 +233,18 @@ EOF
233
# which assumes _ruby_ is in the user's $PATH. that's _one_
234
# portable way to run ruby, which could be installed anywhere,
235
# really.
212
- cat >"$fqgitdir/gitweb/$httpd" <<EOF
236
+ cat >"$fqgitdir/gitweb/$httpd.sh" <<EOF
237
#!/bin/sh
238
exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
239
EOF
216
- chmod +x "$fqgitdir/gitweb/$httpd"
240
+ chmod +x "$fqgitdir/gitweb/$httpd.sh"
241
242
cat >"$conf" <<EOF
243
:Port: $port
244
:DocumentRoot: "$root"
245
:DirectoryIndex: ["gitweb.cgi"]
246
:PidFile: "$fqgitdir/pid"
247
+:CGIInterpreter: "$wrapper"
248
EOF
249
test "$local" = true && echo ':BindAddress: "127.0.0.1"' >> "$conf"
250
}