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 # in addition, we may have generated a server script
40 # in $fqgitdir/gitweb.
41 for i
in /usr
/local
/sbin
/usr
/sbin
"$fqgitdir/gitweb"
43 if test -x "$i/$httpd_only"
45 # don't quote $httpd, there can be
46 # arguments to it (-f)
47 $i/$httpd "$fqgitdir/gitweb/httpd.conf"
51 echo "$httpd_only not found. Install $httpd_only or use" \
52 "--httpd to specify another http daemon."
56 echo "Could not execute http daemon $httpd."
62 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
87 httpd
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
95 -b|
--browser|
--browser=*)
98 browser
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
109 port
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
117 -m|
--module-path=*|
--module-path)
120 module_path
=`expr "$1" : '-[^=]*=\(.*\)'` ;;
135 mkdir
-p "$GIT_DIR/gitweb/tmp"
136 GIT_EXEC_PATH
="`git --exec-path`"
138 export GIT_EXEC_PATH GIT_DIR
142 # generate a standalone server script in $fqgitdir/gitweb.
143 cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
146 options = YAML::load_file(ARGV[0])
147 options[:StartCallback] = proc do
148 File.open(options[:PidFile],"w") do |f|
152 options[:ServerType] = WEBrick::Daemon
153 server = WEBrick::HTTPServer.new(options)
154 ['INT', 'TERM'].each do |signal|
155 trap(signal) {server.shutdown}
159 # generate a shell script to invoke the above ruby script,
160 # which assumes _ruby_ is in the user's $PATH. that's _one_
161 # portable way to run ruby, which could be installed anywhere,
163 cat >"$fqgitdir/gitweb/$httpd" <<EOF
165 exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
167 chmod +x
"$fqgitdir/gitweb/$httpd"
171 :DocumentRoot: "$fqgitdir/gitweb"
172 :DirectoryIndex: ["gitweb.cgi"]
173 :PidFile: "$fqgitdir/pid"
175 test "$local" = true
&& echo ':BindAddress: "127.0.0.1"' >> "$conf"
180 server.document-root = "$fqgitdir/gitweb"
182 server.modules = ( "mod_cgi" )
183 server.indexfiles = ( "gitweb.cgi" )
184 server.pid-file = "$fqgitdir/pid"
185 cgi.assign = ( ".cgi" => "" )
186 mimetype.assign = ( ".css" => "text/css" )
188 test x
"$local" = xtrue
&& echo 'server.bind = "127.0.0.1"' >> "$conf"
192 test -z "$module_path" && module_path
=/usr
/lib
/apache
2/modules
193 mkdir
-p "$GIT_DIR/gitweb/logs"
195 test x
"$local" = xtrue
&& bind='127.0.0.1:'
196 echo 'text/css css' > $fqgitdir/mime.types
198 ServerName "git-instaweb"
199 ServerRoot "$fqgitdir/gitweb"
200 DocumentRoot "$fqgitdir/gitweb"
201 PidFile "$fqgitdir/pid"
205 for mod
in mime dir
; do
206 if test -e $module_path/mod_
${mod}.so
; then
207 echo "LoadModule ${mod}_module " \
208 "$module_path/mod_${mod}.so" >> "$conf"
212 TypesConfig $fqgitdir/mime.types
213 DirectoryIndex gitweb.cgi
216 # check to see if Dennis Stosberg's mod_perl compatibility patch
217 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
218 if test -f "$module_path/mod_perl.so" && grep '^our $gitbin' \
219 "$GIT_DIR/gitweb/gitweb.cgi" >/dev
/null
221 # favor mod_perl if available
223 LoadModule perl_module $module_path/mod_perl.so
225 PerlPassEnv GIT_EXEC_DIR
226 <Location /gitweb.cgi>
227 SetHandler perl-script
228 PerlResponseHandler ModPerl::Registry
229 PerlOptions +ParseHeaders
235 list_mods
=`echo "$httpd" | sed "s/-f$/-l/"`
236 $list_mods |
grep 'mod_cgi\.c' >/dev
/null
2>&1 || \
237 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
239 AddHandler cgi-script .cgi
240 <Location /gitweb.cgi>
248 s#^\(my\|our\) $projectroot =.*#\1 $projectroot = "'$
(dirname "$fqgitdir")'";#
249 s#\(my\|our\) $gitbin =.*#\1 $gitbin = "'$GIT_EXEC_PATH'";#
250 s#\(my\|our\) $projects_list =.*#\1 $projects_list = $projectroot;#
251 s#\(my\|our\) $git_temp =.*#\1 $git_temp = "'$fqgitdir/gitweb
/tmp
'";#'
254 cat > "$1.tmp" <<\EOFGITWEB
257 sed "$script" "$1.tmp" > "$1"
263 cat > "$1" <<\EOFGITWEB
268 gitweb_cgi
"$GIT_DIR/gitweb/gitweb.cgi"
269 gitweb_css
"$GIT_DIR/gitweb/gitweb.css"
282 echo "Unknown httpd specified: $httpd"
288 url
=http
://127.0.0.1:$port
289 "$browser" $url ||
echo $url