stop t1400 hiding errors in tests
[git/git.git] / git-instaweb.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Eric Wong
4 #
5 USAGE='[--start] [--stop] [--restart]
6 [--local] [--httpd=<httpd>] [--port=<port>] [--browser=<browser>]
7 [--module-path=<path> (for Apache2 only)]'
8
9 . git-sh-setup
10
11 fqgitdir="$GIT_DIR"
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`"
17
18 conf=$GIT_DIR/gitweb/httpd.conf
19
20 # Defaults:
21
22 # if installed, it doesn't need further configuration (module_path)
23 test -z "$httpd" && httpd='lighttpd -f'
24
25 # probably the most popular browser among gitweb users
26 test -z "$browser" && browser='firefox'
27
28 # any untaken local port will do...
29 test -z "$port" && port=1234
30
31 start_httpd () {
32 httpd_only="`echo $httpd | cut -f1 -d' '`"
33 if case "$httpd_only" in /*) : ;; *) which $httpd_only >/dev/null;; esac
34 then
35 $httpd $fqgitdir/gitweb/httpd.conf
36 else
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
40 do
41 if test -x "$i/$httpd_only"
42 then
43 # don't quote $httpd, there can be
44 # arguments to it (-f)
45 $i/$httpd "$fqgitdir/gitweb/httpd.conf"
46 return
47 fi
48 done
49 echo "$httpd_only not found. Install $httpd_only or use" \
50 "--httpd to specify another http daemon."
51 exit 1
52 fi
53 if test $? != 0; then
54 echo "Could not execute http daemon $httpd."
55 exit 1
56 fi
57 }
58
59 stop_httpd () {
60 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
61 }
62
63 while test $# != 0
64 do
65 case "$1" in
66 --stop|stop)
67 stop_httpd
68 exit 0
69 ;;
70 --start|start)
71 start_httpd
72 exit 0
73 ;;
74 --restart|restart)
75 stop_httpd
76 start_httpd
77 exit 0
78 ;;
79 --local|-l)
80 local=true
81 ;;
82 -d|--httpd|--httpd=*)
83 case "$#,$1" in
84 *,*=*)
85 httpd=`expr "$1" : '-[^=]*=\(.*\)'` ;;
86 1,*)
87 usage ;;
88 *)
89 httpd="$2"
90 shift ;;
91 esac
92 ;;
93 -b|--browser|--browser=*)
94 case "$#,$1" in
95 *,*=*)
96 browser=`expr "$1" : '-[^=]*=\(.*\)'` ;;
97 1,*)
98 usage ;;
99 *)
100 browser="$2"
101 shift ;;
102 esac
103 ;;
104 -p|--port|--port=*)
105 case "$#,$1" in
106 *,*=*)
107 port=`expr "$1" : '-[^=]*=\(.*\)'` ;;
108 1,*)
109 usage ;;
110 *)
111 port="$2"
112 shift ;;
113 esac
114 ;;
115 -m|--module-path=*|--module-path)
116 case "$#,$1" in
117 *,*=*)
118 module_path=`expr "$1" : '-[^=]*=\(.*\)'` ;;
119 1,*)
120 usage ;;
121 *)
122 module_path="$2"
123 shift ;;
124 esac
125 ;;
126 *)
127 usage
128 ;;
129 esac
130 shift
131 done
132
133 mkdir -p "$GIT_DIR/gitweb/tmp"
134 GIT_EXEC_PATH="`git --exec-path`"
135 GIT_DIR="$fqgitdir"
136 export GIT_EXEC_PATH GIT_DIR
137
138
139 lighttpd_conf () {
140 cat > "$conf" <<EOF
141 server.document-root = "$fqgitdir/gitweb"
142 server.port = $port
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" )
148 EOF
149 test "$local" = true && echo 'server.bind = "127.0.0.1"' >> "$conf"
150 }
151
152 apache2_conf () {
153 test -z "$module_path" && module_path=/usr/lib/apache2/modules
154 mkdir -p "$GIT_DIR/gitweb/logs"
155 bind=
156 test "$local" = true && bind='127.0.0.1:'
157 echo 'text/css css' > $fqgitdir/mime.types
158 cat > "$conf" <<EOF
159 ServerName "git-instaweb"
160 ServerRoot "$fqgitdir/gitweb"
161 DocumentRoot "$fqgitdir/gitweb"
162 PidFile "$fqgitdir/pid"
163 Listen $bind$port
164 EOF
165
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"
170 fi
171 done
172 cat >> "$conf" <<EOF
173 TypesConfig $fqgitdir/mime.types
174 DirectoryIndex gitweb.cgi
175 EOF
176
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
181 then
182 # favor mod_perl if available
183 cat >> "$conf" <<EOF
184 LoadModule perl_module $module_path/mod_perl.so
185 PerlPassEnv GIT_DIR
186 PerlPassEnv GIT_EXEC_DIR
187 <Location /gitweb.cgi>
188 SetHandler perl-script
189 PerlResponseHandler ModPerl::Registry
190 PerlOptions +ParseHeaders
191 Options +ExecCGI
192 </Location>
193 EOF
194 else
195 # plain-old CGI
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"
199 cat >> "$conf" <<EOF
200 AddHandler cgi-script .cgi
201 <Location /gitweb.cgi>
202 Options +ExecCGI
203 </Location>
204 EOF
205 fi
206 }
207
208 script='
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'";#'
213
214 gitweb_cgi () {
215 cat > "$1.tmp" <<\EOFGITWEB
216 @@GITWEB_CGI@@
217 EOFGITWEB
218 sed "$script" "$1.tmp" > "$1"
219 chmod +x "$1"
220 rm -f "$1.tmp"
221 }
222
223 gitweb_css () {
224 cat > "$1" <<\EOFGITWEB
225 @@GITWEB_CSS@@
226 EOFGITWEB
227 }
228
229 gitweb_cgi $GIT_DIR/gitweb/gitweb.cgi
230 gitweb_css $GIT_DIR/gitweb/gitweb.css
231
232 case "$httpd" in
233 *lighttpd*)
234 lighttpd_conf
235 ;;
236 *apache2*)
237 apache2_conf
238 ;;
239 *)
240 echo "Unknown httpd specified: $httpd"
241 exit 1
242 ;;
243 esac
244
245 start_httpd
246 test -z "$browser" && browser=echo
247 url=http://127.0.0.1:$port
248 $browser $url || echo $url