#!/usr/bin/with-contenv bash

rm /etc/nginx/sites-enabled/default 2> /dev/null
if [ "$HTTPS" == "OFF" ]; then
    cp /etc/nginx/sites-enabled.templates/no-https /etc/nginx/sites-enabled/administration
    echo -e "\t\t\033[1;33m* setting NGiNX to run without TLS certificate\033[0m"
else
    cp /etc/nginx/sites-enabled.templates/https /etc/nginx/sites-enabled/administration
    echo -e "\t\t\033[1;33m* setting NGiNX to run with TLS certificate\033[0m"
fi

sed -i "s/__HTTP_PORT__/$HTTP_PORT/g" /etc/nginx/sites-enabled/administration
sed -i "s/__HTTPS_PORT__/$HTTPS_PORT/g" /etc/nginx/sites-enabled/administration

if [ "$DISABLE_ROUNDCUBE" == "TRUE" ]; then
    rm -Rf /opt/www/webmail 2> /dev/null
fi

if [ "$APP_ENV" == "dev" ]; then
    cp /etc/dev/admin.conf /etc/php/7.4/fpm/pool.d/admin.conf
    cp /etc/dev/administration /etc/nginx/administration
fi
