#!/bin/sh
# Cerynix — postinst
# Copyright (c) 2026 SIA Cerynix. All rights reserved.
# SPDX-License-Identifier: LicenseRef-Cerynix-Proprietary
#
# We deliberately DO NOT start the stack here: install.sh needs a hostname and
# generates per-install secrets, so a fresh box has nothing to run yet. We only
# register + enable the unit so it comes up on boot AFTER `cerynix init` has
# written /opt/cerynix/.env (the unit no-ops until then).
set -e

UNIT=cerynix.service

case "$1" in
  configure)
    # Reload unit definitions, then enable (start-on-boot) without starting now.
    if [ -d /run/systemd/system ]; then
      systemctl --system daemon-reload >/dev/null 2>&1 || true
    fi
    if command -v deb-systemd-helper >/dev/null 2>&1; then
      deb-systemd-helper enable "$UNIT" >/dev/null 2>&1 || true
    elif command -v systemctl >/dev/null 2>&1; then
      systemctl enable "$UNIT" >/dev/null 2>&1 || true
    fi

    cat <<'EOF'

  Cerynix is installed under /opt/cerynix.

  The stack was NOT started automatically — it needs a hostname and generates
  its own secrets on first run. To configure it and bring it up, run:

      sudo cerynix init

  After that:  cerynix status | cerynix logs | cerynix repair | cerynix upgrade

EOF
    ;;
  abort-upgrade|abort-remove|abort-deconfigure)
    ;;
esac

exit 0
