#!/bin/bash
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
#
# This script is run by rpm after all rpms stages are complete.
#
# It does the setup for the core sgd after an install or an upgrade.
# Usage: posttrans
#

if [ -z "${STATE_PATH}" -o -z "${INSTDIR}" ]
then
    echo "Missing STATE_PATH='${STATE_PATH}' or INSTDIR='${INSTDIR}'" 1>&2
    exit 1
fi

TTAINSTDIR=${INSTDIR}
# Set the upgrade state
. ${TTAINSTDIR}/bin/scripts/upgrade

# If upgrade-state-init file exists then new install else an upgrade
if [ -f "${STATE_PATH}/upgrade-state-init" ]
then
    # Initial install
    sgd_upgrade_state_init          # Set upgrade state to HOT
    rm -f "${STATE_PATH}/upgrade-state-init"
else
    # Upgrade
    sgd_upgrade_state_set COLD      # Set to COLD
fi
