#! /bin/sh
# preinst script for crafty
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>

case "$1" in
    install|upgrade)
#Opening books have been moved to a more compliant place.
	#Get rid of empty dir
    if test \( $(ls /var/cache/crafty|wc -w) = '0' \)
		then rm -rf /var/cache/crafty	
    fi
    if [ -d /var/cache/crafty -a ! -d /var/lib/crafty ]
		then echo "Moving /var/cache/crafty to /var/lib/crafty"
		#We first copy the files, they'll be removed in postinst. This allows us to
		#unwind if install/upgrade fails or is aborted.
		mkdir -p /var/lib/crafty
		cp -R /var/cache/crafty/* /var/lib/crafty
    fi
    ;;

    abort-upgrade)

    if [ -d /var/cache/crafty -a -d /var/lib/crafty ]
		then rm -rf /var/lib/crafty
    fi
	;;

    *)
        echo "preinst called with unknown argument \`$1'" >&2
        exit 0
    ;;
esac

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

#DEBHELPER#

exit 0


