if [ "$1" = "install" ] || [ "$1" = "upgrade" ]; then
    # Record which of this package's units already exist on the system *before*
    # our files are unpacked. postinst enables only the units missing here.
    # This is the only moment that reliably answers "was the unit there
    # before this package version": once we are unpacked, any other maintainer
    # script in the same dpkg run (deb-systemd-helper runs 'svctl compile &&
    # svctl update' unconditionally) compiles our unit into the s6-rc databases
    # as "known, not enabled", and asking svctl afterwards gives the wrong answer.
    mkdir -p /var/lib/dh-s6
    : > "/var/lib/dh-s6/#PACKAGE#.existing"
    for unit in #UNITFILES#; do
        if [ -d "/usr/lib/s6-rc/sources/$unit" ]; then
            echo "$unit" >> "/var/lib/dh-s6/#PACKAGE#.existing"
        fi
    done
fi
