#!/bin/sh
# postinst script for apparmor
#
# see: dh_installdeb(1)
set -e

. /usr/lib/apparmor/rc.apparmor.functions

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

# Automatically added by dh_apparmor/3.0.4-2ubuntu2.1
if [ "$1" = "configure" ]; then
    APP_PROFILE="/etc/apparmor.d/lsb_release"
    if [ -f "$APP_PROFILE" ]; then
        # Add the local/ include
        LOCAL_APP_PROFILE="/etc/apparmor.d/local/lsb_release"

        test -e "$LOCAL_APP_PROFILE" || {
            mkdir -p `dirname "$LOCAL_APP_PROFILE"`
            install --mode 644 /dev/null "$LOCAL_APP_PROFILE"
        }

        # Reload the profile, including any abstraction updates
        if aa-enabled --quiet 2>/dev/null; then
            apparmor_parser -r -T -W "$APP_PROFILE" || true
        fi
    fi
fi
# End automatically added section
# Automatically added by dh_apparmor/3.0.4-2ubuntu2.1
if [ "$1" = "configure" ]; then
    APP_PROFILE="/etc/apparmor.d/nvidia_modprobe"
    if [ -f "$APP_PROFILE" ]; then
        # Add the local/ include
        LOCAL_APP_PROFILE="/etc/apparmor.d/local/nvidia_modprobe"

        test -e "$LOCAL_APP_PROFILE" || {
            mkdir -p `dirname "$LOCAL_APP_PROFILE"`
            install --mode 644 /dev/null "$LOCAL_APP_PROFILE"
        }

        # Reload the profile, including any abstraction updates
        if aa-enabled --quiet 2>/dev/null; then
            apparmor_parser -r -T -W "$APP_PROFILE" || true
        fi
    fi
fi
# End automatically added section
# Derived from scripts automatically added by dh_installinit/13.6ubuntu1
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
	if [ -f "/usr/lib/systemd/system/apparmor.service" ]; then
		systemctl enable --now apparmor || true
	fi
fi
# End automatically added section

# Now that AppArmor is installed, attempt to reload profiles in the
# case of upgrades.
aa_log_action_start() {
    echo "$@"
}
aa_log_action_end() {
    echo -n
}
aa_log_daemon_msg() {
    echo "$@"
}
aa_log_end_msg() {
    echo -n
}
aa_log_failure_msg() {
    echo "Error: $@"
}
aa_log_skipped_msg() {
    echo "Skipped: $@"
}
aa_log_warning_msg() {
    echo "Warning: $@"
}
case "$1" in
    configure)
        if aa-status --enabled 2>/dev/null; then
            parse_profiles reload || true
        fi
        ;;
esac

exit 0
