3 # Copyright (c) 2006 Eric Wong
9 git-instaweb [options] (--start | --stop | --restart)
11 l,local only bind on 127.0.0.1
12 p,port= the port to bind to
13 d,httpd= the command to launch
14 b,browser= the browser to launch
15 m,module-path= the module path (only needed for apache2)
17 stop stop the web server
18 start start the web server
19 restart restart the web server
25 local="`git config --bool --get instaweb.local`"
26 httpd
="`git config --get instaweb.httpd`"
27 browser
="`git config --get instaweb.browser`"
28 test -z "$browser" && browser
="`git config --get web.browser`"
29 port
=`git config --get instaweb.port`
30 module_path
="`git config --get instaweb.modulepath`"
32 conf
="$GIT_DIR/gitweb/httpd.conf"
36 # if installed, it doesn't need further configuration (module_path)
37 test -z "$httpd" && httpd
='lighttpd -f'
39 # probably the most popular browser among gitweb users
40 test -z "$browser" && browser
='firefox'
42 # any untaken local port will do...
43 test -z "$port" && port
=1234
46 httpd_only
="`echo $httpd | cut -f1 -d' '`"
47 if case "$httpd_only" in /*) : ;; *) which $httpd_only >/dev
/null
;; esac
49 $httpd "$fqgitdir/gitweb/httpd.conf"
51 # many httpds are installed in /usr/sbin or /usr/local/sbin
52 # these days and those are not in most users $PATHs
53 # in addition, we may have generated a server script
54 # in $fqgitdir/gitweb.
55 for i
in /usr
/local
/sbin
/usr
/sbin
"$fqgitdir/gitweb"
57 if test -x "$i/$httpd_only"
59 # don't quote $httpd, there can be
60 # arguments to it (-f)
61 $i/$httpd "$fqgitdir/gitweb/httpd.conf"
65 echo "$httpd_only not found. Install $httpd_only or use" \
66 "--httpd to specify another http daemon."
70 echo "Could not execute http daemon $httpd."
76 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
123 mkdir
-p "$GIT_DIR/gitweb/tmp"
124 GIT_EXEC_PATH
="`git --exec-path`"
126 export GIT_EXEC_PATH GIT_DIR
130 # generate a standalone server script in $fqgitdir/gitweb.
131 cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF
134 options = YAML::load_file(ARGV[0])
135 options[:StartCallback] = proc do
136 File.open(options[:PidFile],"w") do |f|
140 options[:ServerType] = WEBrick::Daemon
141 server = WEBrick::HTTPServer.new(options)
142 ['INT', 'TERM'].each do |signal|
143 trap(signal) {server.shutdown}
147 # generate a shell script to invoke the above ruby script,
148 # which assumes _ruby_ is in the user's $PATH. that's _one_
149 # portable way to run ruby, which could be installed anywhere,
151 cat >"$fqgitdir/gitweb/$httpd" <<EOF
153 exec ruby "$fqgitdir/gitweb/$httpd.rb" \$*
155 chmod +x
"$fqgitdir/gitweb/$httpd"
159 :DocumentRoot: "$fqgitdir/gitweb"
160 :DirectoryIndex: ["gitweb.cgi"]
161 :PidFile: "$fqgitdir/pid"
163 test "$local" = true
&& echo ':BindAddress: "127.0.0.1"' >> "$conf"
168 server.document-root = "$fqgitdir/gitweb"
170 server.modules = ( "mod_cgi" )
171 server.indexfiles = ( "gitweb.cgi" )
172 server.pid-file = "$fqgitdir/pid"
173 cgi.assign = ( ".cgi" => "" )
174 mimetype.assign = ( ".css" => "text/css" )
176 test x
"$local" = xtrue
&& echo 'server.bind = "127.0.0.1"' >> "$conf"
180 test -z "$module_path" && module_path
=/usr
/lib
/apache
2/modules
181 mkdir
-p "$GIT_DIR/gitweb/logs"
183 test x
"$local" = xtrue
&& bind='127.0.0.1:'
184 echo 'text/css css' > $fqgitdir/mime.types
186 ServerName "git-instaweb"
187 ServerRoot "$fqgitdir/gitweb"
188 DocumentRoot "$fqgitdir/gitweb"
189 PidFile "$fqgitdir/pid"
193 for mod
in mime dir
; do
194 if test -e $module_path/mod_
${mod}.so
; then
195 echo "LoadModule ${mod}_module " \
196 "$module_path/mod_${mod}.so" >> "$conf"
200 TypesConfig $fqgitdir/mime.types
201 DirectoryIndex gitweb.cgi
204 # check to see if Dennis Stosberg's mod_perl compatibility patch
205 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
206 if test -f "$module_path/mod_perl.so" && grep '^our $gitbin' \
207 "$GIT_DIR/gitweb/gitweb.cgi" >/dev
/null
209 # favor mod_perl if available
211 LoadModule perl_module $module_path/mod_perl.so
213 PerlPassEnv GIT_EXEC_DIR
214 <Location /gitweb.cgi>
215 SetHandler perl-script
216 PerlResponseHandler ModPerl::Registry
217 PerlOptions +ParseHeaders
223 list_mods
=`echo "$httpd" | sed "s/-f$/-l/"`
224 $list_mods |
grep 'mod_cgi\.c' >/dev
/null
2>&1 || \
225 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
227 AddHandler cgi-script .cgi
228 <Location /gitweb.cgi>
236 s#^(my|our) \$projectroot =.*#$1 \$projectroot = "'$
(dirname "$fqgitdir")'";#;
237 s#(my|our) \$gitbin =.*#$1 \$gitbin = "'$GIT_EXEC_PATH'";#;
238 s#(my|our) \$projects_list =.*#$1 \$projects_list = \$projectroot;#;
239 s#(my|our) \$git_temp =.*#$1 \$git_temp = "'$fqgitdir/gitweb
/tmp
'";#;'
242 cat > "$1.tmp" <<\EOFGITWEB
245 # Use the configured full path to perl to match the generated
246 # scripts' 'hashpling' line
247 "$PERL" -p -e "$script" "$1.tmp" > "$1"
253 cat > "$1" <<\EOFGITWEB
258 gitweb_cgi
"$GIT_DIR/gitweb/gitweb.cgi"
259 gitweb_css
"$GIT_DIR/gitweb/gitweb.css"
272 echo "Unknown httpd specified: $httpd"
277 init_browser_path
() {
278 browser_path
="`git config browser.$1.path`"
279 test -z "$browser_path" && browser_path
="$1"
283 url
=http
://127.0.0.1:$port
284 test -n "$browser" && {
285 init_browser_path
"$browser"