OpenSolaris_b135/pkgdefs/SUNWmdr/postinstall.tmpl

#!/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 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#pragma ident	"%Z%%M%	%I%	%E% SMI"
#

PATH=/usr/sadm/bin:/usr/bin:/usr/sbin
MD_CONF=${PKG_INSTALL_ROOT:-/}/kernel/drv/md.conf
SYSTEM_FILE=${PKG_INSTALL_ROOT:-/}/etc/system
inetconf_pre=${PKG_INSTALL_ROOT:-/}/etc/inet/inetd.conf.preupgrade
inetsed=/tmp/inetd.sed.$$
inettmp=/tmp/inetd.tmp.$$

#
# fix_drv_migrate (mntpath)
# If root is mirrored and the driver name changes 
# across upgrade, then we need to update the system file
# with the forceloads for the new underlying drivers
#

fix_drv_migrate() {
	grep "^md_drv_migrate" /kernel/drv/md.conf || return

	# check if we have a mirrored root.
	rootdev=`cat $1/etc/vfstab | nawk '/^#/ { next; }
						{ if ( $3 == "/" )
							print $1
						}'`
	md_dir=`dirname $rootdev`
	if [ "$md_dir" = "/dev/md/dsk" ]; then
		/usr/sbin/metaroot -v $1/etc/vfstab -k $1/etc/system $rootdev
	fi
}

# add_devid_destroy(filename)
# returns contents in filename
# md_devid_destroy property is required when upgrading
# from pre SVM to SVM releases.
# It is specifically placed between 
# # Begin MDD database info and # End MDD database info because 
# on the subsequent reboot, this line will be removed automatically when
# metadevadm is run in rc2.d.
#

add_devid_destroy() {
	sed '/^# End MDD database/i\
md_devid_destroy=1;' $1 >>/tmp/t$$
	mv /tmp/t$$ $1
}


# fix_mdconf fixes/updates the md.conf and mddb.cf on the target disk.
# The ugly script below does the following:
# 1. For pre SLVM the mddb_bootlist is transformed from the
#    format used in /etc/system to the driver config file format 
#    and then :id0 is appended for device ID support. 
# 2. For SLVM phase 1 only :id0 is appended to the bootlist.
#
# pre SLVM format in /etc/system
# * set md:mddb_bootlist1="sd:215:16 sd:310:15"
#
# SLVM phase 1 format in /kernel/drv/md.conf
# mddb_bootlist1="sd:215:16 sd:310:15";
#
# New format in /kernel/drv/md.conf
# mddb_bootlist1="sd:215:16:id0 sd:310:15:id0";
#
# MINIROOT:
# If on the miniroot, the md.conf on the target disk is updated
# with mddb_bootlist from md.conf from the miniroot and the mddb.cf is
# copied from the miniroot too.
# NONMINIROOT: 
# On non miniroot the md.conf is updated as follows:
# if /etc/system has the mddb_bootlist, convert it to the new format.
# if md.conf has the mddb_boolist append :id0 to it.

fix_mdconf() {
	#if we are in the miniroot copy mddb.cf and mddb_bootlist from
	#/kernel/drv/md.conf 
	if [ "${BASEDIR}" != "/" -a -d /.tmp_proto -a \
		-h /etc/transfer_list ] ; then
		cp /etc/lvm/mddb.cf ${BASEDIR}/etc/lvm/mddb.cf

		# delete all the lines for mddb_bootlist 
		cat ${MD_CONF} | sed -e '/^# Begin/,/^# End/d' > \
							/tmp/md.conf.$$
        	echo "" >> /tmp/md.conf.$$
        	echo "# Begin MDD database info (do not edit)" >> \
							/tmp/md.conf.$$
		grep mddb_bootlist /kernel/drv/md.conf >> /tmp/md.conf.$$
        	echo "# End MDD database info (do not edit)" >> /tmp/md.conf.$$

		# cmdk->sd migration. Need to reset the forceloaded drivers in 
		# /etc/system.

		fix_drv_migrate $PKG_INSTALL_ROOT		
	else
		#if we are not in the miniroot, then we have 2 cases
		# 1. Pre-SLVM ie. mddb_bootlist is in /etc/system
		# 2. SLVM phase 1. where mddb_bootlist is in md.conf
		#    not in devid format.

		if [ "$RELEASE" != "SLVM" ]; then
			cp ${MD_CONF} /tmp/md.conf.$$
        		echo "# Begin MDD database info (do not edit)" >> \
								/tmp/md.conf.$$	
  			sed -e 's/^set md://' -e 's/$/;/' ${SYSTEM_FILE}\
				| grep mddb_bootlist | \
				sed -e \
				'/^mddb_bootlist/s/\([a-zA-Z0-9]\{1,\}:[0-9]\{1,\}:[0-9]\{1,\}\)"/\1:id0"/g' \
				-e \
				'/^mddb_bootlist/s/\([a-zA-Z0-9]\{1,\}:[0-9]\{1,\}:[0-9]\{1,\}\) /\1:id0 /g' \
			>> /tmp/md.conf.$$
       			echo "# End MDD database info (do not edit)" >> /tmp/md.conf.$$

		else
			sed -e \
			'/^mddb_bootlist/s/\([a-zA-Z0-9]\{1,\}:[0-9]\{1,\}:[0-9]\{1,\}\)"/\1:id0"/g' \
			-e \
			'/^mddb_bootlist/s/\([a-zA-Z0-9]\{1,\}:[0-9]\{1,\}:[0-9]\{1,\}\) /\1:id0 /g' \
			< ${MD_CONF} > /tmp/md.conf.$$
		fi

		add_devid_destroy /tmp/md.conf.$$

	fi
	cp /tmp/md.conf.$$ ${MD_CONF} || echo "copy error: /tmp/md.conf.$$ to ${MD_CONF}"
}

delete_system_bootlist() {
        cat ${SYSTEM_FILE} | sed -e /"Begin MDD database info"/,/"End MDD database info"/d > /tmp/system.$$
        cp /tmp/system.$$ ${SYSTEM_FILE} || echo "copy error: /tmp/system.$$ to ${SYSTEM_FILE}"
}

inetd_fini() {
	cmp -s $inetconf_pre $inettmp
	case $? in
	0)	;;
	1)	cat $inettmp > $inetconf_pre
		if [ $? -ne 0 ]; then
			echo "couldn't edit $inetconf_pre"
			return 1
		fi
		;;

	*)	echo "couldn't read $inetconf_pre or $inettmp"
		return 1
		;;
	esac

	rm -f -- $inetsed $inettmp
	return 0
}

inetd_remove() {
	#
	# Remove any svm additions from /etc/inet/inetd.conf.preupgrade
	#
	sed -e 's:/:\\/:g' -e 's:.*:/&/ d:' > $inetsed
	if [ $? -ne 0 ]; then
		echo "couldn't create $inetsed"
		return 1
	fi
	sed -f $inetsed < $inetconf_pre > $inettmp
	if [ $? -ne 0 ]; then
		echo "couldn't create $inettmp"
		return 1
	fi

	return 0
}

#
# Perform an upgrade
#
if [ "$IS_AN_UPGRADE" = "true" ]; then
# if previous release was not SLVM or md.conf did not have devids fix it.
	sed -e 's/#.*$//' ${MD_CONF} | egrep '^[ 	]*mddb_bootlist.*:id' >/dev/null 2>&1
	DEVID_STATUS=$?
	if [ "$RELEASE" != "SLVM" -o $DEVID_STATUS -eq 1 ]; then
		fix_mdconf
		delete_system_bootlist
	fi
fi

#
# Work with the SMF.  The SVM services are in the SMF seed and enabled by
# default.  If SVM mddbs are not configured then we should disable the SVM
# services.
#

# if we are in the miniroot check for mddbs in /kernel/drv/md.conf 
if [ "${BASEDIR}" != "/" -a -d /.tmp_proto -a -h /etc/transfer_list ] ; then
	SMF_MD_CONF=/kernel/drv/md.conf
else
	SMF_MD_CONF=${MD_CONF}
fi

sed -e 's/#.*$//' ${SMF_MD_CONF} | egrep '^[ 	]*mddb_bootlist' >/dev/null 2>&1
MDDB_STATUS=$?

if [ $MDDB_STATUS -eq 0 ]; then
	echo "/usr/sbin/svcadm enable system/mdmonitor:default" >> \
		$BASEDIR/var/svc/profile/upgrade

else
	echo "/usr/sbin/svcadm disable system/metainit:default" >> \
		$BASEDIR/var/svc/profile/upgrade
	echo "/usr/sbin/svcadm disable system/metasync:default" >> \
		$BASEDIR/var/svc/profile/upgrade

	for svc in meta mdcomm metamed metamh; do
		echo "/usr/sbin/svcadm disable network/rpc/$svc:default" >> \
		    $BASEDIR/var/svc/profile/upgrade
	done

	# Remove entries in inetd.conf.preupgrade for SLVM daemons
	if [ "$IS_AN_UPGRADE" = "true" -a -f ${inetconf_pre} ]; then
		inetd_remove rpc.metad rpc.metamhd rpc.metamedd <<EOF
^[#	 ]*100229/1
^[#	 ]*100230/1
^[#	 ]*100242/1
^# METAD
^# METAMHD
^# METAMEDD
^# SLVM Daemons
EOF
		inetd_fini
	fi
fi