#!/bin/sh -e

usage() {
    cat << EOF
Usage: configure-web-proxy
Configure a local web proxy using apache for openQA.

Options:
 -h, --help         display this help
EOF
    exit "$1"
}

opts=$(getopt -o h --long help -n "$0" -- "$@") || usage 1
eval set -- "$opts"
while true; do
  case "$1" in
    -h | --help ) usage 0; shift ;;
    -- ) shift; break ;;
    * ) break ;;
  esac
done

for i in headers proxy proxy_http proxy_wstunnel rewrite ; do a2enmod $i ; done
sed -i -e 's/^.*httpsonly.*$/httpsonly = 0/g' /etc/openqa/openqa.ini
sed "s/#ServerName.*$/ServerName $(hostname)/" /etc/apache2/vhosts.d/openqa.conf.template > /etc/apache2/vhosts.d/openqa.conf
