#!/bin/sh

set -e

case "$1" in
    upgrade)
	if dpkg --compare-versions "$2" lt 5.8.1+dfsg1-2; then
	    # Move the incorrectly placed AppArmor file
	    if [ -d /etc/apparmor.d/apache2.d/wordpress ]; then
		mv  /etc/apparmor.d/apache2.d/wordpress /etc/apparmor.d/apache2.d/wordpress.old
	        if [ -e /etc/apparmor.d/apache2.d/wordpress.old/wordpress.apparmor ]; then
		    mv /etc/apparmor.d/apache2.d/wordpress.old/wordpress.apparmor /etc/apparmor.d/apache2.d/wordpress.tmp
		fi
		# Try to remove the old directory but ignore if it fails
		rmdir /etc/apparmor.d/apache2.d/wordpress.old || true
	    fi
	fi
    ;;
esac

#DEBHELPER#
