#!/bin/bash
set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package> <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <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/rtc-juggler-bundle/pythonic"
BUNDLE_BIN="${BUNDLE_PATH}/bundle"

case "$1" in
    configure)

    # create hardlinks for new checks
    for check in `"${BUNDLE_BIN}" --list-checks`; do
        ln -f "${BUNDLE_BIN}" "${BUNDLE_PATH}/${check}"
    done

    # remove checks from old bundle (absent in new bundle) and transitional file
    test -f "${BUNDLE_BIN}.transitional" && \
        find "${BUNDLE_PATH}" -samefile  "${BUNDLE_BIN}.transitional" -delete
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

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