#!/bin/sh
# postinst script for openmpi
#
# 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)
        . /etc/profile.d/xcat.sh
        if [ -f /tmp/xCAT-server_upgrade.tmp ]; then
          if [ -x /lib/systemd/systemd ]; then
            if [ -f /run/systemd/generator.late/xcatd.service ]; then
                # To cover the case upgrade from no xcatd systemd unit file (cannot enable by default for HA case)
                ls /etc/rc?.d/S??xcatd >/dev/null 2>&1
                if [ "$?" = "0" ]; then
                   [ -x /usr/sbin/update-rc.d ] && /usr/sbin/update-rc.d xcatd remove
                   /bin/systemctl daemon-reload
                   /bin/systemctl enable xcatd.service
                fi
            else
                /bin/systemctl daemon-reload
            fi
          fi
          # No need to reload xcatd here as it will be covered by xCAT/xCATsn now
          rm /tmp/xCAT-server_upgrade.tmp
        else
          if [ -x /lib/systemd/systemd ]; then
            /bin/systemctl daemon-reload
            /bin/systemctl enable xcatd.service
          else
            update-rc.d xcatd defaults
          fi
        fi
        ln -sf /opt/xcat/sbin/xcatd /usr/sbin/xcatd
    ;;

    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
