t / lib-httpd.shon commit Merge branch 'maint-1.6.0' into maint-1.6.1 (96aa7ad)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
   4#
   5
   6if test -z "$GIT_TEST_HTTPD"
   7then
   8        say "skipping test, network testing disabled by default"
   9        say "(define GIT_TEST_HTTPD to enable)"
  10        test_done
  11        exit
  12fi
  13
  14LIB_HTTPD_PATH=${LIB_HTTPD_PATH-'/usr/sbin/apache2'}
  15LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'8111'}
  16
  17TEST_PATH="$TEST_DIRECTORY"/lib-httpd
  18HTTPD_ROOT_PATH="$PWD"/httpd
  19HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www
  20
  21if ! test -x "$LIB_HTTPD_PATH"
  22then
  23        say "skipping test, no web server found at '$LIB_HTTPD_PATH'"
  24        test_done
  25        exit
  26fi
  27
  28HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
  29        sed -n 's/^Server version: Apache\/\([0-9]*\)\..*$/\1/p; q'`
  30
  31if test -n "$HTTPD_VERSION"
  32then
  33        if test -z "$LIB_HTTPD_MODULE_PATH"
  34        then
  35                if ! test $HTTPD_VERSION -ge 2
  36                then
  37                        say "skipping test, at least Apache version 2 is required"
  38                        test_done
  39                        exit
  40                fi
  41
  42                LIB_HTTPD_MODULE_PATH='/usr/lib/apache2/modules'
  43        fi
  44else
  45        error "Could not identify web server at '$LIB_HTTPD_PATH'"
  46fi
  47
  48HTTPD_PARA=""
  49
  50prepare_httpd() {
  51        mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH"
  52
  53        ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
  54
  55        if test -n "$LIB_HTTPD_SSL"
  56        then
  57                HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT
  58
  59                RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
  60                        -config "$TEST_PATH/ssl.cnf" \
  61                        -new -x509 -nodes \
  62                        -out "$HTTPD_ROOT_PATH/httpd.pem" \
  63                        -keyout "$HTTPD_ROOT_PATH/httpd.pem"
  64                GIT_SSL_NO_VERIFY=t
  65                export GIT_SSL_NO_VERIFY
  66                HTTPD_PARA="$HTTPD_PARA -DSSL"
  67        else
  68                HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT
  69        fi
  70
  71        if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
  72        then
  73                HTTPD_PARA="$HTTPD_PARA -DDAV"
  74
  75                if test -n "$LIB_HTTPD_SVN"
  76                then
  77                        HTTPD_PARA="$HTTPD_PARA -DSVN"
  78                        rawsvnrepo="$HTTPD_ROOT_PATH/svnrepo"
  79                        svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn"
  80                fi
  81        fi
  82}
  83
  84start_httpd() {
  85        prepare_httpd
  86
  87        trap 'stop_httpd; die' exit
  88
  89        "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
  90                -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
  91                -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start
  92}
  93
  94stop_httpd() {
  95        trap 'die' exit
  96
  97        "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
  98                -f "$TEST_PATH/apache.conf" -k stop
  99}