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