#!/bin/sh
set -eu

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

if [ ! -e /etc/coulobre/panel.env ]; then
    printf '%s\n' \
        'The Coulobre installer is ready. After APT exits, start setup with the command below.' \
        '  sudo coulobre-install --interactive' \
        'Run coulobre-install --help for config-file and web setup.'
    exit 0
fi

systemctl daemon-reload
systemd-run --quiet --wait --pipe --collect \
    --property=EnvironmentFile=/etc/coulobre/panel.env \
    --setenv=PYTHONPATH=/usr/share/coulobre-panel/source/src \
    /opt/coulobre/bin/python -P -m coulobre.package_upgrade

systemctl enable --now coulobre-remote-deploy.socket
