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