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)" |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 27 | root="$(git config --get instaweb.gitwebdir)" |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 28 | port=$(git config --get instaweb.port) |
| 29 | module_path="$(git config --get instaweb.modulepath)" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 30 | |
Jonas Fonseca | 9126425 | 2007-11-09 00:21:42 +0100 | [diff] [blame] | 31 | conf="$GIT_DIR/gitweb/httpd.conf" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 32 | |
| 33 | # Defaults: |
| 34 | |
Pavel Roskin | 82e5a82 | 2006-07-10 01:50:18 -0400 | [diff] [blame] | 35 | # if installed, it doesn't need further configuration (module_path) |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 36 | test -z "$httpd" && httpd='lighttpd -f' |
| 37 | |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 38 | # Default is @@GITWEBDIR@@ |
| 39 | test -z "$root" && root='@@GITWEBDIR@@' |
| 40 | |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 41 | # any untaken local port will do... |
| 42 | test -z "$port" && port=1234 |
| 43 | |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 44 | resolve_full_httpd () { |
| 45 | case "$httpd" in |
Dan McGee | 4bdf859 | 2010-06-30 07:29:08 -0500 | [diff] [blame] | 46 | *apache2*|*lighttpd*|*httpd*) |
| 47 | # yes, *httpd* covers *lighttpd* above, but it is there for clarity |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 48 | # ensure that the apache2/lighttpd command ends with "-f" |
Junio C Hamano | e1622bf | 2009-11-23 15:56:32 -0800 | [diff] [blame] | 49 | if ! echo "$httpd" | sane_grep -- '-f *$' >/dev/null 2>&1 |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 50 | then |
| 51 | httpd="$httpd -f" |
| 52 | fi |
| 53 | ;; |
Jakub Narebski | 7864698 | 2010-05-28 21:11:25 +0200 | [diff] [blame] | 54 | *plackup*) |
| 55 | # server is started by running via generated gitweb.psgi in $fqgitdir/gitweb |
| 56 | full_httpd="$fqgitdir/gitweb/gitweb.psgi" |
| 57 | httpd_only="${httpd%% *}" # cut on first space |
| 58 | return |
| 59 | ;; |
Eric Wong | 422bff2 | 2010-08-04 09:51:25 +0000 | [diff] [blame] | 60 | *webrick*) |
Eric Wong | f46e130 | 2010-08-05 08:35:45 +0000 | [diff] [blame] | 61 | # server is started by running via generated webrick.rb in |
Eric Wong | 422bff2 | 2010-08-04 09:51:25 +0000 | [diff] [blame] | 62 | # $fqgitdir/gitweb |
Eric Wong | f46e130 | 2010-08-05 08:35:45 +0000 | [diff] [blame] | 63 | full_httpd="$fqgitdir/gitweb/webrick.rb" |
Eric Wong | 422bff2 | 2010-08-04 09:51:25 +0000 | [diff] [blame] | 64 | httpd_only="${httpd%% *}" # cut on first space |
| 65 | return |
| 66 | ;; |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 67 | esac |
| 68 | |
| 69 | httpd_only="$(echo $httpd | cut -f1 -d' ')" |
Ramsay Jones | e47eec8 | 2009-03-09 18:31:55 +0000 | [diff] [blame] | 70 | 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] | 71 | then |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 72 | full_httpd=$httpd |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 73 | else |
| 74 | # many httpds are installed in /usr/sbin or /usr/local/sbin |
| 75 | # these days and those are not in most users $PATHs |
Mike Dalessio | 14b45b6 | 2007-10-06 13:29:48 -0400 | [diff] [blame] | 76 | # in addition, we may have generated a server script |
| 77 | # in $fqgitdir/gitweb. |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 78 | for i in /usr/local/sbin /usr/sbin "$root" "$fqgitdir/gitweb" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 79 | do |
| 80 | if test -x "$i/$httpd_only" |
| 81 | then |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 82 | full_httpd=$i/$httpd |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 83 | return |
| 84 | fi |
| 85 | done |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 86 | |
| 87 | echo >&2 "$httpd_only not found. Install $httpd_only or use" \ |
| 88 | "--httpd to specify another httpd daemon." |
Fredrik Kuivinen | f281e3a | 2007-01-06 11:40:06 +0100 | [diff] [blame] | 89 | exit 1 |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 90 | fi |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | start_httpd () { |
Stephen Boyd | 0b624b4 | 2009-11-22 23:09:12 -0800 | [diff] [blame] | 94 | if test -f "$fqgitdir/pid"; then |
| 95 | say "Instance already running. Restarting..." |
| 96 | stop_httpd |
| 97 | fi |
| 98 | |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 99 | # here $httpd should have a meaningful value |
| 100 | resolve_full_httpd |
| 101 | |
| 102 | # don't quote $full_httpd, there can be arguments to it (-f) |
Wilhansen Li | 0ded475 | 2009-08-21 22:24:48 +0800 | [diff] [blame] | 103 | case "$httpd" in |
Jakub Narebski | 7864698 | 2010-05-28 21:11:25 +0200 | [diff] [blame] | 104 | *mongoose*|*plackup*) |
| 105 | #These servers don't have a daemon mode so we'll have to fork it |
Wilhansen Li | 0ded475 | 2009-08-21 22:24:48 +0800 | [diff] [blame] | 106 | $full_httpd "$fqgitdir/gitweb/httpd.conf" & |
| 107 | #Save the pid before doing anything else (we'll print it later) |
| 108 | pid=$! |
| 109 | |
| 110 | if test $? != 0; then |
| 111 | echo "Could not execute http daemon $httpd." |
| 112 | exit 1 |
| 113 | fi |
| 114 | |
| 115 | cat > "$fqgitdir/pid" <<EOF |
| 116 | $pid |
| 117 | EOF |
| 118 | ;; |
| 119 | *) |
| 120 | $full_httpd "$fqgitdir/gitweb/httpd.conf" |
| 121 | if test $? != 0; then |
| 122 | echo "Could not execute http daemon $httpd." |
| 123 | exit 1 |
| 124 | fi |
| 125 | ;; |
| 126 | esac |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | stop_httpd () { |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 130 | test -f "$fqgitdir/pid" && kill $(cat "$fqgitdir/pid") |
Jakub Narebski | d112762 | 2010-05-28 21:11:23 +0200 | [diff] [blame] | 131 | rm -f "$fqgitdir/pid" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Jakub Narebski | d94775e | 2010-05-28 21:11:24 +0200 | [diff] [blame] | 134 | httpd_is_ready () { |
| 135 | "$PERL" -MIO::Socket::INET -e " |
| 136 | local \$| = 1; # turn on autoflush |
| 137 | exit if (IO::Socket::INET->new('127.0.0.1:$port')); |
| 138 | print 'Waiting for \'$httpd\' to start ..'; |
| 139 | do { |
| 140 | print '.'; |
| 141 | sleep(1); |
| 142 | } until (IO::Socket::INET->new('127.0.0.1:$port')); |
| 143 | print qq! (done)\n!; |
| 144 | " |
| 145 | } |
| 146 | |
David Kastrup | 822f7c7 | 2007-09-23 22:42:08 +0200 | [diff] [blame] | 147 | while test $# != 0 |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 148 | do |
| 149 | case "$1" in |
| 150 | --stop|stop) |
| 151 | stop_httpd |
| 152 | exit 0 |
| 153 | ;; |
| 154 | --start|start) |
| 155 | start_httpd |
| 156 | exit 0 |
| 157 | ;; |
| 158 | --restart|restart) |
| 159 | stop_httpd |
| 160 | start_httpd |
| 161 | exit 0 |
| 162 | ;; |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 163 | -l|--local) |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 164 | local=true |
| 165 | ;; |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 166 | -d|--httpd) |
| 167 | shift |
| 168 | httpd="$1" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 169 | ;; |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 170 | -b|--browser) |
| 171 | shift |
| 172 | browser="$1" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 173 | ;; |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 174 | -p|--port) |
| 175 | shift |
| 176 | port="$1" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 177 | ;; |
Pierre Habouzit | c2db2e0 | 2007-11-04 11:30:59 +0100 | [diff] [blame] | 178 | -m|--module-path) |
| 179 | shift |
| 180 | module_path="$1" |
| 181 | ;; |
| 182 | --) |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 183 | ;; |
| 184 | *) |
| 185 | usage |
| 186 | ;; |
| 187 | esac |
| 188 | shift |
| 189 | done |
| 190 | |
| 191 | mkdir -p "$GIT_DIR/gitweb/tmp" |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 192 | GIT_EXEC_PATH="$(git --exec-path)" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 193 | GIT_DIR="$fqgitdir" |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 194 | GITWEB_CONFIG="$fqgitdir/gitweb/gitweb_config.perl" |
| 195 | export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 196 | |
Mike Dalessio | 425b78e | 2007-10-06 13:29:49 -0400 | [diff] [blame] | 197 | webrick_conf () { |
Eric Wong | 422bff2 | 2010-08-04 09:51:25 +0000 | [diff] [blame] | 198 | # webrick seems to have no way of passing arbitrary environment |
| 199 | # variables to the underlying CGI executable, so we wrap the |
| 200 | # actual gitweb.cgi using a shell script to force it |
| 201 | wrapper="$fqgitdir/gitweb/$httpd/wrapper.sh" |
| 202 | cat > "$wrapper" <<EOF |
| 203 | #!/bin/sh |
| 204 | # we use this shell script wrapper around the real gitweb.cgi since |
| 205 | # there appears to be no other way to pass arbitrary environment variables |
| 206 | # into the CGI process |
| 207 | GIT_EXEC_PATH=$GIT_EXEC_PATH GIT_DIR=$GIT_DIR GITWEB_CONFIG=$GITWEB_CONFIG |
| 208 | export GIT_EXEC_PATH GIT_DIR GITWEB_CONFIG |
| 209 | exec $root/gitweb.cgi |
| 210 | EOF |
| 211 | chmod +x "$wrapper" |
| 212 | |
| 213 | # This assumes _ruby_ is in the user's $PATH. that's _one_ |
| 214 | # portable way to run ruby, which could be installed anywhere, really. |
Mike Dalessio | 425b78e | 2007-10-06 13:29:49 -0400 | [diff] [blame] | 215 | # generate a standalone server script in $fqgitdir/gitweb. |
| 216 | cat >"$fqgitdir/gitweb/$httpd.rb" <<EOF |
Eric Wong | f46e130 | 2010-08-05 08:35:45 +0000 | [diff] [blame] | 217 | #!/usr/bin/env ruby |
Mike Dalessio | 425b78e | 2007-10-06 13:29:49 -0400 | [diff] [blame] | 218 | require 'webrick' |
Eric Wong | e9323e7 | 2010-08-05 08:46:04 +0000 | [diff] [blame] | 219 | require 'logger' |
Eric Wong | f46e130 | 2010-08-05 08:35:45 +0000 | [diff] [blame] | 220 | options = { |
| 221 | :Port => $port, |
| 222 | :DocumentRoot => "$root", |
Eric Wong | e9323e7 | 2010-08-05 08:46:04 +0000 | [diff] [blame] | 223 | :Logger => Logger.new('$fqgitdir/gitweb/error.log'), |
| 224 | :AccessLog => [ |
| 225 | [ Logger.new('$fqgitdir/gitweb/access.log'), |
| 226 | WEBrick::AccessLog::COMBINED_LOG_FORMAT ] |
| 227 | ], |
Eric Wong | f46e130 | 2010-08-05 08:35:45 +0000 | [diff] [blame] | 228 | :DirectoryIndex => ["gitweb.cgi"], |
| 229 | :CGIInterpreter => "$wrapper", |
| 230 | :StartCallback => lambda do |
| 231 | File.open("$fqgitdir/pid", "w") { |f| f.puts Process.pid } |
| 232 | end, |
| 233 | :ServerType => WEBrick::Daemon, |
| 234 | } |
| 235 | options[:BindAddress] = '127.0.0.1' if "$local" == "true" |
Mike Dalessio | 425b78e | 2007-10-06 13:29:49 -0400 | [diff] [blame] | 236 | server = WEBrick::HTTPServer.new(options) |
| 237 | ['INT', 'TERM'].each do |signal| |
| 238 | trap(signal) {server.shutdown} |
| 239 | end |
| 240 | server.start |
| 241 | EOF |
Eric Wong | f46e130 | 2010-08-05 08:35:45 +0000 | [diff] [blame] | 242 | chmod +x "$fqgitdir/gitweb/$httpd.rb" |
| 243 | # configuration is embedded in server script file, webrick.rb |
| 244 | rm -f "$conf" |
Mike Dalessio | 425b78e | 2007-10-06 13:29:49 -0400 | [diff] [blame] | 245 | } |
| 246 | |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 247 | lighttpd_conf () { |
| 248 | cat > "$conf" <<EOF |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 249 | server.document-root = "$root" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 250 | server.port = $port |
Ramsay Jones | e47eec8 | 2009-03-09 18:31:55 +0000 | [diff] [blame] | 251 | server.modules = ( "mod_setenv", "mod_cgi" ) |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 252 | server.indexfiles = ( "gitweb.cgi" ) |
| 253 | server.pid-file = "$fqgitdir/pid" |
Pavan Kumar Sunkara | be5347b | 2010-05-28 11:55:51 +0530 | [diff] [blame] | 254 | server.errorlog = "$fqgitdir/gitweb/$httpd_only/error.log" |
Ramsay Jones | e47eec8 | 2009-03-09 18:31:55 +0000 | [diff] [blame] | 255 | |
| 256 | # to enable, add "mod_access", "mod_accesslog" to server.modules |
| 257 | # variable above and uncomment this |
Pavan Kumar Sunkara | be5347b | 2010-05-28 11:55:51 +0530 | [diff] [blame] | 258 | #accesslog.filename = "$fqgitdir/gitweb/$httpd_only/access.log" |
Ramsay Jones | e47eec8 | 2009-03-09 18:31:55 +0000 | [diff] [blame] | 259 | |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 260 | setenv.add-environment = ( "PATH" => env.PATH, "GITWEB_CONFIG" => env.GITWEB_CONFIG ) |
Ramsay Jones | e47eec8 | 2009-03-09 18:31:55 +0000 | [diff] [blame] | 261 | |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 262 | cgi.assign = ( ".cgi" => "" ) |
Ramsay Jones | e47eec8 | 2009-03-09 18:31:55 +0000 | [diff] [blame] | 263 | |
| 264 | # mimetype mapping |
| 265 | mimetype.assign = ( |
| 266 | ".pdf" => "application/pdf", |
| 267 | ".sig" => "application/pgp-signature", |
| 268 | ".spl" => "application/futuresplash", |
| 269 | ".class" => "application/octet-stream", |
| 270 | ".ps" => "application/postscript", |
| 271 | ".torrent" => "application/x-bittorrent", |
| 272 | ".dvi" => "application/x-dvi", |
| 273 | ".gz" => "application/x-gzip", |
| 274 | ".pac" => "application/x-ns-proxy-autoconfig", |
| 275 | ".swf" => "application/x-shockwave-flash", |
| 276 | ".tar.gz" => "application/x-tgz", |
| 277 | ".tgz" => "application/x-tgz", |
| 278 | ".tar" => "application/x-tar", |
| 279 | ".zip" => "application/zip", |
| 280 | ".mp3" => "audio/mpeg", |
| 281 | ".m3u" => "audio/x-mpegurl", |
| 282 | ".wma" => "audio/x-ms-wma", |
| 283 | ".wax" => "audio/x-ms-wax", |
| 284 | ".ogg" => "application/ogg", |
| 285 | ".wav" => "audio/x-wav", |
| 286 | ".gif" => "image/gif", |
| 287 | ".jpg" => "image/jpeg", |
| 288 | ".jpeg" => "image/jpeg", |
| 289 | ".png" => "image/png", |
| 290 | ".xbm" => "image/x-xbitmap", |
| 291 | ".xpm" => "image/x-xpixmap", |
| 292 | ".xwd" => "image/x-xwindowdump", |
| 293 | ".css" => "text/css", |
| 294 | ".html" => "text/html", |
| 295 | ".htm" => "text/html", |
| 296 | ".js" => "text/javascript", |
| 297 | ".asc" => "text/plain", |
| 298 | ".c" => "text/plain", |
| 299 | ".cpp" => "text/plain", |
| 300 | ".log" => "text/plain", |
| 301 | ".conf" => "text/plain", |
| 302 | ".text" => "text/plain", |
| 303 | ".txt" => "text/plain", |
| 304 | ".dtd" => "text/xml", |
| 305 | ".xml" => "text/xml", |
| 306 | ".mpeg" => "video/mpeg", |
| 307 | ".mpg" => "video/mpeg", |
| 308 | ".mov" => "video/quicktime", |
| 309 | ".qt" => "video/quicktime", |
| 310 | ".avi" => "video/x-msvideo", |
| 311 | ".asf" => "video/x-ms-asf", |
| 312 | ".asx" => "video/x-ms-asf", |
| 313 | ".wmv" => "video/x-ms-wmv", |
| 314 | ".bz2" => "application/x-bzip", |
| 315 | ".tbz" => "application/x-bzip-compressed-tar", |
| 316 | ".tar.bz2" => "application/x-bzip-compressed-tar", |
| 317 | "" => "text/plain" |
| 318 | ) |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 319 | EOF |
Jonas Fonseca | 9126425 | 2007-11-09 00:21:42 +0100 | [diff] [blame] | 320 | test x"$local" = xtrue && echo 'server.bind = "127.0.0.1"' >> "$conf" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | apache2_conf () { |
Dan McGee | 4bdf859 | 2010-06-30 07:29:08 -0500 | [diff] [blame] | 324 | if test -z "$module_path" |
| 325 | then |
| 326 | test -d "/usr/lib/httpd/modules" && |
| 327 | module_path="/usr/lib/httpd/modules" |
| 328 | test -d "/usr/lib/apache2/modules" && |
| 329 | module_path="/usr/lib/apache2/modules" |
| 330 | fi |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 331 | bind= |
Jonas Fonseca | 9126425 | 2007-11-09 00:21:42 +0100 | [diff] [blame] | 332 | test x"$local" = xtrue && bind='127.0.0.1:' |
Sean Estabrooks | e24c76b | 2009-07-18 09:45:44 -0700 | [diff] [blame] | 333 | echo 'text/css css' > "$fqgitdir/mime.types" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 334 | cat > "$conf" <<EOF |
Eric Wong | 44a167b | 2007-01-02 00:57:11 -0800 | [diff] [blame] | 335 | ServerName "git-instaweb" |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 336 | ServerRoot "$root" |
| 337 | DocumentRoot "$root" |
Pavan Kumar Sunkara | be5347b | 2010-05-28 11:55:51 +0530 | [diff] [blame] | 338 | ErrorLog "$fqgitdir/gitweb/$httpd_only/error.log" |
| 339 | CustomLog "$fqgitdir/gitweb/$httpd_only/access.log" combined |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 340 | PidFile "$fqgitdir/pid" |
| 341 | Listen $bind$port |
Eric Wong | 44a167b | 2007-01-02 00:57:11 -0800 | [diff] [blame] | 342 | EOF |
| 343 | |
Dan McGee | 4bdf859 | 2010-06-30 07:29:08 -0500 | [diff] [blame] | 344 | for mod in mime dir env log_config |
| 345 | do |
| 346 | if test -e $module_path/mod_${mod}.so |
| 347 | then |
Eric Wong | 44a167b | 2007-01-02 00:57:11 -0800 | [diff] [blame] | 348 | echo "LoadModule ${mod}_module " \ |
| 349 | "$module_path/mod_${mod}.so" >> "$conf" |
| 350 | fi |
| 351 | done |
| 352 | cat >> "$conf" <<EOF |
Sean Estabrooks | e24c76b | 2009-07-18 09:45:44 -0700 | [diff] [blame] | 353 | TypesConfig "$fqgitdir/mime.types" |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 354 | DirectoryIndex gitweb.cgi |
| 355 | EOF |
| 356 | |
| 357 | # check to see if Dennis Stosberg's mod_perl compatibility patch |
| 358 | # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied |
Junio C Hamano | e1622bf | 2009-11-23 15:56:32 -0800 | [diff] [blame] | 359 | if test -f "$module_path/mod_perl.so" && |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 360 | sane_grep 'MOD_PERL' "$root/gitweb.cgi" >/dev/null |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 361 | then |
| 362 | # favor mod_perl if available |
| 363 | cat >> "$conf" <<EOF |
| 364 | LoadModule perl_module $module_path/mod_perl.so |
| 365 | PerlPassEnv GIT_DIR |
Dan McGee | 2989f51 | 2010-06-29 21:44:59 -0500 | [diff] [blame] | 366 | PerlPassEnv GIT_EXEC_PATH |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 367 | PerlPassEnv GITWEB_CONFIG |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 368 | <Location /gitweb.cgi> |
| 369 | SetHandler perl-script |
| 370 | PerlResponseHandler ModPerl::Registry |
| 371 | PerlOptions +ParseHeaders |
| 372 | Options +ExecCGI |
| 373 | </Location> |
| 374 | EOF |
| 375 | else |
| 376 | # plain-old CGI |
Flavio Poletti | 43d60d2 | 2008-06-12 23:54:55 +0200 | [diff] [blame] | 377 | resolve_full_httpd |
Stephen Boyd | 9524cf2 | 2010-01-26 15:08:31 -0800 | [diff] [blame] | 378 | list_mods=$(echo "$full_httpd" | sed 's/-f$/-l/') |
Junio C Hamano | e1622bf | 2009-11-23 15:56:32 -0800 | [diff] [blame] | 379 | $list_mods | sane_grep 'mod_cgi\.c' >/dev/null 2>&1 || \ |
Mark Rada | 10d1432 | 2009-09-26 14:12:32 -0400 | [diff] [blame] | 380 | if test -f "$module_path/mod_cgi.so" |
| 381 | then |
| 382 | echo "LoadModule cgi_module $module_path/mod_cgi.so" >> "$conf" |
| 383 | else |
| 384 | $list_mods | grep 'mod_cgid\.c' >/dev/null 2>&1 || \ |
| 385 | if test -f "$module_path/mod_cgid.so" |
| 386 | then |
| 387 | echo "LoadModule cgid_module $module_path/mod_cgid.so" \ |
| 388 | >> "$conf" |
| 389 | else |
| 390 | echo "You have no CGI support!" |
| 391 | exit 2 |
| 392 | fi |
| 393 | echo "ScriptSock logs/gitweb.sock" >> "$conf" |
| 394 | fi |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 395 | cat >> "$conf" <<EOF |
Dan McGee | 2989f51 | 2010-06-29 21:44:59 -0500 | [diff] [blame] | 396 | PassEnv GIT_DIR |
| 397 | PassEnv GIT_EXEC_PATH |
| 398 | PassEnv GITWEB_CONFIG |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 399 | AddHandler cgi-script .cgi |
| 400 | <Location /gitweb.cgi> |
| 401 | Options +ExecCGI |
| 402 | </Location> |
| 403 | EOF |
| 404 | fi |
| 405 | } |
| 406 | |
Wilhansen Li | 0ded475 | 2009-08-21 22:24:48 +0800 | [diff] [blame] | 407 | mongoose_conf() { |
| 408 | cat > "$conf" <<EOF |
| 409 | # Mongoose web server configuration file. |
| 410 | # Lines starting with '#' and empty lines are ignored. |
| 411 | # For detailed description of every option, visit |
| 412 | # http://code.google.com/p/mongoose/wiki/MongooseManual |
| 413 | |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 414 | root $root |
Wilhansen Li | 0ded475 | 2009-08-21 22:24:48 +0800 | [diff] [blame] | 415 | ports $port |
| 416 | index_files gitweb.cgi |
| 417 | #ssl_cert $fqgitdir/gitweb/ssl_cert.pem |
Pavan Kumar Sunkara | be5347b | 2010-05-28 11:55:51 +0530 | [diff] [blame] | 418 | error_log $fqgitdir/gitweb/$httpd_only/error.log |
| 419 | access_log $fqgitdir/gitweb/$httpd_only/access.log |
Wilhansen Li | 0ded475 | 2009-08-21 22:24:48 +0800 | [diff] [blame] | 420 | |
| 421 | #cgi setup |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 422 | cgi_env PATH=$PATH,GIT_DIR=$GIT_DIR,GIT_EXEC_PATH=$GIT_EXEC_PATH,GITWEB_CONFIG=$GITWEB_CONFIG |
Wilhansen Li | 0ded475 | 2009-08-21 22:24:48 +0800 | [diff] [blame] | 423 | cgi_interp $PERL |
| 424 | cgi_ext cgi,pl |
| 425 | |
| 426 | # mimetype mapping |
| 427 | 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 |
| 428 | EOF |
| 429 | } |
| 430 | |
Jakub Narebski | 7864698 | 2010-05-28 21:11:25 +0200 | [diff] [blame] | 431 | plackup_conf () { |
| 432 | # generate a standalone 'plackup' server script in $fqgitdir/gitweb |
| 433 | # with embedded configuration; it does not use "$conf" file |
| 434 | cat > "$fqgitdir/gitweb/gitweb.psgi" <<EOF |
| 435 | #!$PERL |
| 436 | |
| 437 | # gitweb - simple web interface to track changes in git repositories |
| 438 | # PSGI wrapper and server starter (see http://plackperl.org) |
| 439 | |
| 440 | use strict; |
| 441 | |
| 442 | use IO::Handle; |
| 443 | use Plack::MIME; |
| 444 | use Plack::Builder; |
| 445 | use Plack::App::WrapCGI; |
| 446 | use CGI::Emulate::PSGI 0.07; # minimum version required to work with gitweb |
| 447 | |
| 448 | # mimetype mapping (from lighttpd_conf) |
| 449 | Plack::MIME->add_type( |
| 450 | ".pdf" => "application/pdf", |
| 451 | ".sig" => "application/pgp-signature", |
| 452 | ".spl" => "application/futuresplash", |
| 453 | ".class" => "application/octet-stream", |
| 454 | ".ps" => "application/postscript", |
| 455 | ".torrent" => "application/x-bittorrent", |
| 456 | ".dvi" => "application/x-dvi", |
| 457 | ".gz" => "application/x-gzip", |
| 458 | ".pac" => "application/x-ns-proxy-autoconfig", |
| 459 | ".swf" => "application/x-shockwave-flash", |
| 460 | ".tar.gz" => "application/x-tgz", |
| 461 | ".tgz" => "application/x-tgz", |
| 462 | ".tar" => "application/x-tar", |
| 463 | ".zip" => "application/zip", |
| 464 | ".mp3" => "audio/mpeg", |
| 465 | ".m3u" => "audio/x-mpegurl", |
| 466 | ".wma" => "audio/x-ms-wma", |
| 467 | ".wax" => "audio/x-ms-wax", |
| 468 | ".ogg" => "application/ogg", |
| 469 | ".wav" => "audio/x-wav", |
| 470 | ".gif" => "image/gif", |
| 471 | ".jpg" => "image/jpeg", |
| 472 | ".jpeg" => "image/jpeg", |
| 473 | ".png" => "image/png", |
| 474 | ".xbm" => "image/x-xbitmap", |
| 475 | ".xpm" => "image/x-xpixmap", |
| 476 | ".xwd" => "image/x-xwindowdump", |
| 477 | ".css" => "text/css", |
| 478 | ".html" => "text/html", |
| 479 | ".htm" => "text/html", |
| 480 | ".js" => "text/javascript", |
| 481 | ".asc" => "text/plain", |
| 482 | ".c" => "text/plain", |
| 483 | ".cpp" => "text/plain", |
| 484 | ".log" => "text/plain", |
| 485 | ".conf" => "text/plain", |
| 486 | ".text" => "text/plain", |
| 487 | ".txt" => "text/plain", |
| 488 | ".dtd" => "text/xml", |
| 489 | ".xml" => "text/xml", |
| 490 | ".mpeg" => "video/mpeg", |
| 491 | ".mpg" => "video/mpeg", |
| 492 | ".mov" => "video/quicktime", |
| 493 | ".qt" => "video/quicktime", |
| 494 | ".avi" => "video/x-msvideo", |
| 495 | ".asf" => "video/x-ms-asf", |
| 496 | ".asx" => "video/x-ms-asf", |
| 497 | ".wmv" => "video/x-ms-wmv", |
| 498 | ".bz2" => "application/x-bzip", |
| 499 | ".tbz" => "application/x-bzip-compressed-tar", |
| 500 | ".tar.bz2" => "application/x-bzip-compressed-tar", |
| 501 | "" => "text/plain" |
| 502 | ); |
| 503 | |
| 504 | my \$app = builder { |
| 505 | # to be able to override \$SIG{__WARN__} to log build time warnings |
| 506 | use CGI::Carp; # it sets \$SIG{__WARN__} itself |
| 507 | |
| 508 | my \$logdir = "$fqgitdir/gitweb/$httpd_only"; |
| 509 | open my \$access_log_fh, '>>', "\$logdir/access.log" |
| 510 | or die "Couldn't open access log '\$logdir/access.log': \$!"; |
| 511 | open my \$error_log_fh, '>>', "\$logdir/error.log" |
| 512 | or die "Couldn't open error log '\$logdir/error.log': \$!"; |
| 513 | |
| 514 | \$access_log_fh->autoflush(1); |
| 515 | \$error_log_fh->autoflush(1); |
| 516 | |
| 517 | # redirect build time warnings to error.log |
| 518 | \$SIG{'__WARN__'} = sub { |
| 519 | my \$msg = shift; |
| 520 | # timestamp warning like in CGI::Carp::warn |
| 521 | my \$stamp = CGI::Carp::stamp(); |
| 522 | \$msg =~ s/^/\$stamp/gm; |
| 523 | print \$error_log_fh \$msg; |
| 524 | }; |
| 525 | |
| 526 | # write errors to error.log, access to access.log |
| 527 | enable 'AccessLog', |
| 528 | format => "combined", |
| 529 | logger => sub { print \$access_log_fh @_; }; |
| 530 | enable sub { |
| 531 | my \$app = shift; |
| 532 | sub { |
| 533 | my \$env = shift; |
| 534 | \$env->{'psgi.errors'} = \$error_log_fh; |
| 535 | \$app->(\$env); |
| 536 | } |
| 537 | }; |
| 538 | # gitweb currently doesn't work with $SIG{CHLD} set to 'IGNORE', |
| 539 | # because it uses 'close $fd or die...' on piped filehandle $fh |
| 540 | # (which causes the parent process to wait for child to finish). |
| 541 | enable_if { \$SIG{'CHLD'} eq 'IGNORE' } sub { |
| 542 | my \$app = shift; |
| 543 | sub { |
| 544 | my \$env = shift; |
| 545 | local \$SIG{'CHLD'} = 'DEFAULT'; |
| 546 | local \$SIG{'CLD'} = 'DEFAULT'; |
| 547 | \$app->(\$env); |
| 548 | } |
| 549 | }; |
| 550 | # serve static files, i.e. stylesheet, images, script |
| 551 | enable 'Static', |
| 552 | path => sub { m!\.(js|css|png)\$! && s!^/gitweb/!! }, |
| 553 | root => "$root/", |
| 554 | encoding => 'utf-8'; # encoding for 'text/plain' files |
| 555 | # convert CGI application to PSGI app |
| 556 | Plack::App::WrapCGI->new(script => "$root/gitweb.cgi")->to_app; |
| 557 | }; |
| 558 | |
| 559 | # make it runnable as standalone app, |
| 560 | # like it would be run via 'plackup' utility |
| 561 | if (__FILE__ eq \$0) { |
| 562 | require Plack::Runner; |
| 563 | |
| 564 | my \$runner = Plack::Runner->new(); |
| 565 | \$runner->parse_options(qw(--env deployment --port $port), |
| 566 | "$local" ? qw(--host 127.0.0.1) : ()); |
| 567 | \$runner->run(\$app); |
| 568 | } |
| 569 | __END__ |
| 570 | EOF |
| 571 | |
| 572 | chmod a+x "$fqgitdir/gitweb/gitweb.psgi" |
| 573 | # configuration is embedded in server script file, gitweb.psgi |
| 574 | rm -f "$conf" |
| 575 | } |
| 576 | |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 577 | gitweb_conf() { |
| 578 | cat > "$fqgitdir/gitweb/gitweb_config.perl" <<EOF |
| 579 | #!/usr/bin/perl |
| 580 | our \$projectroot = "$(dirname "$fqgitdir")"; |
| 581 | our \$git_temp = "$fqgitdir/gitweb/tmp"; |
| 582 | our \$projects_list = \$projectroot; |
Giuseppe Bilotta | fc5b8e0 | 2010-11-11 13:26:18 +0100 | [diff] [blame] | 583 | |
| 584 | \$feature{'remote_heads'}{'default'} = [1]; |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 585 | EOF |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Pavan Kumar Sunkara | c0cb4ed | 2010-05-28 11:55:52 +0530 | [diff] [blame] | 588 | gitweb_conf |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 589 | |
Pavan Kumar Sunkara | be5347b | 2010-05-28 11:55:51 +0530 | [diff] [blame] | 590 | resolve_full_httpd |
| 591 | mkdir -p "$fqgitdir/gitweb/$httpd_only" |
| 592 | |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 593 | case "$httpd" in |
| 594 | *lighttpd*) |
| 595 | lighttpd_conf |
| 596 | ;; |
Dan McGee | 4bdf859 | 2010-06-30 07:29:08 -0500 | [diff] [blame] | 597 | *apache2*|*httpd*) |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 598 | apache2_conf |
| 599 | ;; |
Mike Dalessio | 425b78e | 2007-10-06 13:29:49 -0400 | [diff] [blame] | 600 | webrick) |
| 601 | webrick_conf |
| 602 | ;; |
Wilhansen Li | 0ded475 | 2009-08-21 22:24:48 +0800 | [diff] [blame] | 603 | *mongoose*) |
| 604 | mongoose_conf |
| 605 | ;; |
Jakub Narebski | 7864698 | 2010-05-28 21:11:25 +0200 | [diff] [blame] | 606 | *plackup*) |
| 607 | plackup_conf |
| 608 | ;; |
Eric Wong | a51d37c | 2006-07-01 15:14:14 -0700 | [diff] [blame] | 609 | *) |
| 610 | echo "Unknown httpd specified: $httpd" |
| 611 | exit 1 |
| 612 | ;; |
| 613 | esac |
| 614 | |
| 615 | start_httpd |
Johannes Schindelin | 5209eda | 2006-07-26 23:11:46 +0200 | [diff] [blame] | 616 | url=http://127.0.0.1:$port |
Christian Couder | 2e0c290 | 2008-02-02 07:32:56 +0100 | [diff] [blame] | 617 | |
| 618 | if test -n "$browser"; then |
Jakub Narebski | d94775e | 2010-05-28 21:11:24 +0200 | [diff] [blame] | 619 | httpd_is_ready && git web--browse -b "$browser" $url || echo $url |
Christian Couder | 2e0c290 | 2008-02-02 07:32:56 +0100 | [diff] [blame] | 620 | else |
Jakub Narebski | d94775e | 2010-05-28 21:11:24 +0200 | [diff] [blame] | 621 | httpd_is_ready && git web--browse -c "instaweb.browser" $url || echo $url |
Christian Couder | 2e0c290 | 2008-02-02 07:32:56 +0100 | [diff] [blame] | 622 | fi |