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