#!/bin/sh
# postinst script for reboot-notifier
#
# see: dh_installdeb(1)

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 http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

case "$1" in
configure)
    case "`uname -r`" in
    4.1.0-cl-1-*)
        cat << \EOF > /etc/profile.d/cumulus-old-apt-motd.sh
#!/bin/sh
case "`uname -r`" in
4.1.0-cl-1-*)
    cat << . >&2
***********************************************************************
*** Upgraded from older release without APT::Get::Upgrade-Allow-New ***
***  if you didn't run dist-upgrade, some packages were held back   ***
***     re-run apt-get upgrade now that the setting is enabled      ***
***   rebooting after this has been done will clear this message    ***
***********************************************************************
.
    ;;
*)
    # we are running a newer release, remove ourselves if running as root
    [ "`id -u`" -ne 0 ] || rm /etc/profile.d/cumulus-old-apt-motd.sh
    ;;
esac
EOF
        chmod +x /etc/profile.d/cumulus-old-apt-motd.sh

        # execute the script now so that it shows up *somewhere* in apt output
        /etc/profile.d/cumulus-old-apt-motd.sh

        # output to /var/run/reboot-required so that there's a *chance* it's
        # displayed after apt completes its run (this is the only post-invoke
        # hook we definitely have in place when the upgrade starts)
        /etc/profile.d/cumulus-old-apt-motd.sh 2>/var/run/reboot-required
        ;;
    esac # uname -r
    ;;

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
