postremove revision 6029a2d88c01674debfd7c2e16c941a97302b739
#!/sbin/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.
#
# ident "%Z%%M% %I% %E% SMI"
#
# Function : deletemegasastargets
# This function is responsible for cleaning up the
# mega_sas related lines from
# ${BASEDIR}/kernel/drv/sd.conf file.
deletemegasastargets()
{
SDCONF=${BASEDIR}/kernel/drv/sd.conf
HEADER="# MEGA AUTOGENERATED CONFIGURATION : START (DO NOT DELETE/ALTER THIS LINE)"
FOOTER="# MEGA AUTOGENERATED CONFIGURATION : END (DO NOT DELETE/ALTER THIS LINE)"
HEADER2="# WARNING : LINES ADDED WITHIN THIS MEGA CONF SECTION"
HEADER3="# WOULD GET DELETED WHEN THE MEGA_SAS DRIVER PACKAGE IS REMOVED"
LINEENDPATTERN="parent=\"mega_sas\""
GREP=/usr/bin/grep
NAWK=/usr/bin/nawk
RM=/usr/bin/rm
MV=/usr/bin/mv
CP=/usr/bin/cp
# Check if $SDCONF file exists
if [ ! -f $SDCONF ]
then
echo "ERROR : $SDCONF File does not exist"
exit 0
fi
$RM /tmp/$$.conf >/dev/null 2>&1
$GREP -w "$HEADER" $SDCONF >/dev/null 2>&1
slstatus=$?
$GREP -w "$FOOTER" $SDCONF >/dev/null 2>&1
elstatus=$?
$GREP -w "$LINEENDPATTERN" $SDCONF > /dev/null 2>&1
lestatus=$?
# If no startline, endline and no lines that
# match LINEENDPATTERN, return
# If only start or endline or LINEENDPATTERN is
# missing then its corrupted. That time we remove
# all lines which have parent="mega_sas", along with
# start and end lines. The commented lines
# that appear after the start line should also
# be removed
if [ $slstatus -ne 0 -a $elstatus -ne 0 -a $lestatus -ne 0 ]
then
echo "mega_sas related lines in $SDCONF file not found"
return 0
elif [ $slstatus -ne 0 -o $elstatus -ne 0 -o $lestatus -ne 0 ]
then
# Shouldn't come to this section
# In case user corrupts $SDCONF, do a dirty remove
echo "$SDCONF file seems to be corrupted"
echo "Removing lines in $SDCONF relevant to mega_sas"
cat $SDCONF | $GREP -v "$LINEENDPATTERN" | $GREP -v "$HEADER" \
| $GREP -v "$FOOTER" | $GREP -v "$HEADER2" \
| $GREP -v "$HEADER3" >> /tmp/$$.conf
if [ $? -eq 0 ]
then
$CP /tmp/$$.conf $SDCONF
$RM -f /tmp/$$.conf >/dev/null 2>&1
else
echo "ERROR while removing mega_sas related lines from $SDCONF"
exit 0
fi
return 0
fi
# Remove the MEGA section from $SDCONF
$NAWK -v start=0 '{
if ($0 ~ /# MEGA AUTOGENERATED CONFIGURATION : START/) {
start=1;
}
if ( start == 0 ) {
print $0;
}
if ($0 ~ /# MEGA AUTOGENERATED CONFIGURATION : END/) {
start=0;
}
}' $SDCONF >> /tmp/$$.conf
if [ $? -ne 0 ]
then
echo "ERROR : while removing mega_sas related section"
echo " from $SDCONF file."
$RM -f /tmp/$$.conf
exit 0
fi
$CP /tmp/$$.conf $SDCONF
$RM -f /tmp/$$.conf >/dev/null 2>&1
}
BD=${BASEDIR:-/}
if grep "\<mega_sas\>" $BD/etc/name_to_major > /dev/null 2>&1
then
rem_drv -b ${BD} mega_sas
fi
deletemegasastargets