1#!/bin/bash
 2echo "Expanding chart_httpd.conf"
 3
 4if [[ "${CHART_PREFIX:0:1}" == "/" ]]; then
 5    export CHART_TRUNC_PREFIX="${CHART_PREFIX:1:-1}"
 6else
 7    export CHART_TRUNC_PREFIX="${CHART_PREFIX:0:-1}"
 8fi
 9
10envsubst '$CHART_TRUNC_PREFIX $CHART_PORT $CHART_FRONTEND_PORT $CHART_LOG_DIR' < chart_httpd.conf.tmpl > /etc/apache2/sites-available/chart_httpd.conf
11if [[ "${AUTH_TYPE}" == "digest" ]]; then
12    echo "Expanding authdigest.tmpl"
13    envsubst '$CHART_PREFIX $CHART_AUTH_TYPE $CHART_AUTH_FILE $CHART_AUTH_REALM ' < authdigest.tmpl > authdigest
14    sed -i '/--Auth placeholder--/r authdigest' /etc/apache2/sites-available/chart_httpd.conf
15fi
16perl -p -i -e "s/Listen 80/Listen ${CHART_FRONTEND_PORT}/" /etc/apache2/ports.conf
17echo "Configuring Apache"
18QUIET=--quiet
19# QUIET=
20a2dissite ${QUIET} 000-default
21a2ensite ${QUIET} chart_httpd
22a2enmod ${QUIET} headers
23# a2enmod ${QUIET} deflate
24a2enmod ${QUIET} proxy_http
25a2enmod ${QUIET} expires
26a2enmod ${QUIET} auth_digest
27# setenforce 0
28mkdir /var/run/apache2
29source /etc/apache2/envvars
30if [[ $# -eq 0 ]]; then
31    echo "Running apache in foreground"
32    /usr/sbin/apache2 -D FOREGROUND
33else
34    echo "Switching to $@"
35    exec $@
36fi