#!/bin/sh

set -e

chmod 755 /usr/lib/python3/dist-packages/libinithooks/inithooks_cache.py

if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] \
        || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
    systemctl daemon-reload >/dev/null || true
    # Firstboot runs package upgrades itself. Restarting initialization or
    # its console here can kill dpkg before configuration has completed.
    # Existing services use the updated scripts on their next invocation.
    rm -f /run/inithooks-was-active /run/turnkey-init-fence-was-active
    if [ -z "$2" ]; then
        # fresh install ($2 is empty) - enable services
        systemctl enable inithooks.service
        systemctl enable turnkey-init-fence.service
    fi
fi

exit 0
