#!/bin/sh
#
# checkinstall script for Cisco Network Registrar (nwreg2)
#
# Copyright (C) 2002-2007 by Cisco Systems, Inc.  This program contains
# proprietary and confidential information.  All rights reserved except as
# may be permitted by prior written consent.
#

# Most of the pkgadd environment is not available within this script.
# BASEDIR is one of the few exceptions.

# Verify proper operating system type 
OS=`uname -s`
if [ "$OS" != "SunOS" ] ; then
    # terminate the installation
    echo "Error: This package is for Solaris only."
    exit 1
fi

MISSING_PATCHES=0
pkginfo -q SUNWscpu
if [ $? -ne 0 ]; then
    MISSING_PATCHES=1
fi

pkginfo -q SUNWlibC
if [ $? -ne 0 ]; then
    MISSING_PATCHES=1
fi

if [ $MISSING_PATCHES -ne 0 ]; then
    fmt <<EOF 1>&2

$NAME $VERSION$PATCH cannot be installed on a system which does not contain the
following Solaris packages:  SUNWscpu and SUNWlibC.  Please install these
Solaris packages before attempting to install $NAME.
EOF
    exit 1
fi

#
# The following code attempts to detect versions of CNR prior to 3.5, as
# upgrade from versions prior to 3.5 is not supported.
#
UNSUPPORTED_VERSION=0
pkginfo -q AICnwreg
if [ $? -eq 0 ]; then
    UNSUPPORTED_VERSION=1
fi

pkginfo -q AICnwreg2
if [ $? -eq 0 ]; then
    UNSUPPORTED_VERSION=1
fi

pkginfo -q nwreg2
if [ $? -eq 0 ]; then
    OLD_VERSION=`pkgparam nwreg2 VERSION`
    MAJOR=`/usr/bin/expr "$OLD_VERSION" : '\([0-9]*\)'`
    MINOR=`/usr/bin/expr "$OLD_VERSION" : '[0-9]*\.\([0-9]*\)'`

    if [ $MAJOR -lt 6 ]; then
	UNSUPPORTED_VERSION=1
    fi
fi

if [ $UNSUPPORTED_VERSION -ne 0 ]; then
    fmt <<EOF 1>&2

$NAME $VERSION$PATCH cannot be installed on a system which contains a version
of $NAME older than 6.0.  The old version must be either be removed first, or
upgraded to version 6.0.  Please contact the Technical Assistance Center with
any questions.
EOF
    exit 1
fi

exit 0
