if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ]; then
    if [ -x "/usr/bin/svctl" ]; then
        # Enable a unit exactly once: the first time postinst ever runs for
        # it, tracked by a marker under our own state dir. The marker is
        # only ever written by this unit's own postinst, so it can't be
        # affected by another package's svctl compile/update elsewhere in
        # the same dpkg run -- unlike asking svctl isenabled, which reflects
        # the shared s6-rc database any package's postinst may have already
        # recompiled. An admin's later "svctl disable" is respected on
        # upgrades, since the marker just stays put.
        markerdir="/var/lib/dh-s6/enabled"
        mkdir -p "$markerdir"

        # >>> BEGIN TEMPORARY (see dh_installs6(1) POD) -- once the fleet is
        # past packages built before markers existed: delete this block, and
        # below replace `[ ! -e "$marker" ] && $assumenew` with just
        # `[ ! -e "$marker" ]`.
        #
        # A missing marker normally means "genuinely new, enable it" -- but
        # not on this package's very first run under this scheme, where it's
        # ambiguous with "predates markers entirely" and wrongly enabling
        # would override an admin's earlier svctl disable. A sibling unit
        # already having a marker rules that out (this package has run under
        # this scheme before); $2 (dpkg's old-version arg) rules it out too
        # by being empty, i.e. a genuine first install. Otherwise assume the
        # unit predates markers and leave it alone.
        assumenew=true
        if [ -n "$2" ]; then
            assumenew=false
            for unit in #UNITFILES#; do
                [ -e "$markerdir/$unit" ] && assumenew=true
            done
        fi
        # <<< END TEMPORARY

        s6toenable=""
        for unit in #UNITFILES#; do
            marker="$markerdir/$unit"
            if [ ! -e "$marker" ] && $assumenew; then
                s6toenable="$s6toenable $unit"
            fi
            : > "$marker"
        done
        # compile first (svctl enable resolves units against compiled-work),
        # then enable the new units and switch the live database
        svctl compile || true
        if [ -n "$s6toenable" ]; then
            svctl enable $s6toenable || true
        fi
        if ! svctl update; then
            echo "dh-s6: WARNUNG 'svctl update' ist fehlgeschlagen. Die Meldung darueber nennt" >&2
            echo "dh-s6: WARNUNG die Dienste, die nicht in den gewollten Zustand gekommen sind." >&2
            echo "dh-s6: WARNUNG Das Paket bleibt trotzdem konfiguriert: ein haengender Dienst" >&2
            echo "dh-s6: WARNUNG darf dpkg nicht auf 'iF' stehen lassen und damit jede weitere" >&2
            echo "dh-s6: WARNUNG Paketoperation blockieren (rt-2.tick1, 22.09.2026). Die" >&2
            echo "dh-s6: WARNUNG s6-Datenbank ist dann aber NICHT auf dem neuen Stand:" >&2
            echo "dh-s6: WARNUNG Ursache beheben und 'svctl update' wiederholen." >&2
        fi
    fi
fi
