send-pack: respect '+' on wildcard refspecs
[git/dscho.git] / git-instaweb.sh
blob41ff08f8e44b12bddcea257bc66f0b577e342ddd
1 #!/bin/sh
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)]'
9 . git-sh-setup
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`"
18 conf=$GIT_DIR/gitweb/httpd.conf
20 # Defaults:
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
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
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
48 done
49 echo "$httpd_only not found. Install $httpd_only or use" \
50 "--httpd to specify another http daemon."
51 exit 1
53 if test $? != 0; then
54 echo "Could not execute http daemon $httpd."
55 exit 1
59 stop_httpd () {
60 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
63 while test $# != 0
65 case "$1" in
66 --stop|stop)
67 stop_httpd
68 exit 0
70 --start|start)
71 start_httpd
72 exit 0
74 --restart|restart)
75 stop_httpd
76 start_httpd
77 exit 0
79 --local|-l)
80 local=true
82 -d|--httpd|--httpd=*)
83 case "$#,$1" in
84 *,*=*)
85 httpd=`expr "$1" : '-[^=]*=\(.*\)'` ;;
86 1,*)
87 usage ;;
89 httpd="$2"
90 shift ;;
91 esac
93 -b|--browser|--browser=*)
94 case "$#,$1" in
95 *,*=*)
96 browser=`expr "$1" : '-[^=]*=\(.*\)'` ;;
97 1,*)
98 usage ;;
100 browser="$2"
101 shift ;;
102 esac
104 -p|--port|--port=*)
105 case "$#,$1" in
106 *,*=*)
107 port=`expr "$1" : '-[^=]*=\(.*\)'` ;;
108 1,*)
109 usage ;;
111 port="$2"
112 shift ;;
113 esac
115 -m|--module-path=*|--module-path)
116 case "$#,$1" in
117 *,*=*)
118 module_path=`expr "$1" : '-[^=]*=\(.*\)'` ;;
119 1,*)
120 usage ;;
122 module_path="$2"
123 shift ;;
124 esac
127 usage
129 esac
130 shift
131 done
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
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" )
149 test "$local" = true && echo 'server.bind = "127.0.0.1"' >> "$conf"
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
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"
171 done
172 cat >> "$conf" <<EOF
173 TypesConfig $fqgitdir/mime.types
174 DirectoryIndex gitweb.cgi
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>
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>
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'";#'
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"
223 gitweb_css () {
224 cat > "$1" <<\EOFGITWEB
225 @@GITWEB_CSS@@
226 EOFGITWEB
229 gitweb_cgi $GIT_DIR/gitweb/gitweb.cgi
230 gitweb_css $GIT_DIR/gitweb/gitweb.css
232 case "$httpd" in
233 *lighttpd*)
234 lighttpd_conf
236 *apache2*)
237 apache2_conf
240 echo "Unknown httpd specified: $httpd"
241 exit 1
243 esac
245 start_httpd
246 test -z "$browser" && browser=echo
247 url=http://127.0.0.1:$port
248 $browser $url || echo $url