3 # Copyright (c) 2006 Eric Wong
8 git-instaweb [options] (--start | --stop | --restart)
10 l,local only bind on 127.0.0.1
11 p,port= the port to bind to
12 d,httpd= the command to launch
13 b,browser= the browser to launch
14 m,module-path= the module path (only needed for apache2)
16 stop stop the web server
17 start start the web server
18 restart restart the web server
24 local="`git config --bool --get instaweb.local`"
25 httpd
="`git config --get instaweb.httpd`"
26 browser
="`git config --get instaweb.browser`"
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 # probably the most popular browser among gitweb users
38 test -z "$browser" && browser
='firefox'
40 # any untaken local port will do...
41 test -z "$port" && port
=1234
44 httpd_only
="`echo $httpd | cut -f1 -d' '`"
45 if case "$httpd_only" in /*) : ;; *) which $httpd_only >/dev
/null
;; esac
47 $httpd "$fqgitdir/gitweb/httpd.conf"
49 # many httpds are installed in /usr/sbin or /usr/local/sbin
50 # these days and those are not in most users $PATHs
51 # in addition, we may have generated a server script
52 # in $fqgitdir/gitweb.
53 for i
in /usr
/local
/sbin
/usr
/sbin
"$fqgitdir/gitweb"
55 if test -x "$i/$httpd_only"
57 # don't quote $httpd, there can be
58 # arguments to it (-f)
59 $i/$httpd "$fqgitdir/gitweb/httpd.conf"
63 echo "$httpd_only not found. Install $httpd_only or use" \
64 "--httpd to specify another http daemon."
68 echo "Could not execute http daemon $httpd."
74 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
121 mkdir
-p "$GIT_DIR/gitweb/tmp"
122 GIT_EXEC_PATH
="`git --exec-path`"
124 export GIT_EXEC_PATH GIT_DIR
128 # generate a standalone server script in $fqgitdir/gitweb.
129 cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
132 options = YAML::load_file(ARGV[0])
133 options[:StartCallback] = proc do
134 File.open(options[:PidFile],"w") do |f|
138 options[:ServerType] = WEBrick::Daemon
139 server = WEBrick::HTTPServer.new(options)
140 ['INT', 'TERM'].each do |signal|
141 trap(signal) {server.shutdown}
145 # generate a shell script to invoke the above ruby script,
146 # which assumes _ruby_ is in the user's $PATH. that's _one_
147 # portable way to run ruby, which could be installed anywhere,
149 cat >"$fqgitdir/gitweb/$httpd" <<EOF
151 exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
153 chmod +x
"$fqgitdir/gitweb/$httpd"
157 :DocumentRoot: "$fqgitdir/gitweb"
158 :DirectoryIndex: ["gitweb.cgi"]
159 :PidFile: "$fqgitdir/pid"
161 test "$local" = true
&& echo ':BindAddress: "127.0.0.1"' >> "$conf"
166 server.document-root = "$fqgitdir/gitweb"
168 server.modules = ( "mod_cgi" )
169 server.indexfiles = ( "gitweb.cgi" )
170 server.pid-file = "$fqgitdir/pid"
171 cgi.assign = ( ".cgi" => "" )
172 mimetype.assign = ( ".css" => "text/css" )
174 test x
"$local" = xtrue
&& echo 'server.bind = "127.0.0.1"' >> "$conf"
178 test -z "$module_path" && module_path
=/usr
/lib
/apache
2/modules
179 mkdir
-p "$GIT_DIR/gitweb/logs"
181 test x
"$local" = xtrue
&& bind='127.0.0.1:'
182 echo 'text/css css' > $fqgitdir/mime.types
184 ServerName "git-instaweb"
185 ServerRoot "$fqgitdir/gitweb"
186 DocumentRoot "$fqgitdir/gitweb"
187 PidFile "$fqgitdir/pid"
191 for mod
in mime dir
; do
192 if test -e $module_path/mod_
${mod}.so
; then
193 echo "LoadModule ${mod}_module " \
194 "$module_path/mod_${mod}.so" >> "$conf"
198 TypesConfig $fqgitdir/mime.types
199 DirectoryIndex gitweb.cgi
202 # check to see if Dennis Stosberg's mod_perl compatibility patch
203 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
204 if test -f "$module_path/mod_perl.so" && grep '^our $gitbin' \
205 "$GIT_DIR/gitweb/gitweb.cgi" >/dev
/null
207 # favor mod_perl if available
209 LoadModule perl_module $module_path/mod_perl.so
211 PerlPassEnv GIT_EXEC_DIR
212 <Location /gitweb.cgi>
213 SetHandler perl-script
214 PerlResponseHandler ModPerl::Registry
215 PerlOptions +ParseHeaders
221 list_mods
=`echo "$httpd" | sed "s/-f$/-l/"`
222 $list_mods |
grep 'mod_cgi\.c' >/dev
/null
2>&1 || \
223 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
225 AddHandler cgi-script .cgi
226 <Location /gitweb.cgi>
234 s#^\(my\|our\) $projectroot =.*#\1 $projectroot = "'$
(dirname "$fqgitdir")'";#
235 s#\(my\|our\) $gitbin =.*#\1 $gitbin = "'$GIT_EXEC_PATH'";#
236 s#\(my\|our\) $projects_list =.*#\1 $projects_list = $projectroot;#
237 s#\(my\|our\) $git_temp =.*#\1 $git_temp = "'$fqgitdir/gitweb
/tmp
'";#'
240 cat > "$1.tmp" <<\EOFGITWEB
243 sed "$script" "$1.tmp" > "$1"
249 cat > "$1" <<\EOFGITWEB
254 gitweb_cgi
"$GIT_DIR/gitweb/gitweb.cgi"
255 gitweb_css
"$GIT_DIR/gitweb/gitweb.css"
268 echo "Unknown httpd specified: $httpd"
274 url
=http
://127.0.0.1:$port
275 "$browser" $url ||
echo $url