#!/bin/sh
#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident	"@(#)preinstall	1.1	07/03/02 SMI"
#
#       preinstall script for package: SUNWlucfg
#

# Exit codes for installation scripts
e_ok=0      
e_fatal=1      # stop installation on this exit
e_warning=2    # Installation will go on. 
e_int=3        # Interrupted. Stop installation
e_reboot=10    # User must reboot after installation of all selected packages
e_rebootnow=20 # User must reboot right after installation of current package
               # To be added to one of the single-digit exit code above

# Trap interrupt
trap `exit $e_int` 15

PATH=/usr/bin:{$PATH}
PRODREG=/usr/bin/prodreg
UNAME=/usr/bin/uname
ECHO=/usr/bin/echo

LU_SYSTEM_HWARCH="`${UNAME} -p`"
LU_SYSTEM_OSRELEASE="`${UNAME} -r`"
LU_SYSTEM_OSVERSION="`${UNAME} -sr`"
LU_MNEMONIC="com.sun.liveupgrade"

# On the i386 processor platform, live upgrade is not supported until Solaris 2.7.
# If running on the i386 platform, check for known releases prior to 2.7 that we know
# are not supported.

if [ "${LU_SYSTEM_HWARCH}" = "i386" ] ; then
  for sunosRelease in 5.0 5.1 5.2 5.3 5.4 5.5 5.5.1 5.6 ; do
    if [ "${sunosRelease}" = "${LU_SYSTEM_OSRELEASE}" ] ; then
      ${ECHO} "INFORMATION: You are running ${LU_SYSTEM_OSVERSION} on the ${LU_SYSTEM_HWARCH} hardware platform."
      ${ECHO} "FATAL ERROR: Live Upgrade is not supported on the ${LU_SYSTEM_HWARCH} platform prior to SunOS 5.7 (Solaris 7)."
      exit "${e_fatal}"
    fi
  done
fi

# If prodreg is available, unregister any old prodreg entries for Live Upgrade.
# Only need to unregister the top level LU_MNEMONIC entry - all subordinate
# entries will be automatically unregistered.

if [ -x "${PRODREG}" ] ; then
	LU_ID="`${PRODREG} list mnemonic mnemonic id | 
		grep -w \"${LU_MNEMONIC}\" | sort | head -1 | awk '{print $NF}'`"
	if [ -n "${LU_ID}" ] ; then
		# If the ID is "NULL" then use an empty string for the ID
		[ "${LU_ID}" = "NULL" ] && LU_ID=""
		${PRODREG} unregister "${LU_MNEMONIC}" "${LU_ID}"
	fi
fi

# Done - clean and exit.

exit "${e_ok}"

