#!/bin/sh

# Copyright (c) 2010-2013, by Broadcom, Inc.
# All Rights Reserved.

PATH="${PKG_INSTALL_ROOT}/usr/bin:${PKG_INSTALL_ROOT}/usr/sbin:${PATH}"
export PATH 

abort_install()
{
    echo ""
    echo "----------------------------------------"
    echo "| ERROR: $1"
    echo "| Aborting installation!"
    echo "----------------------------------------"
    echo ""
    exit 1
}

# The ARCH environment variable is set appropriately when the package
# is created and made available for the installation scripts (pkginfo(4)).
if [ `uname -p` != "$ARCH" ]; then
    abort_install "Package was not built for this system architecture."
fi

# The OSREL environment variable is set appropriately when the package
# is created and made available for the installation scripts (pkginfo(4)).
if [ `uname -r` != "$OSREL" ]; then
    abort_install "Package was not built for this Solaris release."
fi

PKG_FLAGS=""
if [ "${PKG_INSTALL_ROOT}" != "" -a "${PKG_INSTALL_ROOT}" != "/" ]; then
    PKG_FLAGS="-R ${PKG_INSTALL_ROOT}"
fi

# With Solaris 11 make sure the SUNWbge package has been removed. For
# Solaris 10 the bge driver is part of the SUNWcakr package which cannot
# be removed. Instead the preinstall/postremove scripts handle the conflict.

if [ `uname -r` = "5.11" ]; then
    pkginfo ${PKG_FLAGS} SUNWbge > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        abort_install "The SUNWbge package is installed (remove with pkgrm)."
    fi
fi

pkginfo ${PKG_FLAGS} BRCMbge > /dev/null 2>&1
if [ $? -eq 0 ]; then
    abort_install "The BRCMbge package is installed (remove with pkgrm)."
fi

exit 0

