Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2006 Eric Wong |
| 4 | # |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 5 | |
Charles Bailey | c569969 | 2007-12-19 12:25:27 +0000 | [diff] [blame] | 6 | PERL='@@PERL@@' |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 7 | OPTIONS_KEEPDASHDASH= |
| 8 | OPTIONS_SPEC="\ |
Stephan Beyer | 1b1dd23 | 2008-07-13 15:36:15 +0200 | [diff] [blame] | 9 | git instaweb [options] (--start | --stop | --restart) |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 10 | -- |
| 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) |
| 16 | Action |
| 17 | stop stop the web server |
| 18 | start start the web server |
| 19 | restart restart the web server |
| 20 | " |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 21 | |
| 22 | . git-sh-setup |
| 23 | |
David Kastrup | b2bc9a3 | 2007-08-11 15:36:28 +0200 | [diff] [blame] | 24 | fqgitdir="$GIT_DIR" |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 25 | local="$(git config --bool --get instaweb.local)" |
| 26 | httpd="$(git config --get instaweb.httpd)" |
| 27 | port=$(git config --get instaweb.port) |
| 28 | module_path="$(git config --get instaweb.modulepath)" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 29 | |
Jonas Fonseca | 9126425 | 2007-11-09 00:21:42 +0100 | [diff] [blame] | 30 | conf="$GIT_DIR/gitweb/httpd.conf" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 31 | |
| 32 | # Defaults: |
| 33 | |
Pavel Roskin | 82e5a82 | 2006-07-10 01:50:18 -0400 | [diff] [blame] | 34 | # if installed, it doesn't need further configuration (module_path) |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 35 | test -z "$httpd" && httpd='lighttpd -f' |
| 36 | |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 37 | # any untaken local port will do... |
| 38 | test -z "$port" && port=1234 |
| 39 | |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 40 | resolve_full_httpd () { |
| 41 | case "$httpd" in |
| 42 | *apache2*|*lighttpd*) |
| 43 | # ensure that the apache2/lighttpd command ends with "-f" |
Junio C Hamano | e1622bf | 2009-11-23 15:56:32 -0800 | [diff] [blame] | 44 | if ! echo "$httpd" | sane_grep -- '-f *$' >/dev/null 2>&1 |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 45 | then |
| 46 | httpd="$httpd -f" |
| 47 | fi |
| 48 | ;; |
| 49 | esac |
| 50 | |
| 51 | httpd_only="$(echo $httpd | cut -f1 -d' ')" |
Ramsay Jones | e47eec8 | 2009-03-09 18:31:55 +0000 | [diff] [blame] | 52 | if case "$httpd_only" in /*) : ;; *) which $httpd_only >/dev/null 2>&1;; esac |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 53 | then |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 54 | full_httpd=$httpd |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 55 | else |
| 56 | # many httpds are installed in /usr/sbin or /usr/local/sbin |
| 57 | # these days and those are not in most users $PATHs |
Mike Dalessio | 14b45b6 | 2007-10-06 13:29:48 -0400 | [diff] [blame] | 58 | # in addition, we may have generated a server script |
| 59 | # in $fqgitdir/gitweb. |
| 60 | for i in /usr/local/sbin /usr/sbin "$fqgitdir/gitweb" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 61 | do |
| 62 | if test -x "$i/$httpd_only" |
| 63 | then |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 64 | full_httpd=$i/$httpd |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 65 | return |
| 66 | fi |
| 67 | done |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 68 | |
| 69 | echo >&2 "$httpd_only not found. Install $httpd_only or use" \ |
| 70 | "--httpd to specify another httpd daemon." |
Fredrik Kuivinen | f281e3a | 2007-01-06 11:40:06 +0100 | [diff] [blame] | 71 | exit 1 |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 72 | fi |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | start_httpd () { |
Stephen Boyd | 0b624b4 | 2009-11-22 23:09:12 -0800 | [diff] [blame] | 76 | if test -f "$fqgitdir/pid"; then |
| 77 | say "Instance already running. Restarting..." |
| 78 | stop_httpd |
| 79 | fi |
| 80 | |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 81 | # here $httpd should have a meaningful value |
| 82 | resolve_full_httpd |
| 83 | |
| 84 | # don't quote $full_httpd, there can be arguments to it (-f) |
Wilhansen Li | 0ded475 | 2009-08-21 22:24:48 +0800 | [diff] [blame] | 85 | case "$httpd" in |
| 86 | *mongoose*) |
| 87 | #The mongoose server doesn't have a daemon mode so we'll have to fork it |
| 88 | $full_httpd "$fqgitdir/gitweb/httpd.conf" & |
| 89 | #Save the pid before doing anything else (we'll print it later) |
| 90 | pid=$! |
| 91 | |
| 92 | if test $? != 0; then |
| 93 | echo "Could not execute http daemon $httpd." |
| 94 | exit 1 |
| 95 | fi |
| 96 | |
| 97 | cat > "$fqgitdir/pid" <<EOF |
| 98 | $pid |
| 99 | EOF |
| 100 | ;; |
| 101 | *) |
| 102 | $full_httpd "$fqgitdir/gitweb/httpd.conf" |
| 103 | if test $? != 0; then |
| 104 | echo "Could not execute http daemon $httpd." |
| 105 | exit 1 |
| 106 | fi |
| 107 | ;; |
| 108 | esac |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | stop_httpd () { |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 112 | test -f "$fqgitdir/pid" && kill $(cat "$fqgitdir/pid") |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 113 | } |
| 114 | |
David Kastrup | 822f7c7 | 2007-09-23 22:42:08 +0200 | [diff] [blame] | 115 | while test $# != 0 |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 116 | do |
| 117 | case "$1" in |
| 118 | --stop|stop) |
| 119 | stop_httpd |
| 120 | exit 0 |
| 121 | ;; |
| 122 | --start|start) |
| 123 | start_httpd |
| 124 | exit 0 |
| 125 | ;; |
| 126 | --restart|restart) |
| 127 | stop_httpd |
| 128 | start_httpd |
| 129 | exit 0 |
| 130 | ;; |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 131 | -l|--local) |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 132 | local=true |
| 133 | ;; |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 134 | -d|--httpd) |
| 135 | shift |
| 136 | httpd="$1" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 137 | ;; |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 138 | -b|--browser) |
| 139 | shift |
| 140 | browser="$1" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 141 | ;; |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 142 | -p|--port) |
| 143 | shift |
| 144 | port="$1" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 145 | ;; |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 146 | -m|--module-path) |
| 147 | shift |
| 148 | module_path="$1" |
| 149 | ;; |
| 150 | --) |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 151 | ;; |
| 152 | *) |
| 153 | usage |
| 154 | ;; |
| 155 | esac |
| 156 | shift |
| 157 | done |
| 158 | |
| 159 | mkdir -p "$GIT_DIR/gitweb/tmp" |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 160 | GIT_EXEC_PATH="$(git --exec-path)" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 161 | GIT_DIR="$fqgitdir" |
| 162 | export GIT_EXEC_PATH GIT_DIR |
| 163 | |
| 164 | |
Mike Dalessio | 425b78e | 2007-10-06 13:29:49 -0400 | [diff] [blame] | 165 | webrick_conf () { |
| 166 | # generate a standalone server script in $fqgitdir/gitweb. |
| 167 | cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF |
| 168 | require 'webrick' |
| 169 | require 'yaml' |
| 170 | options = YAML::load_file(ARGV[0]) |
| 171 | options[:StartCallback] = proc do |
| 172 | File.open(options[:PidFile],"w") do |f| |
| 173 | f.puts Process.pid |
| 174 | end |
| 175 | end |
| 176 | options[:ServerType] = WEBrick::Daemon |
| 177 | server = WEBrick::HTTPServer.new(options) |
| 178 | ['INT', 'TERM'].each do |signal| |
| 179 | trap(signal) {server.shutdown} |
| 180 | end |
| 181 | server.start |
| 182 | EOF |
| 183 | # generate a shell script to invoke the above ruby script, |
| 184 | # which assumes _ruby_ is in the user's $PATH. that's _one_ |
| 185 | # portable way to run ruby, which could be installed anywhere, |
| 186 | # really. |
| 187 | cat >"$fqgitdir/gitweb/$httpd" <<EOF |
| 188 | #!/bin/sh |
| 189 | exec ruby "$fqgitdir/gitweb/$httpd.rb" \$* |
| 190 | EOF |
| 191 | chmod +x "$fqgitdir/gitweb/$httpd" |
| 192 | |
| 193 | cat >"$conf" <<EOF |
| 194 | :Port: $port |
| 195 | :DocumentRoot: "$fqgitdir/gitweb" |
| 196 | :DirectoryIndex: ["gitweb.cgi"] |
| 197 | :PidFile: "$fqgitdir/pid" |
| 198 | EOF |
| 199 | test "$local" = true && echo ':BindAddress: "127.0.0.1"' >> "$conf" |
| 200 | } |
| 201 | |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 202 | lighttpd_conf () { |
| 203 | cat > "$conf" <<EOF |
| 204 | server.document-root = "$fqgitdir/gitweb" |
| 205 | server.port = $port |
Ramsay Jones | e47eec8 | 2009-03-09 18:31:55 +0000 | [diff] [blame] | 206 | server.modules = ( "mod_setenv", "mod_cgi" ) |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 207 | server.indexfiles = ( "gitweb.cgi" ) |
| 208 | server.pid-file = "$fqgitdir/pid" |
Ramsay Jones | e47eec8 | 2009-03-09 18:31:55 +0000 | [diff] [blame] | 209 | server.errorlog = "$fqgitdir/gitweb/error.log" |
| 210 | |
| 211 | # to enable, add "mod_access", "mod_accesslog" to server.modules |
| 212 | # variable above and uncomment this |
| 213 | #accesslog.filename = "$fqgitdir/gitweb/access.log" |
| 214 | |
| 215 | setenv.add-environment = ( "PATH" => "/usr/local/bin:/usr/bin:/bin" ) |
| 216 | |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 217 | cgi.assign = ( ".cgi" => "" ) |
Ramsay Jones | e47eec8 | 2009-03-09 18:31:55 +0000 | [diff] [blame] | 218 | |
| 219 | # mimetype mapping |
| 220 | mimetype.assign = ( |
| 221 | ".pdf" => "application/pdf", |
| 222 | ".sig" => "application/pgp-signature", |
| 223 | ".spl" => "application/futuresplash", |
| 224 | ".class" => "application/octet-stream", |
| 225 | ".ps" => "application/postscript", |
| 226 | ".torrent" => "application/x-bittorrent", |
| 227 | ".dvi" => "application/x-dvi", |
| 228 | ".gz" => "application/x-gzip", |
| 229 | ".pac" => "application/x-ns-proxy-autoconfig", |
| 230 | ".swf" => "application/x-shockwave-flash", |
| 231 | ".tar.gz" => "application/x-tgz", |
| 232 | ".tgz" => "application/x-tgz", |
| 233 | ".tar" => "application/x-tar", |
| 234 | ".zip" => "application/zip", |
| 235 | ".mp3" => "audio/mpeg", |
| 236 | ".m3u" => "audio/x-mpegurl", |
| 237 | ".wma" => "audio/x-ms-wma", |
| 238 | ".wax" => "audio/x-ms-wax", |
| 239 | ".ogg" => "application/ogg", |
| 240 | ".wav" => "audio/x-wav", |
| 241 | ".gif" => "image/gif", |
| 242 | ".jpg" => "image/jpeg", |
| 243 | ".jpeg" => "image/jpeg", |
| 244 | ".png" => "image/png", |
| 245 | ".xbm" => "image/x-xbitmap", |
| 246 | ".xpm" => "image/x-xpixmap", |
| 247 | ".xwd" => "image/x-xwindowdump", |
| 248 | ".css" => "text/css", |
| 249 | ".html" => "text/html", |
| 250 | ".htm" => "text/html", |
| 251 | ".js" => "text/javascript", |
| 252 | ".asc" => "text/plain", |
| 253 | ".c" => "text/plain", |
| 254 | ".cpp" => "text/plain", |
| 255 | ".log" => "text/plain", |
| 256 | ".conf" => "text/plain", |
| 257 | ".text" => "text/plain", |
| 258 | ".txt" => "text/plain", |
| 259 | ".dtd" => "text/xml", |
| 260 | ".xml" => "text/xml", |
| 261 | ".mpeg" => "video/mpeg", |
| 262 | ".mpg" => "video/mpeg", |
| 263 | ".mov" => "video/quicktime", |
| 264 | ".qt" => "video/quicktime", |
| 265 | ".avi" => "video/x-msvideo", |
| 266 | ".asf" => "video/x-ms-asf", |
| 267 | ".asx" => "video/x-ms-asf", |
| 268 | ".wmv" => "video/x-ms-wmv", |
| 269 | ".bz2" => "application/x-bzip", |
| 270 | ".tbz" => "application/x-bzip-compressed-tar", |
| 271 | ".tar.bz2" => "application/x-bzip-compressed-tar", |
| 272 | "" => "text/plain" |
| 273 | ) |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 274 | EOF |
Jonas Fonseca | 9126425 | 2007-11-09 00:21:42 +0100 | [diff] [blame] | 275 | test x"$local" = xtrue && echo 'server.bind = "127.0.0.1"' >> "$conf" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | apache2_conf () { |
| 279 | test -z "$module_path" && module_path=/usr/lib/apache2/modules |
| 280 | mkdir -p "$GIT_DIR/gitweb/logs" |
| 281 | bind= |
Jonas Fonseca | 9126425 | 2007-11-09 00:21:42 +0100 | [diff] [blame] | 282 | test x"$local" = xtrue && bind='127.0.0.1:' |
Sean Estabrooks | e24c76b | 2009-07-18 09:45:44 -0700 | [diff] [blame] | 283 | echo 'text/css css' > "$fqgitdir/mime.types" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 284 | cat > "$conf" <<EOF |
Eric Wong | 44a167b | 2007-01-02 00:57:11 -0800 | [diff] [blame] | 285 | ServerName "git-instaweb" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 286 | ServerRoot "$fqgitdir/gitweb" |
| 287 | DocumentRoot "$fqgitdir/gitweb" |
| 288 | PidFile "$fqgitdir/pid" |
| 289 | Listen $bind$port |
Eric Wong | 44a167b | 2007-01-02 00:57:11 -0800 | [diff] [blame] | 290 | EOF |
| 291 | |
| 292 | for mod in mime dir; do |
| 293 | if test -e $module_path/mod_${mod}.so; then |
| 294 | echo "LoadModule ${mod}_module " \ |
| 295 | "$module_path/mod_${mod}.so" >> "$conf" |
| 296 | fi |
| 297 | done |
| 298 | cat >> "$conf" <<EOF |
Sean Estabrooks | e24c76b | 2009-07-18 09:45:44 -0700 | [diff] [blame] | 299 | TypesConfig "$fqgitdir/mime.types" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 300 | DirectoryIndex gitweb.cgi |
| 301 | EOF |
| 302 | |
| 303 | # check to see if Dennis Stosberg's mod_perl compatibility patch |
| 304 | # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied |
Junio C Hamano | e1622bf | 2009-11-23 15:56:32 -0800 | [diff] [blame] | 305 | if test -f "$module_path/mod_perl.so" && |
| 306 | sane_grep 'MOD_PERL' "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 307 | then |
| 308 | # favor mod_perl if available |
| 309 | cat >> "$conf" <<EOF |
| 310 | LoadModule perl_module $module_path/mod_perl.so |
| 311 | PerlPassEnv GIT_DIR |
| 312 | PerlPassEnv GIT_EXEC_DIR |
| 313 | <Location /gitweb.cgi> |
| 314 | SetHandler perl-script |
| 315 | PerlResponseHandler ModPerl::Registry |
| 316 | PerlOptions +ParseHeaders |
| 317 | Options +ExecCGI |
| 318 | </Location> |
| 319 | EOF |
| 320 | else |
| 321 | # plain-old CGI |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 322 | resolve_full_httpd |
Stephen Boyd | 9524cf2 | 2010-01-26 15:08:31 -0800 | [diff] [blame] | 323 | list_mods=$(echo "$full_httpd" | sed 's/-f$/-l/') |
Junio C Hamano | e1622bf | 2009-11-23 15:56:32 -0800 | [diff] [blame] | 324 | $list_mods | sane_grep 'mod_cgi\.c' >/dev/null 2>&1 || \ |
Mark Rada | 10d1432 | 2009-09-26 14:12:32 -0400 | [diff] [blame] | 325 | if test -f "$module_path/mod_cgi.so" |
| 326 | then |
| 327 | echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf" |
| 328 | else |
| 329 | $list_mods | grep 'mod_cgid\.c' >/dev/null 2>&1 || \ |
| 330 | if test -f "$module_path/mod_cgid.so" |
| 331 | then |
| 332 | echo "LoadModule cgid_module $module_path/mod_cgid.so" \ |
| 333 | >> "$conf" |
| 334 | else |
| 335 | echo "You have no CGI support!" |
| 336 | exit 2 |
| 337 | fi |
| 338 | echo "ScriptSock logs/gitweb.sock" >> "$conf" |
| 339 | fi |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 340 | cat >> "$conf" <<EOF |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 341 | AddHandler cgi-script .cgi |
| 342 | <Location /gitweb.cgi> |
| 343 | Options +ExecCGI |
| 344 | </Location> |
| 345 | EOF |
| 346 | fi |
| 347 | } |
| 348 | |
Wilhansen Li | 0ded475 | 2009-08-21 22:24:48 +0800 | [diff] [blame] | 349 | mongoose_conf() { |
| 350 | cat > "$conf" <<EOF |
| 351 | # Mongoose web server configuration file. |
| 352 | # Lines starting with '#' and empty lines are ignored. |
| 353 | # For detailed description of every option, visit |
| 354 | # http://code.google.com/p/mongoose/wiki/MongooseManual |
| 355 | |
| 356 | root $fqgitdir/gitweb |
| 357 | ports $port |
| 358 | index_files gitweb.cgi |
| 359 | #ssl_cert $fqgitdir/gitweb/ssl_cert.pem |
| 360 | error_log $fqgitdir/gitweb/error.log |
| 361 | access_log $fqgitdir/gitweb/access.log |
| 362 | |
| 363 | #cgi setup |
| 364 | cgi_env PATH=/usr/local/bin:/usr/bin:/bin,GIT_DIR=$GIT_DIR,GIT_EXEC_PATH=$GIT_EXEC_PATH |
| 365 | cgi_interp $PERL |
| 366 | cgi_ext cgi,pl |
| 367 | |
| 368 | # mimetype mapping |
| 369 | mime_types .gz=application/x-gzip,.tar.gz=application/x-tgz,.tgz=application/x-tgz,.tar=application/x-tar,.zip=application/zip,.gif=image/gif,.jpg=image/jpeg,.jpeg=image/jpeg,.png=image/png,.css=text/css,.html=text/html,.htm=text/html,.js=text/javascript,.c=text/plain,.cpp=text/plain,.log=text/plain,.conf=text/plain,.text=text/plain,.txt=text/plain,.dtd=text/xml,.bz2=application/x-bzip,.tbz=application/x-bzip-compressed-tar,.tar.bz2=application/x-bzip-compressed-tar |
| 370 | EOF |
| 371 | } |
| 372 | |
| 373 | |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 374 | script=' |
Charles Bailey | c569969 | 2007-12-19 12:25:27 +0000 | [diff] [blame] | 375 | s#^(my|our) \$projectroot =.*#$1 \$projectroot = "'$(dirname "$fqgitdir")'";#; |
| 376 | s#(my|our) \$gitbin =.*#$1 \$gitbin = "'$GIT_EXEC_PATH'";#; |
| 377 | s#(my|our) \$projects_list =.*#$1 \$projects_list = \$projectroot;#; |
| 378 | s#(my|our) \$git_temp =.*#$1 \$git_temp = "'$fqgitdir/gitweb/tmp'";#;' |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 379 | |
| 380 | gitweb_cgi () { |
| 381 | cat > "$1.tmp" <<\EOFGITWEB |
| 382 | @@GITWEB_CGI@@ |
| 383 | EOFGITWEB |
Charles Bailey | c569969 | 2007-12-19 12:25:27 +0000 | [diff] [blame] | 384 | # Use the configured full path to perl to match the generated |
| 385 | # scripts' 'hashpling' line |
| 386 | "$PERL" -p -e "$script" "$1.tmp" > "$1" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 387 | chmod +x "$1" |
| 388 | rm -f "$1.tmp" |
| 389 | } |
| 390 | |
| 391 | gitweb_css () { |
| 392 | cat > "$1" <<\EOFGITWEB |
| 393 | @@GITWEB_CSS@@ |
| 394 | EOFGITWEB |
| 395 | } |
| 396 | |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 397 | gitweb_js () { |
| 398 | cat > "$1" <<\EOFGITWEB |
| 399 | @@GITWEB_JS@@ |
| 400 | EOFGITWEB |
| 401 | } |
| 402 | |
Jonas Fonseca | 9126425 | 2007-11-09 00:21:42 +0100 | [diff] [blame] | 403 | gitweb_cgi "$GIT_DIR/gitweb/gitweb.cgi" |
| 404 | gitweb_css "$GIT_DIR/gitweb/gitweb.css" |
Jakub Narebski | 4af819d | 2009-09-01 13:39:17 +0200 | [diff] [blame] | 405 | gitweb_js "$GIT_DIR/gitweb/gitweb.js" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 406 | |
| 407 | case "$httpd" in |
| 408 | *lighttpd*) |
| 409 | lighttpd_conf |
| 410 | ;; |
| 411 | *apache2*) |
| 412 | apache2_conf |
| 413 | ;; |
Mike Dalessio | 425b78e | 2007-10-06 13:29:49 -0400 | [diff] [blame] | 414 | webrick) |
| 415 | webrick_conf |
| 416 | ;; |
Wilhansen Li | 0ded475 | 2009-08-21 22:24:48 +0800 | [diff] [blame] | 417 | *mongoose*) |
| 418 | mongoose_conf |
| 419 | ;; |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 420 | *) |
| 421 | echo "Unknown httpd specified: $httpd" |
| 422 | exit 1 |
| 423 | ;; |
| 424 | esac |
| 425 | |
| 426 | start_httpd |
Johannes Schindelin | 5209eda | 2006-07-26 23:11:46 +0200 | [diff] [blame] | 427 | url=http://127.0.0.1:$port |
Christian Couder | 2e0c290 | 2008-02-02 07:32:56 +0100 | [diff] [blame] | 428 | |
| 429 | if test -n "$browser"; then |
| 430 | git web--browse -b "$browser" $url || echo $url |
| 431 | else |
| 432 | git web--browse -c "instaweb.browser" $url || echo $url |
| 433 | fi |