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 case "$httpd_only" in /*) : ;; *) which $httpd_only >/dev
/null
;; esac
35 $httpd $fqgitdir/gitweb
/httpd.conf
37 # many httpds are installed in /usr/sbin or /usr/local/sbin
38 # these days and those are not in most users $PATHs
39 for i
in /usr
/local
/sbin
/usr
/sbin
41 if test -x "$i/$httpd_only"
43 # don't quote $httpd, there can be
44 # arguments to it (-f)
45 $i/$httpd "$fqgitdir/gitweb/httpd.conf"
49 echo "$httpd_only not found. Install $httpd_only or use" \
50 "--httpd to specify another http daemon."
54 echo "Could not execute http daemon $httpd."
60 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
85 httpd
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
93 -b|
--browser|
--browser=*)
96 browser
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
107 port
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
115 -m|
--module-path=*|
--module-path)
118 module_path
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
133 mkdir
-p "$GIT_DIR/gitweb/tmp"
134 GIT_EXEC_PATH
="`git --exec-path`"
136 export GIT_EXEC_PATH GIT_DIR
141 server.document-root = "$fqgitdir/gitweb"
143 server.modules = ( "mod_cgi" )
144 server.indexfiles = ( "gitweb.cgi" )
145 server.pid-file = "$fqgitdir/pid"
146 cgi.assign = ( ".cgi" => "" )
147 mimetype.assign = ( ".css" => "text/css" )
149 test "$local" = true
&& echo 'server.bind = "127.0.0.1"' >> "$conf"
153 test -z "$module_path" && module_path
=/usr
/lib
/apache
2/modules
154 mkdir
-p "$GIT_DIR/gitweb/logs"
156 test "$local" = true
&& bind='127.0.0.1:'
157 echo 'text/css css' > $fqgitdir/mime.types
159 ServerName "git-instaweb"
160 ServerRoot "$fqgitdir/gitweb"
161 DocumentRoot "$fqgitdir/gitweb"
162 PidFile "$fqgitdir/pid"
166 for mod
in mime dir
; do
167 if test -e $module_path/mod_
${mod}.so
; then
168 echo "LoadModule ${mod}_module " \
169 "$module_path/mod_${mod}.so" >> "$conf"
173 TypesConfig $fqgitdir/mime.types
174 DirectoryIndex gitweb.cgi
177 # check to see if Dennis Stosberg's mod_perl compatibility patch
178 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
179 if test -f "$module_path/mod_perl.so" && grep '^our $gitbin' \
180 "$GIT_DIR/gitweb/gitweb.cgi" >/dev
/null
182 # favor mod_perl if available
184 LoadModule perl_module $module_path/mod_perl.so
186 PerlPassEnv GIT_EXEC_DIR
187 <Location /gitweb.cgi>
188 SetHandler perl-script
189 PerlResponseHandler ModPerl::Registry
190 PerlOptions +ParseHeaders
196 list_mods
=`echo "$httpd" | sed "s/-f$/-l/"`
197 $list_mods |
grep 'mod_cgi\.c' >/dev
/null
2>&1 || \
198 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
200 AddHandler cgi-script .cgi
201 <Location /gitweb.cgi>
209 s#^\(my\|our\) $projectroot =.*#\1 $projectroot = "'`dirname $fqgitdir`'";#
210 s#\(my\|our\) $gitbin =.*#\1 $gitbin = "'$GIT_EXEC_PATH'";#
211 s#\(my\|our\) $projects_list =.*#\1 $projects_list = $projectroot;#
212 s#\(my\|our\) $git_temp =.*#\1 $git_temp = "'$fqgitdir/gitweb
/tmp
'";#'
215 cat > "$1.tmp" <<\EOFGITWEB
218 sed "$script" "$1.tmp" > "$1"
224 cat > "$1" <<\EOFGITWEB
229 gitweb_cgi
$GIT_DIR/gitweb
/gitweb.cgi
230 gitweb_css
$GIT_DIR/gitweb
/gitweb.css
240 echo "Unknown httpd specified: $httpd"
246 test -z "$browser" && browser
=echo
247 url
=http
://127.0.0.1:$port
248 $browser $url ||
echo $url