]> git.ipfire.org Git - thirdparty/git.git/blame - git-instaweb.sh
compat: convert modes to use portable file type values
[thirdparty/git.git] / git-instaweb.sh
CommitLineData
a51d37c1
EW
1#!/bin/sh
2#
3# Copyright (c) 2006 Eric Wong
4#
c2db2e0e 5
c5699693 6PERL='@@PERL@@'
c2db2e0e 7OPTIONS_KEEPDASHDASH=
51ba8ce3 8OPTIONS_STUCKLONG=
c2db2e0e 9OPTIONS_SPEC="\
1b1dd23f 10git instaweb [options] (--start | --stop | --restart)
c2db2e0e
PH
11--
12l,local only bind on 127.0.0.1
13p,port= the port to bind to
14d,httpd= the command to launch
15b,browser= the browser to launch
16m,module-path= the module path (only needed for apache2)
17 Action
18stop stop the web server
19start start the web server
20restart restart the web server
21"
a51d37c1
EW
22
23. git-sh-setup
24
b2bc9a30 25fqgitdir="$GIT_DIR"
43d60d2e
FP
26local="$(git config --bool --get instaweb.local)"
27httpd="$(git config --get instaweb.httpd)"
c0cb4ed3 28root="$(git config --get instaweb.gitwebdir)"
43d60d2e
FP
29port=$(git config --get instaweb.port)
30module_path="$(git config --get instaweb.modulepath)"
c0175f92 31action="browse"
a51d37c1 32
9126425d 33conf="$GIT_DIR/gitweb/httpd.conf"
a51d37c1
EW
34
35# Defaults:
36
82e5a82f 37# if installed, it doesn't need further configuration (module_path)
a51d37c1
EW
38test -z "$httpd" && httpd='lighttpd -f'
39
c0cb4ed3
PKS
40# Default is @@GITWEBDIR@@
41test -z "$root" && root='@@GITWEBDIR@@'
42
a51d37c1
EW
43# any untaken local port will do...
44test -z "$port" && port=1234
45
43d60d2e
FP
46resolve_full_httpd () {
47 case "$httpd" in
4bdf8599
DM
48 *apache2*|*lighttpd*|*httpd*)
49 # yes, *httpd* covers *lighttpd* above, but it is there for clarity
43d60d2e 50 # ensure that the apache2/lighttpd command ends with "-f"
e1622bfc 51 if ! echo "$httpd" | sane_grep -- '-f *$' >/dev/null 2>&1
43d60d2e
FP
52 then
53 httpd="$httpd -f"
54 fi
55 ;;
78646987
JN
56 *plackup*)
57 # server is started by running via generated gitweb.psgi in $fqgitdir/gitweb
58 full_httpd="$fqgitdir/gitweb/gitweb.psgi"
59 httpd_only="${httpd%% *}" # cut on first space
60 return
61 ;;
422bff28 62 *webrick*)
f46e1304 63 # server is started by running via generated webrick.rb in
422bff28 64 # $fqgitdir/gitweb
f46e1304 65 full_httpd="$fqgitdir/gitweb/webrick.rb"
422bff28
EW
66 httpd_only="${httpd%% *}" # cut on first space
67 return
68 ;;
43d60d2e
FP
69 esac
70
71 httpd_only="$(echo $httpd | cut -f1 -d' ')"
e47eec8f 72 if case "$httpd_only" in /*) : ;; *) which $httpd_only >/dev/null 2>&1;; esac
a51d37c1 73 then
43d60d2e 74 full_httpd=$httpd
a51d37c1
EW
75 else
76 # many httpds are installed in /usr/sbin or /usr/local/sbin
77 # these days and those are not in most users $PATHs
14b45b66
MD
78 # in addition, we may have generated a server script
79 # in $fqgitdir/gitweb.
c0cb4ed3 80 for i in /usr/local/sbin /usr/sbin "$root" "$fqgitdir/gitweb"
a51d37c1
EW
81 do
82 if test -x "$i/$httpd_only"
83 then
43d60d2e 84 full_httpd=$i/$httpd
a51d37c1
EW
85 return
86 fi
87 done
43d60d2e
FP
88
89 echo >&2 "$httpd_only not found. Install $httpd_only or use" \
90 "--httpd to specify another httpd daemon."
f281e3a1 91 exit 1
a51d37c1 92 fi
43d60d2e
FP
93}
94
95start_httpd () {
0b624b4c
SB
96 if test -f "$fqgitdir/pid"; then
97 say "Instance already running. Restarting..."
98 stop_httpd
99 fi
100
43d60d2e
FP
101 # here $httpd should have a meaningful value
102 resolve_full_httpd
5ad6d387
JN
103 mkdir -p "$fqgitdir/gitweb/$httpd_only"
104 conf="$fqgitdir/gitweb/$httpd_only.conf"
105
106 # generate correct config file if it doesn't exist
107 test -f "$conf" || configure_httpd
108 test -f "$fqgitdir/gitweb/gitweb_config.perl" || gitweb_conf
43d60d2e
FP
109
110 # don't quote $full_httpd, there can be arguments to it (-f)
0ded4758 111 case "$httpd" in
78646987
JN
112 *mongoose*|*plackup*)
113 #These servers don't have a daemon mode so we'll have to fork it
48bf76ca 114 $full_httpd "$conf" &
0ded4758
WL
115 #Save the pid before doing anything else (we'll print it later)
116 pid=$!
117
118 if test $? != 0; then
119 echo "Could not execute http daemon $httpd."
120 exit 1
121 fi
122
123 cat > "$fqgitdir/pid" <<EOF
124$pid
125EOF
126 ;;
127 *)
48bf76ca 128 $full_httpd "$conf"
0ded4758
WL
129 if test $? != 0; then
130 echo "Could not execute http daemon $httpd."
131 exit 1
132 fi
133 ;;
134 esac
a51d37c1
EW
135}
136
137stop_httpd () {
43d60d2e 138 test -f "$fqgitdir/pid" && kill $(cat "$fqgitdir/pid")
d1127622 139 rm -f "$fqgitdir/pid"
a51d37c1
EW
140}
141
d94775e1
JN
142httpd_is_ready () {
143 "$PERL" -MIO::Socket::INET -e "
144local \$| = 1; # turn on autoflush
145exit if (IO::Socket::INET->new('127.0.0.1:$port'));
146print 'Waiting for \'$httpd\' to start ..';
147do {
148 print '.';
149 sleep(1);
150} until (IO::Socket::INET->new('127.0.0.1:$port'));
151print qq! (done)\n!;
152"
153}
154
822f7c73 155while test $# != 0
a51d37c1
EW
156do
157 case "$1" in
158 --stop|stop)
c0175f92 159 action="stop"
a51d37c1
EW
160 ;;
161 --start|start)
c0175f92 162 action="start"
a51d37c1
EW
163 ;;
164 --restart|restart)
c0175f92 165 action="restart"
a51d37c1 166 ;;
c2db2e0e 167 -l|--local)
a51d37c1
EW
168 local=true
169 ;;
c2db2e0e
PH
170 -d|--httpd)
171 shift
172 httpd="$1"
173 ;;
174 -b|--browser)
175 shift
176 browser="$1"
a51d37c1 177 ;;
c2db2e0e
PH
178 -p|--port)
179 shift
180 port="$1"
a51d37c1 181 ;;
c2db2e0e
PH
182 -m|--module-path)
183 shift
184 module_path="$1"
a51d37c1 185 ;;
c2db2e0e 186 --)
a51d37c1
EW
187 ;;
188 *)
189 usage
190 ;;
191 esac
192 shift
193done
194
195mkdir -p "$GIT_DIR/gitweb/tmp"
43d60d2e 196GIT_EXEC_PATH="$(git --exec-path)"
a51d37c1 197GIT_DIR="$fqgitdir"
c0cb4ed3
PKS
198GITWEB_CONFIG="$fqgitdir/gitweb/gitweb_config.perl"
199export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
a51d37c1 200
425b78e8 201webrick_conf () {
422bff28
EW
202 # webrick seems to have no way of passing arbitrary environment
203 # variables to the underlying CGI executable, so we wrap the
204 # actual gitweb.cgi using a shell script to force it
205 wrapper="$fqgitdir/gitweb/$httpd/wrapper.sh"
206 cat > "$wrapper" <<EOF
207#!/bin/sh
208# we use this shell script wrapper around the real gitweb.cgi since
209# there appears to be no other way to pass arbitrary environment variables
210# into the CGI process
211GIT_EXEC_PATH=$GIT_EXEC_PATH GIT_DIR=$GIT_DIR GITWEB_CONFIG=$GITWEB_CONFIG
212export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
213exec $root/gitweb.cgi
214EOF
215 chmod +x "$wrapper"
216
217 # This assumes _ruby_ is in the user's $PATH. that's _one_
218 # portable way to run ruby, which could be installed anywhere, really.
425b78e8
MD
219 # generate a standalone server script in $fqgitdir/gitweb.
220 cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
f46e1304 221#!/usr/bin/env ruby
425b78e8 222require 'webrick'
e9323e7f 223require 'logger'
f46e1304
EW
224options = {
225 :Port => $port,
226 :DocumentRoot => "$root",
e9323e7f
EW
227 :Logger => Logger.new('$fqgitdir/gitweb/error.log'),
228 :AccessLog => [
229 [ Logger.new('$fqgitdir/gitweb/access.log'),
230 WEBrick::AccessLog::COMBINED_LOG_FORMAT ]
231 ],
f46e1304
EW
232 :DirectoryIndex => ["gitweb.cgi"],
233 :CGIInterpreter => "$wrapper",
234 :StartCallback => lambda do
235 File.open("$fqgitdir/pid", "w") { |f| f.puts Process.pid }
236 end,
237 :ServerType => WEBrick::Daemon,
238}
239options[:BindAddress] = '127.0.0.1' if "$local" == "true"
425b78e8
MD
240server = WEBrick::HTTPServer.new(options)
241['INT', 'TERM'].each do |signal|
242 trap(signal) {server.shutdown}
243end
244server.start
245EOF
f46e1304
EW
246 chmod +x "$fqgitdir/gitweb/$httpd.rb"
247 # configuration is embedded in server script file, webrick.rb
248 rm -f "$conf"
425b78e8
MD
249}
250
a51d37c1
EW
251lighttpd_conf () {
252 cat > "$conf" <<EOF
c0cb4ed3 253server.document-root = "$root"
a51d37c1 254server.port = $port
e47eec8f 255server.modules = ( "mod_setenv", "mod_cgi" )
a51d37c1
EW
256server.indexfiles = ( "gitweb.cgi" )
257server.pid-file = "$fqgitdir/pid"
be5347b3 258server.errorlog = "$fqgitdir/gitweb/$httpd_only/error.log"
e47eec8f
RJ
259
260# to enable, add "mod_access", "mod_accesslog" to server.modules
261# variable above and uncomment this
be5347b3 262#accesslog.filename = "$fqgitdir/gitweb/$httpd_only/access.log"
e47eec8f 263
c0cb4ed3 264setenv.add-environment = ( "PATH" => env.PATH, "GITWEB_CONFIG" => env.GITWEB_CONFIG )
e47eec8f 265
a51d37c1 266cgi.assign = ( ".cgi" => "" )
e47eec8f
RJ
267
268# mimetype mapping
269mimetype.assign = (
270 ".pdf" => "application/pdf",
271 ".sig" => "application/pgp-signature",
272 ".spl" => "application/futuresplash",
273 ".class" => "application/octet-stream",
274 ".ps" => "application/postscript",
275 ".torrent" => "application/x-bittorrent",
276 ".dvi" => "application/x-dvi",
277 ".gz" => "application/x-gzip",
278 ".pac" => "application/x-ns-proxy-autoconfig",
279 ".swf" => "application/x-shockwave-flash",
280 ".tar.gz" => "application/x-tgz",
281 ".tgz" => "application/x-tgz",
282 ".tar" => "application/x-tar",
283 ".zip" => "application/zip",
284 ".mp3" => "audio/mpeg",
285 ".m3u" => "audio/x-mpegurl",
286 ".wma" => "audio/x-ms-wma",
287 ".wax" => "audio/x-ms-wax",
288 ".ogg" => "application/ogg",
289 ".wav" => "audio/x-wav",
290 ".gif" => "image/gif",
291 ".jpg" => "image/jpeg",
292 ".jpeg" => "image/jpeg",
293 ".png" => "image/png",
294 ".xbm" => "image/x-xbitmap",
295 ".xpm" => "image/x-xpixmap",
296 ".xwd" => "image/x-xwindowdump",
297 ".css" => "text/css",
298 ".html" => "text/html",
299 ".htm" => "text/html",
300 ".js" => "text/javascript",
301 ".asc" => "text/plain",
302 ".c" => "text/plain",
303 ".cpp" => "text/plain",
304 ".log" => "text/plain",
305 ".conf" => "text/plain",
306 ".text" => "text/plain",
307 ".txt" => "text/plain",
308 ".dtd" => "text/xml",
309 ".xml" => "text/xml",
310 ".mpeg" => "video/mpeg",
311 ".mpg" => "video/mpeg",
312 ".mov" => "video/quicktime",
313 ".qt" => "video/quicktime",
314 ".avi" => "video/x-msvideo",
315 ".asf" => "video/x-ms-asf",
316 ".asx" => "video/x-ms-asf",
317 ".wmv" => "video/x-ms-wmv",
318 ".bz2" => "application/x-bzip",
319 ".tbz" => "application/x-bzip-compressed-tar",
320 ".tar.bz2" => "application/x-bzip-compressed-tar",
321 "" => "text/plain"
322 )
a51d37c1 323EOF
9126425d 324 test x"$local" = xtrue && echo 'server.bind = "127.0.0.1"' >> "$conf"
a51d37c1
EW
325}
326
327apache2_conf () {
4bdf8599
DM
328 if test -z "$module_path"
329 then
330 test -d "/usr/lib/httpd/modules" &&
331 module_path="/usr/lib/httpd/modules"
332 test -d "/usr/lib/apache2/modules" &&
333 module_path="/usr/lib/apache2/modules"
334 fi
a51d37c1 335 bind=
9126425d 336 test x"$local" = xtrue && bind='127.0.0.1:'
e24c76bf 337 echo 'text/css css' > "$fqgitdir/mime.types"
a51d37c1 338 cat > "$conf" <<EOF
44a167b0 339ServerName "git-instaweb"
c0cb4ed3
PKS
340ServerRoot "$root"
341DocumentRoot "$root"
be5347b3
PKS
342ErrorLog "$fqgitdir/gitweb/$httpd_only/error.log"
343CustomLog "$fqgitdir/gitweb/$httpd_only/access.log" combined
a51d37c1
EW
344PidFile "$fqgitdir/pid"
345Listen $bind$port
44a167b0
EW
346EOF
347
f8ee1f02
JM
348 for mod in mpm_event mpm_prefork mpm_worker
349 do
350 if test -e $module_path/mod_${mod}.so
351 then
352 echo "LoadModule ${mod}_module " \
353 "$module_path/mod_${mod}.so" >> "$conf"
354 # only one mpm module permitted
355 break
356 fi
357 done
358 for mod in mime dir env log_config authz_core
4bdf8599
DM
359 do
360 if test -e $module_path/mod_${mod}.so
361 then
44a167b0
EW
362 echo "LoadModule ${mod}_module " \
363 "$module_path/mod_${mod}.so" >> "$conf"
364 fi
365 done
366 cat >> "$conf" <<EOF
e24c76bf 367TypesConfig "$fqgitdir/mime.types"
a51d37c1
EW
368DirectoryIndex gitweb.cgi
369EOF
370
371 # check to see if Dennis Stosberg's mod_perl compatibility patch
372 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
e1622bfc 373 if test -f "$module_path/mod_perl.so" &&
c0cb4ed3 374 sane_grep 'MOD_PERL' "$root/gitweb.cgi" >/dev/null
a51d37c1
EW
375 then
376 # favor mod_perl if available
377 cat >> "$conf" <<EOF
378LoadModule perl_module $module_path/mod_perl.so
379PerlPassEnv GIT_DIR
2989f516 380PerlPassEnv GIT_EXEC_PATH
c0cb4ed3 381PerlPassEnv GITWEB_CONFIG
a51d37c1
EW
382<Location /gitweb.cgi>
383 SetHandler perl-script
384 PerlResponseHandler ModPerl::Registry
385 PerlOptions +ParseHeaders
386 Options +ExecCGI
387</Location>
388EOF
389 else
390 # plain-old CGI
43d60d2e 391 resolve_full_httpd
9524cf29 392 list_mods=$(echo "$full_httpd" | sed 's/-f$/-l/')
e1622bfc 393 $list_mods | sane_grep 'mod_cgi\.c' >/dev/null 2>&1 || \
10d1432a
MR
394 if test -f "$module_path/mod_cgi.so"
395 then
396 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
397 else
398 $list_mods | grep 'mod_cgid\.c' >/dev/null 2>&1 || \
399 if test -f "$module_path/mod_cgid.so"
400 then
401 echo "LoadModule cgid_module $module_path/mod_cgid.so" \
402 >> "$conf"
403 else
404 echo "You have no CGI support!"
405 exit 2
406 fi
407 echo "ScriptSock logs/gitweb.sock" >> "$conf"
408 fi
a51d37c1 409 cat >> "$conf" <<EOF
2989f516
DM
410PassEnv GIT_DIR
411PassEnv GIT_EXEC_PATH
412PassEnv GITWEB_CONFIG
a51d37c1
EW
413AddHandler cgi-script .cgi
414<Location /gitweb.cgi>
415 Options +ExecCGI
416</Location>
417EOF
418 fi
419}
420
0ded4758
WL
421mongoose_conf() {
422 cat > "$conf" <<EOF
423# Mongoose web server configuration file.
424# Lines starting with '#' and empty lines are ignored.
425# For detailed description of every option, visit
426# http://code.google.com/p/mongoose/wiki/MongooseManual
427
c0cb4ed3 428root $root
0ded4758
WL
429ports $port
430index_files gitweb.cgi
431#ssl_cert $fqgitdir/gitweb/ssl_cert.pem
be5347b3
PKS
432error_log $fqgitdir/gitweb/$httpd_only/error.log
433access_log $fqgitdir/gitweb/$httpd_only/access.log
0ded4758
WL
434
435#cgi setup
c0cb4ed3 436cgi_env PATH=$PATH,GIT_DIR=$GIT_DIR,GIT_EXEC_PATH=$GIT_EXEC_PATH,GITWEB_CONFIG=$GITWEB_CONFIG
0ded4758
WL
437cgi_interp $PERL
438cgi_ext cgi,pl
439
440# mimetype mapping
441mime_types .gz=application/x-gzip,.tar.gz=application/x-tgz,.tgz=application/x-tgz,.tar=application/x-tar,.zip=application/zip,.gif=image/gif,.jpg=image/jpeg,.jpeg=image/jpeg,.png=image/png,.css=text/css,.html=text/html,.htm=text/html,.js=text/javascript,.c=text/plain,.cpp=text/plain,.log=text/plain,.conf=text/plain,.text=text/plain,.txt=text/plain,.dtd=text/xml,.bz2=application/x-bzip,.tbz=application/x-bzip-compressed-tar,.tar.bz2=application/x-bzip-compressed-tar
442EOF
443}
444
78646987
JN
445plackup_conf () {
446 # generate a standalone 'plackup' server script in $fqgitdir/gitweb
447 # with embedded configuration; it does not use "$conf" file
448 cat > "$fqgitdir/gitweb/gitweb.psgi" <<EOF
449#!$PERL
450
451# gitweb - simple web interface to track changes in git repositories
452# PSGI wrapper and server starter (see http://plackperl.org)
453
454use strict;
455
456use IO::Handle;
457use Plack::MIME;
458use Plack::Builder;
459use Plack::App::WrapCGI;
460use CGI::Emulate::PSGI 0.07; # minimum version required to work with gitweb
461
462# mimetype mapping (from lighttpd_conf)
463Plack::MIME->add_type(
464 ".pdf" => "application/pdf",
465 ".sig" => "application/pgp-signature",
466 ".spl" => "application/futuresplash",
467 ".class" => "application/octet-stream",
468 ".ps" => "application/postscript",
469 ".torrent" => "application/x-bittorrent",
470 ".dvi" => "application/x-dvi",
471 ".gz" => "application/x-gzip",
472 ".pac" => "application/x-ns-proxy-autoconfig",
473 ".swf" => "application/x-shockwave-flash",
474 ".tar.gz" => "application/x-tgz",
475 ".tgz" => "application/x-tgz",
476 ".tar" => "application/x-tar",
477 ".zip" => "application/zip",
478 ".mp3" => "audio/mpeg",
479 ".m3u" => "audio/x-mpegurl",
480 ".wma" => "audio/x-ms-wma",
481 ".wax" => "audio/x-ms-wax",
482 ".ogg" => "application/ogg",
483 ".wav" => "audio/x-wav",
484 ".gif" => "image/gif",
485 ".jpg" => "image/jpeg",
486 ".jpeg" => "image/jpeg",
487 ".png" => "image/png",
488 ".xbm" => "image/x-xbitmap",
489 ".xpm" => "image/x-xpixmap",
490 ".xwd" => "image/x-xwindowdump",
491 ".css" => "text/css",
492 ".html" => "text/html",
493 ".htm" => "text/html",
494 ".js" => "text/javascript",
495 ".asc" => "text/plain",
496 ".c" => "text/plain",
497 ".cpp" => "text/plain",
498 ".log" => "text/plain",
499 ".conf" => "text/plain",
500 ".text" => "text/plain",
501 ".txt" => "text/plain",
502 ".dtd" => "text/xml",
503 ".xml" => "text/xml",
504 ".mpeg" => "video/mpeg",
505 ".mpg" => "video/mpeg",
506 ".mov" => "video/quicktime",
507 ".qt" => "video/quicktime",
508 ".avi" => "video/x-msvideo",
509 ".asf" => "video/x-ms-asf",
510 ".asx" => "video/x-ms-asf",
511 ".wmv" => "video/x-ms-wmv",
512 ".bz2" => "application/x-bzip",
513 ".tbz" => "application/x-bzip-compressed-tar",
514 ".tar.bz2" => "application/x-bzip-compressed-tar",
515 "" => "text/plain"
516);
517
518my \$app = builder {
519 # to be able to override \$SIG{__WARN__} to log build time warnings
520 use CGI::Carp; # it sets \$SIG{__WARN__} itself
521
522 my \$logdir = "$fqgitdir/gitweb/$httpd_only";
523 open my \$access_log_fh, '>>', "\$logdir/access.log"
524 or die "Couldn't open access log '\$logdir/access.log': \$!";
525 open my \$error_log_fh, '>>', "\$logdir/error.log"
526 or die "Couldn't open error log '\$logdir/error.log': \$!";
527
528 \$access_log_fh->autoflush(1);
529 \$error_log_fh->autoflush(1);
530
531 # redirect build time warnings to error.log
532 \$SIG{'__WARN__'} = sub {
533 my \$msg = shift;
534 # timestamp warning like in CGI::Carp::warn
535 my \$stamp = CGI::Carp::stamp();
536 \$msg =~ s/^/\$stamp/gm;
537 print \$error_log_fh \$msg;
538 };
539
540 # write errors to error.log, access to access.log
541 enable 'AccessLog',
542 format => "combined",
543 logger => sub { print \$access_log_fh @_; };
544 enable sub {
545 my \$app = shift;
546 sub {
547 my \$env = shift;
548 \$env->{'psgi.errors'} = \$error_log_fh;
549 \$app->(\$env);
550 }
551 };
552 # gitweb currently doesn't work with $SIG{CHLD} set to 'IGNORE',
553 # because it uses 'close $fd or die...' on piped filehandle $fh
554 # (which causes the parent process to wait for child to finish).
555 enable_if { \$SIG{'CHLD'} eq 'IGNORE' } sub {
556 my \$app = shift;
557 sub {
558 my \$env = shift;
559 local \$SIG{'CHLD'} = 'DEFAULT';
560 local \$SIG{'CLD'} = 'DEFAULT';
561 \$app->(\$env);
562 }
563 };
564 # serve static files, i.e. stylesheet, images, script
565 enable 'Static',
566 path => sub { m!\.(js|css|png)\$! && s!^/gitweb/!! },
567 root => "$root/",
568 encoding => 'utf-8'; # encoding for 'text/plain' files
569 # convert CGI application to PSGI app
570 Plack::App::WrapCGI->new(script => "$root/gitweb.cgi")->to_app;
571};
572
573# make it runnable as standalone app,
574# like it would be run via 'plackup' utility
20e7ab8a
JN
575if (caller) {
576 return \$app;
577} else {
78646987
JN
578 require Plack::Runner;
579
580 my \$runner = Plack::Runner->new();
581 \$runner->parse_options(qw(--env deployment --port $port),
20e7ab8a 582 "$local" ? qw(--host 127.0.0.1) : ());
78646987
JN
583 \$runner->run(\$app);
584}
585__END__
586EOF
587
588 chmod a+x "$fqgitdir/gitweb/gitweb.psgi"
589 # configuration is embedded in server script file, gitweb.psgi
590 rm -f "$conf"
591}
592
c0cb4ed3
PKS
593gitweb_conf() {
594 cat > "$fqgitdir/gitweb/gitweb_config.perl" <<EOF
fcb06a8d 595#!@@PERL@@
c0cb4ed3
PKS
596our \$projectroot = "$(dirname "$fqgitdir")";
597our \$git_temp = "$fqgitdir/gitweb/tmp";
598our \$projects_list = \$projectroot;
fc5b8e01
GB
599
600\$feature{'remote_heads'}{'default'} = [1];
c0cb4ed3 601EOF
4af819d4
JN
602}
603
db61f060
JN
604configure_httpd() {
605 case "$httpd" in
606 *lighttpd*)
607 lighttpd_conf
608 ;;
609 *apache2*|*httpd*)
610 apache2_conf
611 ;;
612 webrick)
613 webrick_conf
614 ;;
615 *mongoose*)
616 mongoose_conf
617 ;;
618 *plackup*)
619 plackup_conf
620 ;;
621 *)
622 echo "Unknown httpd specified: $httpd"
623 exit 1
624 ;;
625 esac
626}
627
c0175f92
JN
628case "$action" in
629stop)
630 stop_httpd
631 exit 0
632 ;;
633start)
634 start_httpd
635 exit 0
636 ;;
637restart)
638 stop_httpd
639 start_httpd
640 exit 0
641 ;;
642esac
643
c0cb4ed3 644gitweb_conf
a51d37c1 645
be5347b3
PKS
646resolve_full_httpd
647mkdir -p "$fqgitdir/gitweb/$httpd_only"
5ad6d387 648conf="$fqgitdir/gitweb/$httpd_only.conf"
be5347b3 649
db61f060 650configure_httpd
a51d37c1
EW
651
652start_httpd
5209eda8 653url=http://127.0.0.1:$port
2e0c2902
CC
654
655if test -n "$browser"; then
d94775e1 656 httpd_is_ready && git web--browse -b "$browser" $url || echo $url
2e0c2902 657else
d94775e1 658 httpd_is_ready && git web--browse -c "instaweb.browser" $url || echo $url
2e0c2902 659fi