3 # Copyright (c) 2006 Eric Wong
9 git instaweb [options] (--start | --stop | --restart)
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)
17 stop stop the web server
18 start start the web server
19 restart restart the web server
25 local="$(git config --bool --get instaweb.local)"
26 httpd
="$(git config --get instaweb.httpd)"
27 root
="$(git config --get instaweb.gitwebdir)"
28 port
=$
(git config
--get instaweb.port
)
29 module_path
="$(git config --get instaweb.modulepath)"
31 conf
="$GIT_DIR/gitweb/httpd.conf"
35 # if installed, it doesn't need further configuration (module_path)
36 test -z "$httpd" && httpd
='lighttpd -f'
38 # Default is @@GITWEBDIR@@
39 test -z "$root" && root
='@@GITWEBDIR@@'
41 # any untaken local port will do...
42 test -z "$port" && port
=1234
44 resolve_full_httpd
() {
47 # ensure that the apache2/lighttpd command ends with "-f"
48 if ! echo "$httpd" | sane_grep
-- '-f *$' >/dev
/null
2>&1
55 httpd_only
="$(echo $httpd | cut -f1 -d' ')"
56 if case "$httpd_only" in /*) : ;; *) which $httpd_only >/dev
/null
2>&1;; esac
60 # many httpds are installed in /usr/sbin or /usr/local/sbin
61 # these days and those are not in most users $PATHs
62 # in addition, we may have generated a server script
63 # in $fqgitdir/gitweb.
64 for i
in /usr
/local
/sbin
/usr
/sbin
"$root" "$fqgitdir/gitweb"
66 if test -x "$i/$httpd_only"
73 echo >&2 "$httpd_only not found. Install $httpd_only or use" \
74 "--httpd to specify another httpd daemon."
80 if test -f "$fqgitdir/pid"; then
81 say
"Instance already running. Restarting..."
85 # here $httpd should have a meaningful value
88 # don't quote $full_httpd, there can be arguments to it (-f)
91 #The mongoose server doesn't have a daemon mode so we'll have to fork it
92 $full_httpd "$fqgitdir/gitweb/httpd.conf" &
93 #Save the pid before doing anything else (we'll print it later)
97 echo "Could not execute http daemon $httpd."
101 cat > "$fqgitdir/pid" <<EOF
106 $full_httpd "$fqgitdir/gitweb/httpd.conf"
107 if test $?
!= 0; then
108 echo "Could not execute http daemon $httpd."
116 test -f "$fqgitdir/pid" && kill $
(cat "$fqgitdir/pid")
117 rm -f "$fqgitdir/pid"
164 mkdir
-p "$GIT_DIR/gitweb/tmp"
165 GIT_EXEC_PATH
="$(git --exec-path)"
167 GITWEB_CONFIG
="$fqgitdir/gitweb/gitweb_config.perl"
168 export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG
171 # generate a standalone server script in $fqgitdir/gitweb.
172 cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
175 options = YAML::load_file(ARGV[0])
176 options[:StartCallback] = proc do
177 File.open(options[:PidFile],"w") do |f|
181 options[:ServerType] = WEBrick::Daemon
182 server = WEBrick::HTTPServer.new(options)
183 ['INT', 'TERM'].each do |signal|
184 trap(signal) {server.shutdown}
188 # generate a shell script to invoke the above ruby script,
189 # which assumes _ruby_ is in the user's $PATH. that's _one_
190 # portable way to run ruby, which could be installed anywhere,
192 cat >"$fqgitdir/gitweb/$httpd" <<EOF
194 exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
196 chmod +x
"$fqgitdir/gitweb/$httpd"
200 :DocumentRoot: "$root"
201 :DirectoryIndex: ["gitweb.cgi"]
202 :PidFile: "$fqgitdir/pid"
204 test "$local" = true
&& echo ':BindAddress: "127.0.0.1"' >> "$conf"
209 server.document-root = "$root"
211 server.modules = ( "mod_setenv", "mod_cgi" )
212 server.indexfiles = ( "gitweb.cgi" )
213 server.pid-file = "$fqgitdir/pid"
214 server.errorlog = "$fqgitdir/gitweb/$httpd_only/error.log"
216 # to enable, add "mod_access", "mod_accesslog" to server.modules
217 # variable above and uncomment this
218 #accesslog.filename = "$fqgitdir/gitweb/$httpd_only/access.log"
220 setenv.add-environment = ( "PATH" => env.PATH, "GITWEB_CONFIG" => env.GITWEB_CONFIG )
222 cgi.assign = ( ".cgi" => "" )
226 ".pdf" => "application/pdf",
227 ".sig" => "application/pgp-signature",
228 ".spl" => "application/futuresplash",
229 ".class" => "application/octet-stream",
230 ".ps" => "application/postscript",
231 ".torrent" => "application/x-bittorrent",
232 ".dvi" => "application/x-dvi",
233 ".gz" => "application/x-gzip",
234 ".pac" => "application/x-ns-proxy-autoconfig",
235 ".swf" => "application/x-shockwave-flash",
236 ".tar.gz" => "application/x-tgz",
237 ".tgz" => "application/x-tgz",
238 ".tar" => "application/x-tar",
239 ".zip" => "application/zip",
240 ".mp3" => "audio/mpeg",
241 ".m3u" => "audio/x-mpegurl",
242 ".wma" => "audio/x-ms-wma",
243 ".wax" => "audio/x-ms-wax",
244 ".ogg" => "application/ogg",
245 ".wav" => "audio/x-wav",
246 ".gif" => "image/gif",
247 ".jpg" => "image/jpeg",
248 ".jpeg" => "image/jpeg",
249 ".png" => "image/png",
250 ".xbm" => "image/x-xbitmap",
251 ".xpm" => "image/x-xpixmap",
252 ".xwd" => "image/x-xwindowdump",
253 ".css" => "text/css",
254 ".html" => "text/html",
255 ".htm" => "text/html",
256 ".js" => "text/javascript",
257 ".asc" => "text/plain",
258 ".c" => "text/plain",
259 ".cpp" => "text/plain",
260 ".log" => "text/plain",
261 ".conf" => "text/plain",
262 ".text" => "text/plain",
263 ".txt" => "text/plain",
264 ".dtd" => "text/xml",
265 ".xml" => "text/xml",
266 ".mpeg" => "video/mpeg",
267 ".mpg" => "video/mpeg",
268 ".mov" => "video/quicktime",
269 ".qt" => "video/quicktime",
270 ".avi" => "video/x-msvideo",
271 ".asf" => "video/x-ms-asf",
272 ".asx" => "video/x-ms-asf",
273 ".wmv" => "video/x-ms-wmv",
274 ".bz2" => "application/x-bzip",
275 ".tbz" => "application/x-bzip-compressed-tar",
276 ".tar.bz2" => "application/x-bzip-compressed-tar",
280 test x
"$local" = xtrue
&& echo 'server.bind = "127.0.0.1"' >> "$conf"
284 test -z "$module_path" && module_path
=/usr
/lib
/apache
2/modules
286 test x
"$local" = xtrue
&& bind='127.0.0.1:'
287 echo 'text/css css' > "$fqgitdir/mime.types"
289 ServerName "git-instaweb"
292 ErrorLog "$fqgitdir/gitweb/$httpd_only/error.log"
293 CustomLog "$fqgitdir/gitweb/$httpd_only/access.log" combined
294 PidFile "$fqgitdir/pid"
298 for mod
in mime dir
; do
299 if test -e $module_path/mod_
${mod}.so
; then
300 echo "LoadModule ${mod}_module " \
301 "$module_path/mod_${mod}.so" >> "$conf"
305 TypesConfig "$fqgitdir/mime.types"
306 DirectoryIndex gitweb.cgi
309 # check to see if Dennis Stosberg's mod_perl compatibility patch
310 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
311 if test -f "$module_path/mod_perl.so" &&
312 sane_grep
'MOD_PERL' "$root/gitweb.cgi" >/dev
/null
314 # favor mod_perl if available
316 LoadModule perl_module $module_path/mod_perl.so
318 PerlPassEnv GIT_EXEC_DIR
319 PerlPassEnv GITWEB_CONFIG
320 <Location /gitweb.cgi>
321 SetHandler perl-script
322 PerlResponseHandler ModPerl::Registry
323 PerlOptions +ParseHeaders
330 list_mods
=$
(echo "$full_httpd" |
sed 's/-f$/-l/')
331 $list_mods | sane_grep
'mod_cgi\.c' >/dev
/null
2>&1 || \
332 if test -f "$module_path/mod_cgi.so"
334 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
336 $list_mods |
grep 'mod_cgid\.c' >/dev
/null
2>&1 || \
337 if test -f "$module_path/mod_cgid.so"
339 echo "LoadModule cgid_module $module_path/mod_cgid.so" \
342 echo "You have no CGI support!"
345 echo "ScriptSock logs/gitweb.sock" >> "$conf"
348 AddHandler cgi-script .cgi
349 <Location /gitweb.cgi>
358 # Mongoose web server configuration file.
359 # Lines starting with '#' and empty lines are ignored.
360 # For detailed description of every option, visit
361 # http://code.google.com/p/mongoose/wiki/MongooseManual
365 index_files gitweb.cgi
366 #ssl_cert $fqgitdir/gitweb/ssl_cert.pem
367 error_log $fqgitdir/gitweb/$httpd_only/error.log
368 access_log $fqgitdir/gitweb/$httpd_only/access.log
371 cgi_env PATH=$PATH,GIT_DIR=$GIT_DIR,GIT_EXEC_PATH=$GIT_EXEC_PATH,GITWEB_CONFIG=$GITWEB_CONFIG
376 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
381 cat > "$fqgitdir/gitweb/gitweb_config.perl" <<EOF
383 our \$projectroot = "$(dirname "$fqgitdir")";
384 our \$git_temp = "$fqgitdir/gitweb/tmp";
385 our \$projects_list = \$projectroot;
392 mkdir
-p "$fqgitdir/gitweb/$httpd_only"
408 echo "Unknown httpd specified: $httpd"
414 url
=http
://127.0.0.1:$port
416 if test -n "$browser"; then
417 git web--browse
-b "$browser" $url ||
echo $url
419 git web--browse
-c "instaweb.browser" $url ||
echo $url