#!/bin/sh -e

action="$1"
oldversion="$2"

. /usr/share/debconf/confmodule
db_version 2.0

umask 022

if [ "$action" != configure ] ; then
	exit 0
fi

# functions

setup_aprx_user() {
        if ! getent passwd aprsc >/dev/null; then
        	echo "Creating user account: 'aprsc'"
                adduser --quiet --system --no-create-home --home /var/run/aprx --shell /usr/sbin/nologin --group aprx
        fi
}

fix_permissions() {
        :
	# chown aprx:aprx /opt/aprsc/logs /opt/aprsc/data
}

apparmor_config() {
	# Reload AppArmor profile
	APP_PROFILE="/etc/apparmor.d/sbin.aprx"
	if [ -f "$APP_PROFILE" ] && aa-status --enabled 2>/dev/null; then
		echo "Installing apparmor profile..."
		apparmor_parser -r -T -W "$APP_PROFILE" || true
	fi
}

# main

# setup_aprx_user
# fix_permissions
apparmor_config

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
