#!/bin/bash

set -e

if [ "$1" != "configure" ]; then
    exit 0
fi

# Touch and set permisions on default log files on installation
update-rc.d hestia defaults >/dev/null
invoke-rc.d hestia start || true

# Run triggers only on updates
if [ ! -e "/usr/local/hestia/data/users/admin" ]; then
    exit
fi

# Load hestia.conf
source /usr/local/hestia/conf/hestia.conf

# Reset backend port
if [ ! -z "$BACKEND_PORT" ]; then
    /usr/local/hestia/bin/v-change-sys-port $BACKEND_PORT
fi

# Restart hestia service
if [ -f "/etc/init.d/hestia" ]; then
    systemctl restart hestia > /dev/null 2>&1
fi