#!/bin/bash
set -e

# summary of how this script can be called:
#        * <prerm> `remove'
#        * <old-prerm> `upgrade' <new version>
#        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
#        * <deconfigured's-prerm> `deconfigure' `in-favour' <package-being-installed> <version>
#          [`removing' <conflicting-package> <version>]
#        * <new-prerm> `failed-upgrade' <old-version>
# for details, see https://www.debian.org/doc/debian-policy/#summary-of-ways-maintainer-scripts-are-called
# or the debian-policy package

BUNDLE_PATH="/var/lib/rtc/juggler.d/cauth-juggler-bundle/pythonic"
BUNDLE_BIN="${BUNDLE_PATH}/bundle"

case "$1" in
    remove|deconfigure)

    # remove hardlinked checks, but keep original bundle binary to not to
    # confuse dpkg by it absence
    find "${BUNDLE_PATH}" -samefile "${BUNDLE_BIN}" -a -not -path "${BUNDLE_BIN}" -delete
    ;;

    upgrade)

    # make hardlink of old bin to keep track of disappearing checks in new
    # bundle, will be removed in postinst/configure
    ln -f "${BUNDLE_BIN}" "${BUNDLE_BIN}.transitional"
    ;;

    failed-upgrade)
    ;;

    *)
        echo "prerm 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
