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)]'
13 fqgitdir
="$GIT_DIR" ;;
15 fqgitdir
="$PWD/$GIT_DIR" ;;
18 local="`git config --bool --get instaweb.local`"
19 httpd
="`git config --get instaweb.httpd`"
20 browser
="`git config --get instaweb.browser`"
21 port
=`git config --get instaweb.port`
22 module_path
="`git config --get instaweb.modulepath`"
24 conf
=$GIT_DIR/gitweb
/httpd.conf
28 # if installed, it doesn't need further configuration (module_path)
29 test -z "$httpd" && httpd
='lighttpd -f'
31 # probably the most popular browser among gitweb users
32 test -z "$browser" && browser
='firefox'
34 # any untaken local port will do...
35 test -z "$port" && port
=1234
38 httpd_only
="`echo $httpd | cut -f1 -d' '`"
39 if test "`expr index $httpd_only /`" -eq '1' || \
40 which $httpd_only >/dev
/null
42 $httpd $fqgitdir/gitweb
/httpd.conf
44 # many httpds are installed in /usr/sbin or /usr/local/sbin
45 # these days and those are not in most users $PATHs
46 for i
in /usr
/local
/sbin
/usr
/sbin
48 if test -x "$i/$httpd_only"
50 # don't quote $httpd, there can be
51 # arguments to it (-f)
52 $i/$httpd "$fqgitdir/gitweb/httpd.conf"
56 echo "$httpd_only not found. Install $httpd_only or use" \
57 "--httpd to specify another http daemon."
61 echo "Could not execute http daemon $httpd."
67 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
70 while case "$#" in 0) break ;; esac
92 httpd
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
100 -b|
--browser|
--browser=*)
103 browser
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
114 port
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
122 -m|
--module-path=*|
--module-path)
125 module_path
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
140 mkdir
-p "$GIT_DIR/gitweb/tmp"
141 GIT_EXEC_PATH
="`git --exec-path`"
143 export GIT_EXEC_PATH GIT_DIR
148 server.document-root = "$fqgitdir/gitweb"
150 server.modules = ( "mod_cgi" )
151 server.indexfiles = ( "gitweb.cgi" )
152 server.pid-file = "$fqgitdir/pid"
153 cgi.assign = ( ".cgi" => "" )
154 mimetype.assign = ( ".css" => "text/css" )
156 test "$local" = true
&& echo 'server.bind = "127.0.0.1"' >> "$conf"
160 test -z "$module_path" && module_path
=/usr
/lib
/apache
2/modules
161 mkdir
-p "$GIT_DIR/gitweb/logs"
163 test "$local" = true
&& bind='127.0.0.1:'
164 echo 'text/css css' > $fqgitdir/mime.types
166 ServerName "git-instaweb"
167 ServerRoot "$fqgitdir/gitweb"
168 DocumentRoot "$fqgitdir/gitweb"
169 PidFile "$fqgitdir/pid"
173 for mod
in mime dir
; do
174 if test -e $module_path/mod_
${mod}.so
; then
175 echo "LoadModule ${mod}_module " \
176 "$module_path/mod_${mod}.so" >> "$conf"
180 TypesConfig $fqgitdir/mime.types
181 DirectoryIndex gitweb.cgi
184 # check to see if Dennis Stosberg's mod_perl compatibility patch
185 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
186 if test -f "$module_path/mod_perl.so" && grep '^our $gitbin' \
187 "$GIT_DIR/gitweb/gitweb.cgi" >/dev
/null
189 # favor mod_perl if available
191 LoadModule perl_module $module_path/mod_perl.so
193 PerlPassEnv GIT_EXEC_DIR
194 <Location /gitweb.cgi>
195 SetHandler perl-script
196 PerlResponseHandler ModPerl::Registry
197 PerlOptions +ParseHeaders
203 list_mods
=`echo "$httpd" | sed "s/-f$/-l/"`
204 $list_mods |
grep 'mod_cgi\.c' >/dev
/null
2>&1 || \
205 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
207 AddHandler cgi-script .cgi
208 <Location /gitweb.cgi>
216 s#^\(my\|our\) $projectroot =.*#\1 $projectroot = "'`dirname $fqgitdir`'";#
217 s#\(my\|our\) $gitbin =.*#\1 $gitbin = "'$GIT_EXEC_PATH'";#
218 s#\(my\|our\) $projects_list =.*#\1 $projects_list = $projectroot;#
219 s#\(my\|our\) $git_temp =.*#\1 $git_temp = "'$fqgitdir/gitweb
/tmp
'";#'
222 cat > "$1.tmp" <<\EOFGITWEB
225 sed "$script" "$1.tmp" > "$1"
231 cat > "$1" <<\EOFGITWEB
236 gitweb_cgi
$GIT_DIR/gitweb
/gitweb.cgi
237 gitweb_css
$GIT_DIR/gitweb
/gitweb.css
247 echo "Unknown httpd specified: $httpd"
253 test -z "$browser" && browser
=echo
254 url
=http
://127.0.0.1:$port
255 $browser $url ||
echo $url