#!/bin/sh
set -e

case "$1" in
    install)
    ;;

	upgrade)
		# [2019.07.1-5] Handle the /usr/{lib -> share}/perl6/vendor transition
		# we purge the dir during preinst, and reinstall modules during postinst
		if dpkg --compare-versions $2 lt "2019.07.1-6"; then
			oldvendor=/usr/lib/perl6/vendor
			if test -f $oldvendor/version; then
				rm $oldvendor/version
			fi
			for LIST in $(ls /var/lib/perl6/modules/*.list); do
				for X in $(cat $LIST); do
					if test -f $oldvendor/$X; then
						rm -f $oldvendor/$X
					fi
				done
			done
			find $oldvendor -type d -empty -delete || true
			if test -d $oldvendor; then
				echo "Unexpected files found in $oldvendor!" \
				   "Please manually purge this directory."
			   find $oldvendor -print
			fi
		fi
	;;

    abort-upgrade)
    ;;

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

#DEBHELPER#

exit 0
