#!/bin/sh
set -e

# Movement of /var/lib/games to /var/games as per policy...
# (dpkg should give a warning to users the first time...)
# Movement should only be made when  updating from <-8 to =>-8
if [ -d /var/lib/games/spellcast ]; then
	if [ ! -d /var/games/spellcast ] ; then
		mkdir /var/games/spellcast
	fi
	# Are there any files here?
	if [ ! -z "`ls /var/lib/games/spellcast/*`" ] ; then
		mv /var/lib/games/spellcast/* /var/games/spellcast 
	fi
	rmdir /var/lib/games/spellcast
	chown -R games:games /var/games/spellcast
	chmod 0755 /var/games/spellcast
fi

# Set the games logfile directory permissions
if [ "$1" = "configure" ]; then
    # Ensure the directory exists
    mkdir -p /var/games/spellcast

    # Apply the permissions correctly on the live system
    if ! dpkg-statoverride --list /var/games/spellcast >/dev/null 2>&1; then
        dpkg-statoverride --update --add root games 2775 /var/games/spellcast
    fi
fi


#DEBHELPER#

exit 0
