#!/bin/sh

set -e

apparmor_profile='/etc/apparmor.d/mullvad-browser'

case "$1" in
    install|upgrade|configure)
        # If abi 4.0 is not present, then remove the apparmor profile config
        if [ ! -e /etc/apparmor.d/abi/4.0 ]; then
            rm -f "$apparmor_profile"
        fi
        ;;
esac

if [ "$1" = "configure" ]; then
  if [ -f "$apparmor_profile" ]; then
    # Reload the profile, including any abstraction updates
    if aa-enabled --quiet 2>/dev/null; then
      apparmor_parser -r -T -W "$apparmor_profile" || true
    fi
  fi
fi
