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 port
=$
(git config
--get instaweb.port
)
28 module_path
="$(git config --get instaweb.modulepath)"
30 conf
="$GIT_DIR/gitweb/httpd.conf"
34 # if installed, it doesn't need further configuration (module_path)
35 test -z "$httpd" && httpd
='lighttpd -f'
37 # any untaken local port will do...
38 test -z "$port" && port
=1234
40 resolve_full_httpd
() {
43 # ensure that the apache2/lighttpd command ends with "-f"
44 if ! echo "$httpd" |
grep -- '-f *$' >/dev
/null
2>&1
51 httpd_only
="$(echo $httpd | cut -f1 -d' ')"
52 if case "$httpd_only" in /*) : ;; *) which $httpd_only >/dev
/null
2>&1;; esac
56 # many httpds are installed in /usr/sbin or /usr/local/sbin
57 # these days and those are not in most users $PATHs
58 # in addition, we may have generated a server script
59 # in $fqgitdir/gitweb.
60 for i
in /usr
/local
/sbin
/usr
/sbin
"$fqgitdir/gitweb"
62 if test -x "$i/$httpd_only"
69 echo >&2 "$httpd_only not found. Install $httpd_only or use" \
70 "--httpd to specify another httpd daemon."
76 # here $httpd should have a meaningful value
79 # don't quote $full_httpd, there can be arguments to it (-f)
82 #The mongoose server doesn't have a daemon mode so we'll have to fork it
83 $full_httpd "$fqgitdir/gitweb/httpd.conf" &
84 #Save the pid before doing anything else (we'll print it later)
88 echo "Could not execute http daemon $httpd."
92 cat > "$fqgitdir/pid" <<EOF
97 $full_httpd "$fqgitdir/gitweb/httpd.conf"
99 echo "Could not execute http daemon $httpd."
107 test -f "$fqgitdir/pid" && kill $
(cat "$fqgitdir/pid")
154 mkdir
-p "$GIT_DIR/gitweb/tmp"
155 GIT_EXEC_PATH
="$(git --exec-path)"
157 export GIT_EXEC_PATH GIT_DIR
161 # generate a standalone server script in $fqgitdir/gitweb.
162 cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
165 options = YAML::load_file(ARGV[0])
166 options[:StartCallback] = proc do
167 File.open(options[:PidFile],"w") do |f|
171 options[:ServerType] = WEBrick::Daemon
172 server = WEBrick::HTTPServer.new(options)
173 ['INT', 'TERM'].each do |signal|
174 trap(signal) {server.shutdown}
178 # generate a shell script to invoke the above ruby script,
179 # which assumes _ruby_ is in the user's $PATH. that's _one_
180 # portable way to run ruby, which could be installed anywhere,
182 cat >"$fqgitdir/gitweb/$httpd" <<EOF
184 exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
186 chmod +x
"$fqgitdir/gitweb/$httpd"
190 :DocumentRoot: "$fqgitdir/gitweb"
191 :DirectoryIndex: ["gitweb.cgi"]
192 :PidFile: "$fqgitdir/pid"
194 test "$local" = true
&& echo ':BindAddress: "127.0.0.1"' >> "$conf"
199 server.document-root = "$fqgitdir/gitweb"
201 server.modules = ( "mod_setenv", "mod_cgi" )
202 server.indexfiles = ( "gitweb.cgi" )
203 server.pid-file = "$fqgitdir/pid"
204 server.errorlog = "$fqgitdir/gitweb/error.log"
206 # to enable, add "mod_access", "mod_accesslog" to server.modules
207 # variable above and uncomment this
208 #accesslog.filename = "$fqgitdir/gitweb/access.log"
210 setenv.add-environment = ( "PATH" => "/usr/local/bin:/usr/bin:/bin" )
212 cgi.assign = ( ".cgi" => "" )
216 ".pdf" => "application/pdf",
217 ".sig" => "application/pgp-signature",
218 ".spl" => "application/futuresplash",
219 ".class" => "application/octet-stream",
220 ".ps" => "application/postscript",
221 ".torrent" => "application/x-bittorrent",
222 ".dvi" => "application/x-dvi",
223 ".gz" => "application/x-gzip",
224 ".pac" => "application/x-ns-proxy-autoconfig",
225 ".swf" => "application/x-shockwave-flash",
226 ".tar.gz" => "application/x-tgz",
227 ".tgz" => "application/x-tgz",
228 ".tar" => "application/x-tar",
229 ".zip" => "application/zip",
230 ".mp3" => "audio/mpeg",
231 ".m3u" => "audio/x-mpegurl",
232 ".wma" => "audio/x-ms-wma",
233 ".wax" => "audio/x-ms-wax",
234 ".ogg" => "application/ogg",
235 ".wav" => "audio/x-wav",
236 ".gif" => "image/gif",
237 ".jpg" => "image/jpeg",
238 ".jpeg" => "image/jpeg",
239 ".png" => "image/png",
240 ".xbm" => "image/x-xbitmap",
241 ".xpm" => "image/x-xpixmap",
242 ".xwd" => "image/x-xwindowdump",
243 ".css" => "text/css",
244 ".html" => "text/html",
245 ".htm" => "text/html",
246 ".js" => "text/javascript",
247 ".asc" => "text/plain",
248 ".c" => "text/plain",
249 ".cpp" => "text/plain",
250 ".log" => "text/plain",
251 ".conf" => "text/plain",
252 ".text" => "text/plain",
253 ".txt" => "text/plain",
254 ".dtd" => "text/xml",
255 ".xml" => "text/xml",
256 ".mpeg" => "video/mpeg",
257 ".mpg" => "video/mpeg",
258 ".mov" => "video/quicktime",
259 ".qt" => "video/quicktime",
260 ".avi" => "video/x-msvideo",
261 ".asf" => "video/x-ms-asf",
262 ".asx" => "video/x-ms-asf",
263 ".wmv" => "video/x-ms-wmv",
264 ".bz2" => "application/x-bzip",
265 ".tbz" => "application/x-bzip-compressed-tar",
266 ".tar.bz2" => "application/x-bzip-compressed-tar",
270 test x
"$local" = xtrue
&& echo 'server.bind = "127.0.0.1"' >> "$conf"
274 test -z "$module_path" && module_path
=/usr
/lib
/apache
2/modules
275 mkdir
-p "$GIT_DIR/gitweb/logs"
277 test x
"$local" = xtrue
&& bind='127.0.0.1:'
278 echo 'text/css css' > "$fqgitdir/mime.types"
280 ServerName "git-instaweb"
281 ServerRoot "$fqgitdir/gitweb"
282 DocumentRoot "$fqgitdir/gitweb"
283 PidFile "$fqgitdir/pid"
287 for mod
in mime dir
; do
288 if test -e $module_path/mod_
${mod}.so
; then
289 echo "LoadModule ${mod}_module " \
290 "$module_path/mod_${mod}.so" >> "$conf"
294 TypesConfig "$fqgitdir/mime.types"
295 DirectoryIndex gitweb.cgi
298 # check to see if Dennis Stosberg's mod_perl compatibility patch
299 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
300 if test -f "$module_path/mod_perl.so" && grep 'MOD_PERL' \
301 "$GIT_DIR/gitweb/gitweb.cgi" >/dev
/null
303 # favor mod_perl if available
305 LoadModule perl_module $module_path/mod_perl.so
307 PerlPassEnv GIT_EXEC_DIR
308 <Location /gitweb.cgi>
309 SetHandler perl-script
310 PerlResponseHandler ModPerl::Registry
311 PerlOptions +ParseHeaders
318 list_mods
=$
(echo "$full_httpd" |
sed "s/-f$/-l/")
319 $list_mods |
grep 'mod_cgi\.c' >/dev
/null
2>&1 || \
320 if test -f "$module_path/mod_cgi.so"
322 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
324 $list_mods |
grep 'mod_cgid\.c' >/dev
/null
2>&1 || \
325 if test -f "$module_path/mod_cgid.so"
327 echo "LoadModule cgid_module $module_path/mod_cgid.so" \
330 echo "You have no CGI support!"
333 echo "ScriptSock logs/gitweb.sock" >> "$conf"
336 AddHandler cgi-script .cgi
337 <Location /gitweb.cgi>
346 # Mongoose web server configuration file.
347 # Lines starting with '#' and empty lines are ignored.
348 # For detailed description of every option, visit
349 # http://code.google.com/p/mongoose/wiki/MongooseManual
351 root $fqgitdir/gitweb
353 index_files gitweb.cgi
354 #ssl_cert $fqgitdir/gitweb/ssl_cert.pem
355 error_log $fqgitdir/gitweb/error.log
356 access_log $fqgitdir/gitweb/access.log
359 cgi_env PATH=/usr/local/bin:/usr/bin:/bin,GIT_DIR=$GIT_DIR,GIT_EXEC_PATH=$GIT_EXEC_PATH
364 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
370 s#^(my|our) \$projectroot =.*#$1 \$projectroot = "'$
(dirname "$fqgitdir")'";#;
371 s#(my|our) \$gitbin =.*#$1 \$gitbin = "'$GIT_EXEC_PATH'";#;
372 s#(my|our) \$projects_list =.*#$1 \$projects_list = \$projectroot;#;
373 s#(my|our) \$git_temp =.*#$1 \$git_temp = "'$fqgitdir/gitweb
/tmp
'";#;'
376 cat > "$1.tmp" <<\EOFGITWEB
379 # Use the configured full path to perl to match the generated
380 # scripts' 'hashpling' line
381 "$PERL" -p -e "$script" "$1.tmp" > "$1"
387 cat > "$1" <<\EOFGITWEB
393 cat > "$1" <<\EOFGITWEB
398 gitweb_cgi
"$GIT_DIR/gitweb/gitweb.cgi"
399 gitweb_css
"$GIT_DIR/gitweb/gitweb.css"
400 gitweb_gitwebjs
"$GIT_DIR/gitweb/gitweb.js"
416 echo "Unknown httpd specified: $httpd"
422 url
=http
://127.0.0.1:$port
424 if test -n "$browser"; then
425 git web--browse
-b "$browser" $url ||
echo $url
427 git web--browse
-c "instaweb.browser" $url ||
echo $url