]>
Commit | Line | Data |
---|---|---|
a51d37c1 EW |
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 | case "$GIT_DIR" in | |
12 | /*) | |
13 | fqgitdir="$GIT_DIR" ;; | |
14 | *) | |
15 | fqgitdir="$PWD/$GIT_DIR" ;; | |
16 | esac | |
17 | ||
e0d10e1c TP |
18 | local="`git config --bool --get instaweb.local`" |
19 | httpd="`git config --get instaweb.httpd`" | |
20 | browser="`git config --get instaweb.browser`" | |
21 | port=`git config --get instaweb.port` | |
22 | module_path="`git config --get instaweb.modulepath`" | |
a51d37c1 EW |
23 | |
24 | conf=$GIT_DIR/gitweb/httpd.conf | |
25 | ||
26 | # Defaults: | |
27 | ||
82e5a82f | 28 | # if installed, it doesn't need further configuration (module_path) |
a51d37c1 EW |
29 | test -z "$httpd" && httpd='lighttpd -f' |
30 | ||
31 | # probably the most popular browser among gitweb users | |
32 | test -z "$browser" && browser='firefox' | |
33 | ||
34 | # any untaken local port will do... | |
35 | test -z "$port" && port=1234 | |
36 | ||
37 | start_httpd () { | |
38 | httpd_only="`echo $httpd | cut -f1 -d' '`" | |
39 | if test "`expr index $httpd_only /`" -eq '1' || \ | |
40 | which $httpd_only >/dev/null | |
41 | then | |
42 | $httpd $fqgitdir/gitweb/httpd.conf | |
43 | else | |
44 | # many httpds are installed in /usr/sbin or /usr/local/sbin | |
45 | # these days and those are not in most users $PATHs | |
46 | for i in /usr/local/sbin /usr/sbin | |
47 | do | |
48 | if test -x "$i/$httpd_only" | |
49 | then | |
50 | # don't quote $httpd, there can be | |
51 | # arguments to it (-f) | |
52 | $i/$httpd "$fqgitdir/gitweb/httpd.conf" | |
53 | return | |
54 | fi | |
55 | done | |
f281e3a1 FK |
56 | echo "$httpd_only not found. Install $httpd_only or use" \ |
57 | "--httpd to specify another http daemon." | |
58 | exit 1 | |
a51d37c1 | 59 | fi |
5209eda8 JS |
60 | if test $? != 0; then |
61 | echo "Could not execute http daemon $httpd." | |
62 | exit 1 | |
63 | fi | |
a51d37c1 EW |
64 | } |
65 | ||
66 | stop_httpd () { | |
67 | test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"` | |
68 | } | |
69 | ||
70 | while case "$#" in 0) break ;; esac | |
71 | do | |
72 | case "$1" in | |
73 | --stop|stop) | |
74 | stop_httpd | |
75 | exit 0 | |
76 | ;; | |
77 | --start|start) | |
78 | start_httpd | |
79 | exit 0 | |
80 | ;; | |
81 | --restart|restart) | |
82 | stop_httpd | |
83 | start_httpd | |
84 | exit 0 | |
85 | ;; | |
86 | --local|-l) | |
87 | local=true | |
88 | ;; | |
89 | -d|--httpd|--httpd=*) | |
90 | case "$#,$1" in | |
91 | *,*=*) | |
92 | httpd=`expr "$1" : '-[^=]*=\(.*\)'` ;; | |
93 | 1,*) | |
94 | usage ;; | |
95 | *) | |
96 | httpd="$2" | |
97 | shift ;; | |
98 | esac | |
99 | ;; | |
100 | -b|--browser|--browser=*) | |
101 | case "$#,$1" in | |
102 | *,*=*) | |
103 | browser=`expr "$1" : '-[^=]*=\(.*\)'` ;; | |
104 | 1,*) | |
105 | usage ;; | |
106 | *) | |
107 | browser="$2" | |
108 | shift ;; | |
109 | esac | |
110 | ;; | |
111 | -p|--port|--port=*) | |
112 | case "$#,$1" in | |
113 | *,*=*) | |
114 | port=`expr "$1" : '-[^=]*=\(.*\)'` ;; | |
115 | 1,*) | |
116 | usage ;; | |
117 | *) | |
118 | port="$2" | |
119 | shift ;; | |
120 | esac | |
121 | ;; | |
122 | -m|--module-path=*|--module-path) | |
123 | case "$#,$1" in | |
124 | *,*=*) | |
125 | module_path=`expr "$1" : '-[^=]*=\(.*\)'` ;; | |
126 | 1,*) | |
127 | usage ;; | |
128 | *) | |
129 | module_path="$2" | |
130 | shift ;; | |
131 | esac | |
132 | ;; | |
133 | *) | |
134 | usage | |
135 | ;; | |
136 | esac | |
137 | shift | |
138 | done | |
139 | ||
140 | mkdir -p "$GIT_DIR/gitweb/tmp" | |
141 | GIT_EXEC_PATH="`git --exec-path`" | |
142 | GIT_DIR="$fqgitdir" | |
143 | export GIT_EXEC_PATH GIT_DIR | |
144 | ||
145 | ||
146 | lighttpd_conf () { | |
147 | cat > "$conf" <<EOF | |
148 | server.document-root = "$fqgitdir/gitweb" | |
149 | server.port = $port | |
150 | server.modules = ( "mod_cgi" ) | |
151 | server.indexfiles = ( "gitweb.cgi" ) | |
152 | server.pid-file = "$fqgitdir/pid" | |
153 | cgi.assign = ( ".cgi" => "" ) | |
154 | mimetype.assign = ( ".css" => "text/css" ) | |
155 | EOF | |
156 | test "$local" = true && echo 'server.bind = "127.0.0.1"' >> "$conf" | |
157 | } | |
158 | ||
159 | apache2_conf () { | |
160 | test -z "$module_path" && module_path=/usr/lib/apache2/modules | |
161 | mkdir -p "$GIT_DIR/gitweb/logs" | |
162 | bind= | |
163 | test "$local" = true && bind='127.0.0.1:' | |
164 | echo 'text/css css' > $fqgitdir/mime.types | |
165 | cat > "$conf" <<EOF | |
44a167b0 | 166 | ServerName "git-instaweb" |
a51d37c1 EW |
167 | ServerRoot "$fqgitdir/gitweb" |
168 | DocumentRoot "$fqgitdir/gitweb" | |
169 | PidFile "$fqgitdir/pid" | |
170 | Listen $bind$port | |
44a167b0 EW |
171 | EOF |
172 | ||
173 | for mod in mime dir; do | |
174 | if test -e $module_path/mod_${mod}.so; then | |
175 | echo "LoadModule ${mod}_module " \ | |
176 | "$module_path/mod_${mod}.so" >> "$conf" | |
177 | fi | |
178 | done | |
179 | cat >> "$conf" <<EOF | |
a51d37c1 EW |
180 | TypesConfig $fqgitdir/mime.types |
181 | DirectoryIndex gitweb.cgi | |
182 | EOF | |
183 | ||
184 | # check to see if Dennis Stosberg's mod_perl compatibility patch | |
185 | # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied | |
186 | if test -f "$module_path/mod_perl.so" && grep '^our $gitbin' \ | |
187 | "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null | |
188 | then | |
189 | # favor mod_perl if available | |
190 | cat >> "$conf" <<EOF | |
191 | LoadModule perl_module $module_path/mod_perl.so | |
192 | PerlPassEnv GIT_DIR | |
193 | PerlPassEnv GIT_EXEC_DIR | |
194 | <Location /gitweb.cgi> | |
195 | SetHandler perl-script | |
196 | PerlResponseHandler ModPerl::Registry | |
197 | PerlOptions +ParseHeaders | |
198 | Options +ExecCGI | |
199 | </Location> | |
200 | EOF | |
201 | else | |
202 | # plain-old CGI | |
2b5d2d87 | 203 | list_mods=`echo "$httpd" | sed "s/-f$/-l/"` |
5209eda8 | 204 | $list_mods | grep 'mod_cgi\.c' >/dev/null 2>&1 || \ |
2b5d2d87 | 205 | echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf" |
a51d37c1 | 206 | cat >> "$conf" <<EOF |
a51d37c1 EW |
207 | AddHandler cgi-script .cgi |
208 | <Location /gitweb.cgi> | |
209 | Options +ExecCGI | |
210 | </Location> | |
211 | EOF | |
212 | fi | |
213 | } | |
214 | ||
215 | script=' | |
6ee030d6 EW |
216 | s#^\(my\|our\) $projectroot =.*#\1 $projectroot = "'`dirname $fqgitdir`'";# |
217 | s#\(my\|our\) $gitbin =.*#\1 $gitbin = "'$GIT_EXEC_PATH'";# | |
218 | s#\(my\|our\) $projects_list =.*#\1 $projects_list = $projectroot;# | |
a51d37c1 EW |
219 | s#\(my\|our\) $git_temp =.*#\1 $git_temp = "'$fqgitdir/gitweb/tmp'";#' |
220 | ||
221 | gitweb_cgi () { | |
222 | cat > "$1.tmp" <<\EOFGITWEB | |
223 | @@GITWEB_CGI@@ | |
224 | EOFGITWEB | |
225 | sed "$script" "$1.tmp" > "$1" | |
226 | chmod +x "$1" | |
227 | rm -f "$1.tmp" | |
228 | } | |
229 | ||
230 | gitweb_css () { | |
231 | cat > "$1" <<\EOFGITWEB | |
232 | @@GITWEB_CSS@@ | |
233 | EOFGITWEB | |
234 | } | |
235 | ||
236 | gitweb_cgi $GIT_DIR/gitweb/gitweb.cgi | |
237 | gitweb_css $GIT_DIR/gitweb/gitweb.css | |
238 | ||
239 | case "$httpd" in | |
240 | *lighttpd*) | |
241 | lighttpd_conf | |
242 | ;; | |
243 | *apache2*) | |
244 | apache2_conf | |
245 | ;; | |
246 | *) | |
247 | echo "Unknown httpd specified: $httpd" | |
248 | exit 1 | |
249 | ;; | |
250 | esac | |
251 | ||
252 | start_httpd | |
253 | test -z "$browser" && browser=echo | |
5209eda8 JS |
254 | url=http://127.0.0.1:$port |
255 | $browser $url || echo $url |