OpenSolaris_b135/pkgdefs/SUNWscmu/preinstall

#!/bin/sh
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

#
# Set path
#

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

#
# Set variables
#

BASEDIR=${BASEDIR:=/}
DATE=`date +%Y_%m_%d`
DSLOG="${PKG_INSTALL_ROOT}/var/adm/ds.log"
# fatal error
FAILURE=1
NAMEMAJOR="${PKG_INSTALL_ROOT}/etc/name_to_major"
NODELIST="/tmp/nodelist"
PKG_INSTALL_ROOT=${PKG_INSTALL_ROOT:=/}
# reverse dependency order
# Due to upgrade in product Release 3.0  remove any reference to sdsi
RMODULES="sdbc nsctl nskern "
TMP=/tmp/${PKGINST}.$$
DEVLINKTB="${PKG_INSTALL_ROOT}/etc/devlink.tab"

#
# Set alternate command syntax (if needed)
#

if [ "${PKG_INSTALL_ROOT}" = "/" ]; then
    REM_DRV="rem_drv"
else
    REM_DRV="rem_drv -b ${PKG_INSTALL_ROOT}"
fi

#
# Functions
#

message()
{
    echo ""
    echo "$@"
    echo ""
}

# Remove old backup directories left over from previous installations.
/usr/bin/rm -f ${PKG_INSTALL_ROOT}/var/spool/pkg/bkup.* > /dev/null 2>&1

#
# rem_devlink - remove entry from ${DEVLINKTB}
#

rem_devlink()
{
    PATTERN="$1"
    grep -vw $PATTERN ${DEVLINKTB} >${TMP}.devlink
    if [ $? -eq 0 ]; then
	mv ${TMP}.devlink ${DEVLINKTB}
    else
	rm ${TMP}.devlink
    fi
}

#
# remove modules
#

for MODULE in ${RMODULES}
do
  ERRLOG=/tmp/${MODULE}.prelog
  REMOVERR="ERROR: The removal cannot be completed due to an error removing \
the ${MODULE} loadable module.  The file ${ERRLOG} contains the errors. \
Exiting..."

  #
  # If module has been previously installed, remove it
  #

  if grep -w ${MODULE} ${NAMEMAJOR} >/dev/null; then
      ${REM_DRV} ${MODULE} > ${ERRLOG} 2>&1
      [ $? -ne 0 ] && {
	  message ${REMOVERR}
	  exit ${FAILURE}
      }
      /usr/bin/rm ${ERRLOG}
  fi
  rem_devlink ${MODULE}
done

#
# If upgrading, move old ds.log file so new one can just be current info
#

if [ -f $DSLOG ]
then
    mv $DSLOG $DSLOG.until.$DATE
fi