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 test -z "$browser" && browser
="`git config --get web.browser`"
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 # probably the most popular browser among gitweb users
39 test -z "$browser" && browser
='firefox'
41 # any untaken local port will do...
42 test -z "$port" && port
=1234
45 httpd_only
="`echo $httpd | cut -f1 -d' '`"
46 if case "$httpd_only" in /*) : ;; *) which $httpd_only >/dev
/null
;; esac
48 $httpd "$fqgitdir/gitweb/httpd.conf"
50 # many httpds are installed in /usr/sbin or /usr/local/sbin
51 # these days and those are not in most users $PATHs
52 # in addition, we may have generated a server script
53 # in $fqgitdir/gitweb.
54 for i
in /usr
/local
/sbin
/usr
/sbin
"$fqgitdir/gitweb"
56 if test -x "$i/$httpd_only"
58 # don't quote $httpd, there can be
59 # arguments to it (-f)
60 $i/$httpd "$fqgitdir/gitweb/httpd.conf"
64 echo "$httpd_only not found. Install $httpd_only or use" \
65 "--httpd to specify another http daemon."
69 echo "Could not execute http daemon $httpd."
75 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
122 mkdir
-p "$GIT_DIR/gitweb/tmp"
123 GIT_EXEC_PATH
="`git --exec-path`"
125 export GIT_EXEC_PATH GIT_DIR
129 # generate a standalone server script in $fqgitdir/gitweb.
130 cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
133 options = YAML::load_file(ARGV[0])
134 options[:StartCallback] = proc do
135 File.open(options[:PidFile],"w") do |f|
139 options[:ServerType] = WEBrick::Daemon
140 server = WEBrick::HTTPServer.new(options)
141 ['INT', 'TERM'].each do |signal|
142 trap(signal) {server.shutdown}
146 # generate a shell script to invoke the above ruby script,
147 # which assumes _ruby_ is in the user's $PATH. that's _one_
148 # portable way to run ruby, which could be installed anywhere,
150 cat >"$fqgitdir/gitweb/$httpd" <<EOF
152 exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
154 chmod +x
"$fqgitdir/gitweb/$httpd"
158 :DocumentRoot: "$fqgitdir/gitweb"
159 :DirectoryIndex: ["gitweb.cgi"]
160 :PidFile: "$fqgitdir/pid"
162 test "$local" = true
&& echo ':BindAddress: "127.0.0.1"' >> "$conf"
167 server.document-root = "$fqgitdir/gitweb"
169 server.modules = ( "mod_cgi" )
170 server.indexfiles = ( "gitweb.cgi" )
171 server.pid-file = "$fqgitdir/pid"
172 cgi.assign = ( ".cgi" => "" )
173 mimetype.assign = ( ".css" => "text/css" )
175 test x
"$local" = xtrue
&& echo 'server.bind = "127.0.0.1"' >> "$conf"
179 test -z "$module_path" && module_path
=/usr
/lib
/apache
2/modules
180 mkdir
-p "$GIT_DIR/gitweb/logs"
182 test x
"$local" = xtrue
&& bind='127.0.0.1:'
183 echo 'text/css css' > $fqgitdir/mime.types
185 ServerName "git-instaweb"
186 ServerRoot "$fqgitdir/gitweb"
187 DocumentRoot "$fqgitdir/gitweb"
188 PidFile "$fqgitdir/pid"
192 for mod
in mime dir
; do
193 if test -e $module_path/mod_
${mod}.so
; then
194 echo "LoadModule ${mod}_module " \
195 "$module_path/mod_${mod}.so" >> "$conf"
199 TypesConfig $fqgitdir/mime.types
200 DirectoryIndex gitweb.cgi
203 # check to see if Dennis Stosberg's mod_perl compatibility patch
204 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
205 if test -f "$module_path/mod_perl.so" && grep '^our $gitbin' \
206 "$GIT_DIR/gitweb/gitweb.cgi" >/dev
/null
208 # favor mod_perl if available
210 LoadModule perl_module $module_path/mod_perl.so
212 PerlPassEnv GIT_EXEC_DIR
213 <Location /gitweb.cgi>
214 SetHandler perl-script
215 PerlResponseHandler ModPerl::Registry
216 PerlOptions +ParseHeaders
222 list_mods
=`echo "$httpd" | sed "s/-f$/-l/"`
223 $list_mods |
grep 'mod_cgi\.c' >/dev
/null
2>&1 || \
224 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
226 AddHandler cgi-script .cgi
227 <Location /gitweb.cgi>
235 s#^\(my\|our\) $projectroot =.*#\1 $projectroot = "'$
(dirname "$fqgitdir")'";#
236 s#\(my\|our\) $gitbin =.*#\1 $gitbin = "'$GIT_EXEC_PATH'";#
237 s#\(my\|our\) $projects_list =.*#\1 $projects_list = $projectroot;#
238 s#\(my\|our\) $git_temp =.*#\1 $git_temp = "'$fqgitdir/gitweb
/tmp
'";#'
241 cat > "$1.tmp" <<\EOFGITWEB
244 sed "$script" "$1.tmp" > "$1"
250 cat > "$1" <<\EOFGITWEB
255 gitweb_cgi
"$GIT_DIR/gitweb/gitweb.cgi"
256 gitweb_css
"$GIT_DIR/gitweb/gitweb.css"
269 echo "Unknown httpd specified: $httpd"
275 url
=http
://127.0.0.1:$port
276 "$browser" $url ||
echo $url