#!/bin/sh
# preinst script for ubuntu-advantage-tools
#
# 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>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package

CACHE_DIR="/var/cache/ubuntu-advantage-tools"
CACHE_FILE="ubuntu-advantage-status.cache"

case "$1" in
    install)
    ;;
    upgrade)
        # CACHE_DIR is no longer present or used since 19.1
        # dpkg will take care of removing CACHE_DIR, as long
        # as it's empty
        if dpkg --compare-versions "$2" lt-nl "19.1~"; then
            if [ -f "$CACHE_DIR/$CACHE_FILE" ]; then
                rm -f $CACHE_DIR/$CACHE_FILE || true
            fi
        fi
    ;;

    abort-upgrade)
    ;;

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

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

#DEBHELPER#

exit 0
