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 for i in /usr/local/sbin /usr/sbin
42 if test -x "$i/$httpd_only"
44 # don't quote $httpd, there can be
45 # arguments to it (-f)
46 $i/$httpd "$fqgitdir/gitweb/httpd.conf"
50 echo "$httpd_only not found. Install $httpd_only or use" \
51 "--httpd to specify another http daemon."
55 echo "Could not execute http daemon $httpd."
61 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
64 while case "$#" in 0) break ;; esac
86 httpd=`expr "$1" : '-[^=]*=\(.*\)'` ;;
94 -b|--browser|--browser=*)
97 browser=`expr "$1" : '-[^=]*=\(.*\)'` ;;
108 port=`expr "$1" : '-[^=]*=\(.*\)'` ;;
116 -m|--module-path=*|--module-path)
119 module_path=`expr "$1" : '-[^=]*=\(.*\)'` ;;
134 mkdir -p "$GIT_DIR/gitweb/tmp"
135 GIT_EXEC_PATH="`git --exec-path`"
137 export GIT_EXEC_PATH GIT_DIR
142 server.document-root = "$fqgitdir/gitweb"
144 server.modules = ( "mod_cgi" )
145 server.indexfiles = ( "gitweb.cgi" )
146 server.pid-file = "$fqgitdir/pid"
147 cgi.assign = ( ".cgi" => "" )
148 mimetype.assign = ( ".css" => "text/css" )
150 test "$local" = true && echo 'server.bind = "127.0.0.1"' >> "$conf"
154 test -z "$module_path" && module_path=/usr/lib/apache2/modules
155 mkdir -p "$GIT_DIR/gitweb/logs"
157 test "$local" = true && bind='127.0.0.1:'
158 echo 'text/css css' > $fqgitdir/mime.types
160 ServerName "git-instaweb"
161 ServerRoot "$fqgitdir/gitweb"
162 DocumentRoot "$fqgitdir/gitweb"
163 PidFile "$fqgitdir/pid"
167 for mod in mime dir; do
168 if test -e $module_path/mod_${mod}.so; then
169 echo "LoadModule ${mod}_module " \
170 "$module_path/mod_${mod}.so" >> "$conf"
174 TypesConfig $fqgitdir/mime.types
175 DirectoryIndex gitweb.cgi
178 # check to see if Dennis Stosberg's mod_perl compatibility patch
179 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
180 if test -f "$module_path/mod_perl.so" && grep '^our $gitbin' \
181 "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null
183 # favor mod_perl if available
185 LoadModule perl_module $module_path/mod_perl.so
187 PerlPassEnv GIT_EXEC_DIR
188 <Location /gitweb.cgi>
189 SetHandler perl-script
190 PerlResponseHandler ModPerl::Registry
191 PerlOptions +ParseHeaders
197 list_mods=`echo "$httpd" | sed "s/-f$/-l/"`
198 $list_mods | grep 'mod_cgi\.c' >/dev/null 2>&1 || \
199 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
201 AddHandler cgi-script .cgi
202 <Location /gitweb.cgi>
210 s#^\(my\|our\) $projectroot =.*#\1 $projectroot = "'`dirname $fqgitdir`'";#
211 s#\(my\|our\) $gitbin =.*#\1 $gitbin = "'$GIT_EXEC_PATH'";#
212 s#\(my\|our\) $projects_list =.*#\1 $projects_list = $projectroot;#
213 s#\(my\|our\) $git_temp =.*#\1 $git_temp = "'$fqgitdir/gitweb/tmp'";#'
216 cat > "$1.tmp" <<\EOFGITWEB
219 sed "$script" "$1.tmp" > "$1"
225 cat > "$1" <<\EOFGITWEB
230 gitweb_cgi $GIT_DIR/gitweb/gitweb.cgi
231 gitweb_css $GIT_DIR/gitweb/gitweb.css
241 echo "Unknown httpd specified: $httpd"
247 test -z "$browser" && browser=echo
248 url=http://127.0.0.1:$port
249 $browser $url || echo $url