3 # Copyright (c) 2006 Eric Wong
5 USAGE
='[--start] [--stop] [--restart]
6 [--local] [--httpd=<httpd>] [--port=<port>] [--browser=<browser>]
7 [--module-path=<path> (for Apache2 only)]'
12 local="`git config --bool --get instaweb.local`"
13 httpd
="`git config --get instaweb.httpd`"
14 browser
="`git config --get instaweb.browser`"
15 port
=`git config --get instaweb.port`
16 module_path
="`git config --get instaweb.modulepath`"
18 conf
=$GIT_DIR/gitweb
/httpd.conf
22 # if installed, it doesn't need further configuration (module_path)
23 test -z "$httpd" && httpd
='lighttpd -f'
25 # probably the most popular browser among gitweb users
26 test -z "$browser" && browser
='firefox'
28 # any untaken local port will do...
29 test -z "$port" && port
=1234
32 httpd_only
="`echo $httpd | cut -f1 -d' '`"
33 if test "`expr index $httpd_only /`" -eq '1' || \
34 which $httpd_only >/dev
/null
36 $httpd $fqgitdir/gitweb
/httpd.conf
38 # many httpds are installed in /usr/sbin or /usr/local/sbin
39 # these days and those are not in most users $PATHs
40 # in addition, we may have generated a server script
41 # in $fqgitdir/gitweb.
42 for i
in /usr
/local
/sbin
/usr
/sbin
"$fqgitdir/gitweb"
44 if test -x "$i/$httpd_only"
46 # don't quote $httpd, there can be
47 # arguments to it (-f)
48 $i/$httpd "$fqgitdir/gitweb/httpd.conf"
52 echo "$httpd_only not found. Install $httpd_only or use" \
53 "--httpd to specify another http daemon."
57 echo "Could not execute http daemon $httpd."
63 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
88 httpd
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
96 -b|
--browser|
--browser=*)
99 browser
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
110 port
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
118 -m|
--module-path=*|
--module-path)
121 module_path
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
136 mkdir
-p "$GIT_DIR/gitweb/tmp"
137 GIT_EXEC_PATH
="`git --exec-path`"
139 export GIT_EXEC_PATH GIT_DIR
143 # generate a standalone server script in $fqgitdir/gitweb.
144 cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
147 options = YAML::load_file(ARGV[0])
148 options[:StartCallback] = proc do
149 File.open(options[:PidFile],"w") do |f|
153 options[:ServerType] = WEBrick::Daemon
154 server = WEBrick::HTTPServer.new(options)
155 ['INT', 'TERM'].each do |signal|
156 trap(signal) {server.shutdown}
160 # generate a shell script to invoke the above ruby script,
161 # which assumes _ruby_ is in the user's $PATH. that's _one_
162 # portable way to run ruby, which could be installed anywhere,
164 cat >"$fqgitdir/gitweb/$httpd" <<EOF
166 exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
168 chmod +x
"$fqgitdir/gitweb/$httpd"
172 :DocumentRoot: "$fqgitdir/gitweb"
173 :DirectoryIndex: ["gitweb.cgi"]
174 :PidFile: "$fqgitdir/pid"
176 test "$local" = true
&& echo ':BindAddress: "127.0.0.1"' >> "$conf"
181 server.document-root = "$fqgitdir/gitweb"
183 server.modules = ( "mod_cgi" )
184 server.indexfiles = ( "gitweb.cgi" )
185 server.pid-file = "$fqgitdir/pid"
186 cgi.assign = ( ".cgi" => "" )
187 mimetype.assign = ( ".css" => "text/css" )
189 test "$local" = true
&& echo 'server.bind = "127.0.0.1"' >> "$conf"
193 test -z "$module_path" && module_path
=/usr
/lib
/apache
2/modules
194 mkdir
-p "$GIT_DIR/gitweb/logs"
196 test "$local" = true
&& bind='127.0.0.1:'
197 echo 'text/css css' > $fqgitdir/mime.types
199 ServerName "git-instaweb"
200 ServerRoot "$fqgitdir/gitweb"
201 DocumentRoot "$fqgitdir/gitweb"
202 PidFile "$fqgitdir/pid"
206 for mod
in mime dir
; do
207 if test -e $module_path/mod_
${mod}.so
; then
208 echo "LoadModule ${mod}_module " \
209 "$module_path/mod_${mod}.so" >> "$conf"
213 TypesConfig $fqgitdir/mime.types
214 DirectoryIndex gitweb.cgi
217 # check to see if Dennis Stosberg's mod_perl compatibility patch
218 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
219 if test -f "$module_path/mod_perl.so" && grep '^our $gitbin' \
220 "$GIT_DIR/gitweb/gitweb.cgi" >/dev
/null
222 # favor mod_perl if available
224 LoadModule perl_module $module_path/mod_perl.so
226 PerlPassEnv GIT_EXEC_DIR
227 <Location /gitweb.cgi>
228 SetHandler perl-script
229 PerlResponseHandler ModPerl::Registry
230 PerlOptions +ParseHeaders
236 list_mods
=`echo "$httpd" | sed "s/-f$/-l/"`
237 $list_mods |
grep 'mod_cgi\.c' >/dev
/null
2>&1 || \
238 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
240 AddHandler cgi-script .cgi
241 <Location /gitweb.cgi>
249 s#^\(my\|our\) $projectroot =.*#\1 $projectroot = "'`dirname $fqgitdir`'";#
250 s#\(my\|our\) $gitbin =.*#\1 $gitbin = "'$GIT_EXEC_PATH'";#
251 s#\(my\|our\) $projects_list =.*#\1 $projects_list = $projectroot;#
252 s#\(my\|our\) $git_temp =.*#\1 $git_temp = "'$fqgitdir/gitweb
/tmp
'";#'
255 cat > "$1.tmp" <<\EOFGITWEB
258 sed "$script" "$1.tmp" > "$1"
264 cat > "$1" <<\EOFGITWEB
269 gitweb_cgi
$GIT_DIR/gitweb
/gitweb.cgi
270 gitweb_css
$GIT_DIR/gitweb
/gitweb.css
283 echo "Unknown httpd specified: $httpd"
289 test -z "$browser" && browser
=echo
290 url
=http
://127.0.0.1:$port
291 $browser $url ||
echo $url