Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 238 lines (215 sloc) 4.878 kb
a51d37c Add git-instaweb, instantly browse the working repo with gitweb
Eric Wong authored
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
18 local="`git repo-config --bool --get instaweb.local`"
19 httpd="`git repo-config --get instaweb.httpd`"
20 browser="`git repo-config --get instaweb.browser`"
21 port=`git repo-config --get instaweb.port`
22 module_path="`git repo-config --get instaweb.modulepath`"
23
24 conf=$GIT_DIR/gitweb/httpd.conf
25
26 # Defaults:
27
82e5a82 Pavel Roskin Fix more typos, primarily in the code
proski authored
28 # if installed, it doesn't need further configuration (module_path)
a51d37c Add git-instaweb, instantly browse the working repo with gitweb
Eric Wong authored
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
56 fi
57 }
58
59 stop_httpd () {
60 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
61 }
62
63 while case "$#" in 0) break ;; esac
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 ServerRoot "$fqgitdir/gitweb"
160 DocumentRoot "$fqgitdir/gitweb"
161 PidFile "$fqgitdir/pid"
162 Listen $bind$port
163 TypesConfig $fqgitdir/mime.types
164 DirectoryIndex gitweb.cgi
165 EOF
166
167 # check to see if Dennis Stosberg's mod_perl compatibility patch
168 # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied
169 if test -f "$module_path/mod_perl.so" && grep '^our $gitbin' \
170 "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null
171 then
172 # favor mod_perl if available
173 cat >> "$conf" <<EOF
174 LoadModule perl_module $module_path/mod_perl.so
175 PerlPassEnv GIT_DIR
176 PerlPassEnv GIT_EXEC_DIR
177 <Location /gitweb.cgi>
178 SetHandler perl-script
179 PerlResponseHandler ModPerl::Registry
180 PerlOptions +ParseHeaders
181 Options +ExecCGI
182 </Location>
183 EOF
184 else
185 # plain-old CGI
2b5d2d8 dscho git-instaweb: some Apache have mod_cgi builtin
dscho authored
186 list_mods=`echo "$httpd" | sed "s/-f$/-l/"`
187 $list_mods | grep 'mod_cgi\.c' >/dev/null || \
188 echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf"
a51d37c Add git-instaweb, instantly browse the working repo with gitweb
Eric Wong authored
189 cat >> "$conf" <<EOF
190 AddHandler cgi-script .cgi
191 <Location /gitweb.cgi>
192 Options +ExecCGI
193 </Location>
194 EOF
195 fi
196 }
197
198 script='
6ee030d instaweb: fix unportable ';' usage in sed
Eric Wong authored
199 s#^\(my\|our\) $projectroot =.*#\1 $projectroot = "'`dirname $fqgitdir`'";#
200 s#\(my\|our\) $gitbin =.*#\1 $gitbin = "'$GIT_EXEC_PATH'";#
201 s#\(my\|our\) $projects_list =.*#\1 $projects_list = $projectroot;#
a51d37c Add git-instaweb, instantly browse the working repo with gitweb
Eric Wong authored
202 s#\(my\|our\) $git_temp =.*#\1 $git_temp = "'$fqgitdir/gitweb/tmp'";#'
203
204 gitweb_cgi () {
205 cat > "$1.tmp" <<\EOFGITWEB
206 @@GITWEB_CGI@@
207 EOFGITWEB
208 sed "$script" "$1.tmp" > "$1"
209 chmod +x "$1"
210 rm -f "$1.tmp"
211 }
212
213 gitweb_css () {
214 cat > "$1" <<\EOFGITWEB
215 @@GITWEB_CSS@@
216 EOFGITWEB
217 }
218
219 gitweb_cgi $GIT_DIR/gitweb/gitweb.cgi
220 gitweb_css $GIT_DIR/gitweb/gitweb.css
221
222 case "$httpd" in
223 *lighttpd*)
224 lighttpd_conf
225 ;;
226 *apache2*)
227 apache2_conf
228 ;;
229 *)
230 echo "Unknown httpd specified: $httpd"
231 exit 1
232 ;;
233 esac
234
235 start_httpd
236 test -z "$browser" && browser=echo
237 $browser http://127.0.0.1:$port
Something went wrong with that request. Please try again.