xref: /titanic_51/usr/src/cmd/svc/milestone/manifest-import (revision 293e3ab30a546cd932ee22f9d54b3979fcb52095)
123294c7dSSean Wilcox#!/bin/ksh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6d62bc4baSyz147064# Common Development and Distribution License (the "License").
7d62bc4baSyz147064# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
22adfc3118STruong Nguyen# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate#
247c478bd9Sstevel@tonic-gate
2570cbfe41SPhilippe Jung# 0a  Initialization.
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate[ -f /lib/svc/share/smf_include.sh ] || exit 1
287c478bd9Sstevel@tonic-gate
29c0889d7aSstevep. /lib/svc/share/smf_include.sh
30c0889d7aSstevep
317c478bd9Sstevel@tonic-gateactivity=false
327c478bd9Sstevel@tonic-gate
339444c26fSTom WhittenEMI_SERVICE="svc:/system/early-manifest-import:default"
34adfc3118STruong NguyenPROFILE_DIR_SITE="/etc/svc/profile/site"
359444c26fSTom Whitten
367c478bd9Sstevel@tonic-gateX=
37*293e3ab3STruong Q. NguyenALT_REPOSITORY=
38*293e3ab3STruong Q. NguyenALT_MFST_DIR=
399444c26fSTom Whittenearly=false
409444c26fSTom Whitten[ "$SMF_FMRI" == "$EMI_SERVICE" ] && early=true
41*293e3ab3STruong Q. Nguyen
42*293e3ab3STruong Q. Nguyenusage()
43*293e3ab3STruong Q. Nguyen{
44*293e3ab3STruong Q. Nguyen	echo "Usage: /lib/svc/method/manifest-import [-n]" \
45*293e3ab3STruong Q. Nguyen	    "[-f repository-file -d manifest-directory]"
46*293e3ab3STruong Q. Nguyen	echo "\nOptions:"
47*293e3ab3STruong Q. Nguyen	echo "-n dryrun"
48*293e3ab3STruong Q. Nguyen	echo "-f and -d specify alternate repository and" \
49*293e3ab3STruong Q. Nguyen	    "manifest directory for import\n"
50*293e3ab3STruong Q. Nguyen	exit 2
51*293e3ab3STruong Q. Nguyen}
52*293e3ab3STruong Q. Nguyen
53*293e3ab3STruong Q. Nguyenwhile getopts "nd:f:" opt; do
547c478bd9Sstevel@tonic-gate	case $opt in
557c478bd9Sstevel@tonic-gate		n)	X=echo;;
56*293e3ab3STruong Q. Nguyen		d)	ALT_MFST_DIR=$OPTARG;;
57*293e3ab3STruong Q. Nguyen		f)	ALT_REPOSITORY=$OPTARG;;
58*293e3ab3STruong Q. Nguyen		?)	usage;;
597c478bd9Sstevel@tonic-gate	esac
607c478bd9Sstevel@tonic-gatedone
617c478bd9Sstevel@tonic-gate
62*293e3ab3STruong Q. Nguyen#
63*293e3ab3STruong Q. Nguyen# Both -f and -d options must be specified together or not specified at all
64*293e3ab3STruong Q. Nguyen#
65*293e3ab3STruong Q. Nguyen[ -n "$ALT_REPOSITORY" -a -z "$ALT_MFST_DIR" ] && usage
66*293e3ab3STruong Q. Nguyen[ -n "$ALT_MFST_DIR" -a -z "$ALT_REPOSITORY" ] && usage
67*293e3ab3STruong Q. Nguyen
6823294c7dSSean Wilcoxfunction svccfg_apply {
697c478bd9Sstevel@tonic-gate	$X /usr/sbin/svccfg apply $1
707c478bd9Sstevel@tonic-gate	if [ $? -ne 0 ]; then
717c478bd9Sstevel@tonic-gate		echo "WARNING: svccfg apply $1 failed" | tee /dev/msglog
727c478bd9Sstevel@tonic-gate	fi
737c478bd9Sstevel@tonic-gate}
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate#
769444c26fSTom Whitten# If the smf/manifest table has file entries that are missing
779444c26fSTom Whitten# then there is work to be done by the cleanup process.
787c478bd9Sstevel@tonic-gate#
799444c26fSTom Whittenfunction cleanup_needwork {
809444c26fSTom Whitten	if [ "$early" == true ]; then
819444c26fSTom Whitten		smfmfiles=`/usr/bin/svcprop smf/manifest | \
82adfc3118STruong Nguyen		    awk '(/^lib_/ && /\/manifestfile /) {print $3}'`
837c478bd9Sstevel@tonic-gate	else
849444c26fSTom Whitten		smfmfiles=`/usr/bin/svcprop smf/manifest | \
859444c26fSTom Whitten		    awk '/\/manifestfile / {print $3}'`
867c478bd9Sstevel@tonic-gate	fi
877c478bd9Sstevel@tonic-gate
889444c26fSTom Whitten	nw=`/lib/svc/bin/mfstscan $smfmfiles 2>&1 1>/dev/null`
899444c26fSTom Whitten	[ "$nw" ] && return 1
907c478bd9Sstevel@tonic-gate
919444c26fSTom Whitten	return 0
927c478bd9Sstevel@tonic-gate}
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate#
959444c26fSTom Whitten# Upon upgrading to early manifest import code, preserve hashes of system
969444c26fSTom Whitten# profiles which lived under /var/svc/profile so that svccfg apply would
979444c26fSTom Whitten# not re-apply the profiles and overwrite user customizations. Simply
989444c26fSTom Whitten# migrate manifestfile and hash values to new property groups named after
999444c26fSTom Whitten# profiles under /etc/svc/profile. If the profiles don't really exist,
1009444c26fSTom Whitten# svccfg cleanup will remove the property groups in a later step.
1017c478bd9Sstevel@tonic-gate#
1029444c26fSTom Whitten# Existing generic.xml, inetd_services.xml, and name_service.xml symlinks
1039444c26fSTom Whitten# need to be preserved.
1047c478bd9Sstevel@tonic-gate#
1059444c26fSTom Whitten# Don't process site.xml profile since it is still supported under
1069444c26fSTom Whitten# /var/svc/profile directory.
1077c478bd9Sstevel@tonic-gate#
1089444c26fSTom Whittenfunction preserve_system_profiles {
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate	#
1119444c26fSTom Whitten	# If /var is a separate fs, return and let Late Import
1129444c26fSTom Whitten	# preserves the hashes.
1137c478bd9Sstevel@tonic-gate	#
1149444c26fSTom Whitten	[ -d "/var/svc/profile" ] || return 1
1157c478bd9Sstevel@tonic-gate
1169444c26fSTom Whitten	#
1179444c26fSTom Whitten	# Preserve hashes for the following profiles: generic (two
1189444c26fSTom Whitten	# cases) and platform (uname -i, uname -m outputs).
1199444c26fSTom Whitten	#
1207c478bd9Sstevel@tonic-gate	gn="var_svc_profile_generic_open_xml"
1217c478bd9Sstevel@tonic-gate	gh=`/usr/bin/svcprop -p ${gn}/md5sum smf/manifest 2>/dev/null`
1227c478bd9Sstevel@tonic-gate	[ $? = 0 ] || gh=""
1239444c26fSTom Whitten	gn="etc_svc_profile_generic_open_xml"
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate	gln="var_svc_profile_generic_limited_net_xml"
1267c478bd9Sstevel@tonic-gate	glh=`/usr/bin/svcprop -p ${gln}/md5sum smf/manifest 2>/dev/null`
1277c478bd9Sstevel@tonic-gate	[ $? = 0 ] || glh=""
1289444c26fSTom Whitten	gln="etc_svc_profile_generic_limited_net_xml"
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate	LC_ALL=C pl=`/usr/bin/uname -i | /usr/bin/tr , _`
1317c478bd9Sstevel@tonic-gate	pln="var_svc_profile_platform_${pl}_xml"
1327c478bd9Sstevel@tonic-gate	plh=`/usr/bin/svcprop -p ${pln}/md5sum smf/manifest 2>/dev/null`
1337c478bd9Sstevel@tonic-gate	[ $? = 0 ] || plh=""
1349444c26fSTom Whitten	pln="etc_svc_profile_platform_${pl}_xml"
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate	LC_ALL=C plm=`/usr/bin/uname -m | /usr/bin/tr , _`
1377c478bd9Sstevel@tonic-gate	if [ $plm != $pl ]; then
1387c478bd9Sstevel@tonic-gate		plmn="var_svc_profile_platform_${plm}_xml"
1397c478bd9Sstevel@tonic-gate		plmh=`/usr/bin/svcprop -p ${plmn}/md5sum smf/manifest \
1407c478bd9Sstevel@tonic-gate		    2>/dev/null`
1417c478bd9Sstevel@tonic-gate		[ $? = 0 ] || plmh=""
1429444c26fSTom Whitten		plmn="etc_svc_profile_platform_${plm}_xml"
1437c478bd9Sstevel@tonic-gate	else
1447c478bd9Sstevel@tonic-gate		plmh=""
1457c478bd9Sstevel@tonic-gate	fi
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate	[ -n "$gh" ] && {
1487c478bd9Sstevel@tonic-gate		echo "Preserving generic hash ($gh)."
1497c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest addpg ${gn} framework
1507c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest setprop ${gn}/md5sum = \
1517c478bd9Sstevel@tonic-gate		    opaque: $gh
1529444c26fSTom Whitten		/usr/sbin/svccfg -s smf/manifest setprop ${gn}/manifestfile = \
1539444c26fSTom Whitten		    astring: "/etc/svc/profile/generic.xml"
1547c478bd9Sstevel@tonic-gate	}
1557c478bd9Sstevel@tonic-gate	[ -n "$glh" ] && {
1567c478bd9Sstevel@tonic-gate		echo "Preserving generic_limited hash ($glh)."
1577c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest addpg ${gln} framework
1587c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest setprop ${gln}/md5sum = \
1597c478bd9Sstevel@tonic-gate		    opaque: $glh
1609444c26fSTom Whitten		/usr/sbin/svccfg -s smf/manifest setprop ${gln}/manifestfile = \
1619444c26fSTom Whitten		    astring: "/etc/svc/profile/generic.xml"
1627c478bd9Sstevel@tonic-gate	}
1637c478bd9Sstevel@tonic-gate	[ -n "$plh" ] && {
1647c478bd9Sstevel@tonic-gate		echo "Preserving platform hash ($plh)."
1657c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest addpg $pln framework
1667c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest setprop $pln/md5sum = \
1677c478bd9Sstevel@tonic-gate		    opaque: $plh
1689444c26fSTom Whitten		/usr/sbin/svccfg -s smf/manifest setprop ${pln}/manifestfile = \
1699444c26fSTom Whitten		    astring: "/etc/svc/profile/platform_${pl}_xml"
1707c478bd9Sstevel@tonic-gate	}
1717c478bd9Sstevel@tonic-gate	[ -n "$plmh" ] && {
1727c478bd9Sstevel@tonic-gate		echo "Preserving platform hash ($plmh)."
1737c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest addpg $plmn framework
1747c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest setprop $plmn/md5sum = \
1757c478bd9Sstevel@tonic-gate		    opaque: $plmh
1769444c26fSTom Whitten		/usr/sbin/svccfg -s smf/manifest setprop \
1779444c26fSTom Whitten		    ${plmn}/manifestfile = \
1789444c26fSTom Whitten		    astring: "/etc/svc/profile/platform_${plm}_xml"
1797c478bd9Sstevel@tonic-gate	}
1809444c26fSTom Whitten
1819444c26fSTom Whitten	#
1829444c26fSTom Whitten	# Move symlinks from /var/svc/profile to /etc/svc/profile
1839444c26fSTom Whitten	#
1849444c26fSTom Whitten	generic_prof="/var/svc/profile/generic.xml"
1859444c26fSTom Whitten	ns_prof="/var/svc/profile/name_service.xml"
1869444c26fSTom Whitten	inetd_prof="/var/svc/profile/inetd_services.xml"
187adfc3118STruong Nguyen	platform_prof="/var/svc/profile/platform.xml"
1889444c26fSTom Whitten	[ -L "$generic_prof" ] && mv $generic_prof /etc/svc/profile/
1899444c26fSTom Whitten	[ -L "$ns_prof" ] && mv $ns_prof /etc/svc/profile/
1909444c26fSTom Whitten	[ -L "$inetd_prof" ] && mv $inetd_prof /etc/svc/profile/
191adfc3118STruong Nguyen	[ -L "$platform_prof" ] && mv $platform_prof /etc/svc/profile/
1929444c26fSTom Whitten
1939444c26fSTom Whitten	return 0
1947c478bd9Sstevel@tonic-gate}
1959444c26fSTom Whitten
1969444c26fSTom Whitten#
1979444c26fSTom Whitten# 2.  Manifest import.  Application directories first, then
1989444c26fSTom Whitten# site-specific manifests.
1999444c26fSTom Whitten#
2009444c26fSTom Whittenfunction import_manifests {
2019444c26fSTom Whitten	typeset basedir=$1
202*293e3ab3STruong Q. Nguyen	typeset console_print=$2
2039444c26fSTom Whitten	typeset logf="/etc/svc/volatile/manifest_import.$$"
2049444c26fSTom Whitten
2059444c26fSTom Whitten	rm -f $logf
2069444c26fSTom Whitten
207*293e3ab3STruong Q. Nguyen	nonsite_dirs=`/usr/bin/find $basedir/* -name site \
2089444c26fSTom Whitten	    -prune -o -type d -print -prune`
2099444c26fSTom Whitten
2109444c26fSTom Whitten	if [ -n "$_MFST_DEBUG" ]; then
2119444c26fSTom Whitten		nonsite_manifests=`/lib/svc/bin/mfstscan $nonsite_dirs`
212*293e3ab3STruong Q. Nguyen		site_manifests=`/lib/svc/bin/mfstscan $basedir/site`
2139444c26fSTom Whitten
2149444c26fSTom Whitten		manifests="$nonsite_manifests $site_manifests"
2159444c26fSTom Whitten
2169444c26fSTom Whitten		echo "Changed manifests to import:"
2179444c26fSTom Whitten		for m in $manifests; do echo "  $m"; done
2189444c26fSTom Whitten	fi
2199444c26fSTom Whitten
2209444c26fSTom Whitten	#
221*293e3ab3STruong Q. Nguyen	# Upon boot, attempt to move the repository to tmpfs.
2229444c26fSTom Whitten	#
223*293e3ab3STruong Q. Nguyen	if [ -z "$ALT_REPOSITORY" -a -z "$ALT_MFST_DIR" ]; then
2249444c26fSTom Whitten		/usr/sbin/svcadm _smf_repository_switch fast
225*293e3ab3STruong Q. Nguyen	fi
2269444c26fSTom Whitten
2279444c26fSTom Whitten	#
2289444c26fSTom Whitten	# Import the manifests while giving a running display of imports on
2299444c26fSTom Whitten	# console, and a final count in the logfile.
2309444c26fSTom Whitten	#
231*293e3ab3STruong Q. Nguyen	dirs="$nonsite_dirs"
232*293e3ab3STruong Q. Nguyen	[ -d "$basedir/site" ] && dirs="$dirs $basedir/site"
233*293e3ab3STruong Q. Nguyen
234*293e3ab3STruong Q. Nguyen	if [ "$console_print" = "true" ]; then
2359444c26fSTom Whitten		$X /usr/sbin/svccfg import -p /dev/msglog $dirs > $logf 2>&1
236*293e3ab3STruong Q. Nguyen	else
237*293e3ab3STruong Q. Nguyen		$X /usr/sbin/svccfg import $dirs > $logf 2>&1
238*293e3ab3STruong Q. Nguyen	fi
2399444c26fSTom Whitten
2409444c26fSTom Whitten	grep "Loaded .*. smf(5) service descriptions" $logf > /dev/null 2>&1
2419444c26fSTom Whitten	if [ $? -eq 0 ]; then
2429444c26fSTom Whitten		activity=true
2439444c26fSTom Whitten	fi
2449444c26fSTom Whitten
2459444c26fSTom Whitten	if [ -s $logf ]; then
2469444c26fSTom Whitten		grep "smf(5) service descriptions failed to load" $logf > /dev/null 2>&1
2479444c26fSTom Whitten		failures=$?
2489444c26fSTom Whitten		if [ $failures -eq 0 ]; then
2499444c26fSTom Whitten			echo "svccfg warnings:"
2509444c26fSTom Whitten		fi
2519444c26fSTom Whitten		cat $logf
2529444c26fSTom Whitten
253*293e3ab3STruong Q. Nguyen		if [ $failures -eq 0 -a "$console_print" = "true" ]; then
2549444c26fSTom Whitten			msg="svccfg import warnings.  See"
2559444c26fSTom Whitten			msg="$msg /var/svc/log/system-manifest-import:default.log ."
2569444c26fSTom Whitten			echo $msg > /dev/msglog
2579444c26fSTom Whitten		fi
2589444c26fSTom Whitten	fi
2599444c26fSTom Whitten	rm -f $logf
2609444c26fSTom Whitten}
2619444c26fSTom Whitten
2629444c26fSTom Whitten#
2639444c26fSTom Whitten# 3.  Profile application.  We must create the platform profile upon
2649444c26fSTom Whitten# first boot, as we may be a diskless client of a platform or
2659444c26fSTom Whitten# architecture distinct from our NFS server.
2669444c26fSTom Whitten#
2679444c26fSTom Whitten# Generic and platform profiles are only supported in /etc.
2689444c26fSTom Whitten#
2699444c26fSTom Whittenfunction apply_profile {
2709444c26fSTom Whitten	#
2719444c26fSTom Whitten	# If smf/manifest doesn't have any profile under /etc/var/profile,
2729444c26fSTom Whitten	# this is very likely an import after upgrade so call
2739444c26fSTom Whitten	# preserve_system_profiles in that case.
2749444c26fSTom Whitten	#
2759444c26fSTom Whitten	LC_ALL=C pl=`/usr/bin/uname -i | /usr/bin/tr , _`
2769444c26fSTom Whitten	pln="etc_svc_profile_platform_${pl}_xml"
2779444c26fSTom Whitten
2789444c26fSTom Whitten	LC_ALL=C plm=`/usr/bin/uname -m | /usr/bin/tr , _`
2799444c26fSTom Whitten	[ $plm != $pl ] && plmn="etc_svc_profile_platform_${plm}_xml"
2809444c26fSTom Whitten
2819444c26fSTom Whitten	preserve_profiles=1
2829444c26fSTom Whitten	for prof in $pln $plmn etc_svc_profile_platform_none_xml \
2839444c26fSTom Whitten	    etc_svc_profile_generic_limited_net_xml \
2849444c26fSTom Whitten	    etc_svc_profile_generic_open_xml; do
2859444c26fSTom Whitten		if /usr/bin/svcprop -p $prof smf/manifest >/dev/null 2>&1
2869444c26fSTom Whitten		then
2879444c26fSTom Whitten			preserve_profiles=0
2889444c26fSTom Whitten			break
2899444c26fSTom Whitten		fi
2909444c26fSTom Whitten	done
2919444c26fSTom Whitten
2929444c26fSTom Whitten	if [ $preserve_profiles -eq 1 ]; then
2939444c26fSTom Whitten		echo "/etc/svc system profiles not found: upgrade system profiles"
2949444c26fSTom Whitten		preserve_system_profiles || return
2959444c26fSTom Whitten	fi
2969444c26fSTom Whitten
2979444c26fSTom Whitten	typeset prefix="/etc/svc/profile"
2989444c26fSTom Whitten	svccfg_apply $prefix/generic.xml
2999444c26fSTom Whitten	if [ ! -f $prefix/platform.xml ]; then
3009444c26fSTom Whitten		this_karch=`uname -m`
3019444c26fSTom Whitten		this_plat=`uname -i`
3029444c26fSTom Whitten
3039444c26fSTom Whitten		if [ -f $prefix/platform_$this_plat.xml ]; then
3049444c26fSTom Whitten			platform_profile=platform_$this_plat.xml
3059444c26fSTom Whitten		elif [ -f $prefix/platform_$this_karch.xml ]; then
3069444c26fSTom Whitten			platform_profile=platform_$this_karch.xml
3079444c26fSTom Whitten		else
3089444c26fSTom Whitten			platform_profile=platform_none.xml
3099444c26fSTom Whitten		fi
3109444c26fSTom Whitten
3119444c26fSTom Whitten		ln -s $platform_profile $prefix/platform.xml
3129444c26fSTom Whitten	fi
3139444c26fSTom Whitten
3149444c26fSTom Whitten	svccfg_apply $prefix/platform.xml
3159444c26fSTom Whitten}
3169444c26fSTom Whitten
3179444c26fSTom Whitten#
3189444c26fSTom Whitten# 4.  Upgrade handling.  The upgrade file generally consists of a series
3199444c26fSTom Whitten# of svcadm(1M) and svccfg(1M) commands.
3209444c26fSTom Whitten#
3219444c26fSTom Whittenfunction handle_upgrade {
3229444c26fSTom Whitten
3239444c26fSTom Whitten	[ -f /var/svc/profile/upgrade ] && activity=true
3249444c26fSTom Whitten
3259444c26fSTom Whitten	(
3269444c26fSTom Whitten		unset SVCCFG_CHECKHASH
3279444c26fSTom Whitten
3289444c26fSTom Whitten		if [ -f /var/svc/profile/upgrade ]; then
3299444c26fSTom Whitten			. /var/svc/profile/upgrade
3309444c26fSTom Whitten
3319444c26fSTom Whitten			/usr/bin/mv /var/svc/profile/upgrade \
3329444c26fSTom Whitten			    /var/svc/profile/upgrade.app.`date +\%Y\%m\%d\%H\%M\%S`
3339444c26fSTom Whitten		fi
3349444c26fSTom Whitten
3359444c26fSTom Whitten		#
3369444c26fSTom Whitten		# Rename the datalink upgrade script file. This script is used in the
3379444c26fSTom Whitten		# network/physical service to upgrade datalink configuration, but
3389444c26fSTom Whitten		# the file cannot be renamed until now (when the file system becomes
3399444c26fSTom Whitten		# read-write).
3409444c26fSTom Whitten		#
3419444c26fSTom Whitten		datalink_script=/var/svc/profile/upgrade_datalink
3429444c26fSTom Whitten		if [ -f "${datalink_script}" ]; then
3439444c26fSTom Whitten			/usr/bin/mv "${datalink_script}" \
3449444c26fSTom Whitten			    "${datalink_script}".app.`date +\%Y\%m\%d\%H\%M\%S`
3459444c26fSTom Whitten		fi
3469444c26fSTom Whitten	)
3479444c26fSTom Whitten}
3489444c26fSTom Whitten
3499444c26fSTom Whitten#
350adfc3118STruong Nguyen# 5.  Giving administrator the final say, apply site.xml profile and profiles
351adfc3118STruong Nguyen#     under /etc/svc/profile/site directory.
3529444c26fSTom Whitten#
3539444c26fSTom Whittenfunction apply_site_profile {
354*293e3ab3STruong Q. Nguyen        typeset prefix="$1"
3559444c26fSTom Whitten	[ -f $prefix/site.xml ] && svccfg_apply $prefix/site.xml
356adfc3118STruong Nguyen
357*293e3ab3STruong Q. Nguyen	if [ -d $PROFILE_DIR_SITE -a "$1" = "/etc/svc/profile" ]; then
358adfc3118STruong Nguyen		svccfg_apply $PROFILE_DIR_SITE
359adfc3118STruong Nguyen	fi
3607c478bd9Sstevel@tonic-gate}
3617c478bd9Sstevel@tonic-gate
36270cbfe41SPhilippe Jung#
36370cbfe41SPhilippe Jung# 0b Cleanup deathrow
36470cbfe41SPhilippe Jung#
3659444c26fSTom Whittenif [ "$early" = "false" ];then
36670cbfe41SPhilippe Jung	deathrow=/etc/svc/deathrow
36770cbfe41SPhilippe Jung	if [ -s $deathrow ];then
36870cbfe41SPhilippe Jung		#
36970cbfe41SPhilippe Jung		# svc.startd has unconfigured the services found in deathrow,
37070cbfe41SPhilippe Jung		# clean them now.
37170cbfe41SPhilippe Jung		#
37270cbfe41SPhilippe Jung		while read fmri mfst pkgname; do
37370cbfe41SPhilippe Jung			# Delete services and instances from the deathrow file.
37470cbfe41SPhilippe Jung			/usr/sbin/svccfg delete -f $fmri >/dev/null 2>&1
37570cbfe41SPhilippe Jung			# Remove deathrow manifest hash.
37670cbfe41SPhilippe Jung			/usr/sbin/svccfg delhash -d $mfst >/dev/null 2>&1
37770cbfe41SPhilippe Jung		done < $deathrow
37870cbfe41SPhilippe Jung		/usr/bin/mv $deathrow $deathrow.old
37970cbfe41SPhilippe Jung	fi
3809444c26fSTom Whittenfi
3819444c26fSTom Whitten
3827c478bd9Sstevel@tonic-gateSVCCFG_CHECKHASH=1 export SVCCFG_CHECKHASH
3837c478bd9Sstevel@tonic-gate
3847c478bd9Sstevel@tonic-gate#
38570cbfe41SPhilippe Jung# 0c Clean up repository
3867c478bd9Sstevel@tonic-gate#
3879444c26fSTom Whittenif [ "$early" = "false" ]; then
3887c478bd9Sstevel@tonic-gate	if [ -z "$X" ] && /usr/bin/svcprop smf/manifest 2>/dev/null |
3897c478bd9Sstevel@tonic-gate	    /usr/bin/grep '^ar_svc_[^/]*/md5sum opaque ' >/dev/null
3907c478bd9Sstevel@tonic-gate	then
3917c478bd9Sstevel@tonic-gate		set -- `
3927c478bd9Sstevel@tonic-gate			/usr/bin/svcprop smf/manifest 2>/dev/null |
3937c478bd9Sstevel@tonic-gate			    /usr/bin/grep '^ar_svc[^/]*/md5sum opaque ' |
3947c478bd9Sstevel@tonic-gate			    /usr/bin/tr '/' ' ' |
3957c478bd9Sstevel@tonic-gate			    while read pg prop type value; do
3967c478bd9Sstevel@tonic-gate				echo "$pg/$value"
3977c478bd9Sstevel@tonic-gate			done
3987c478bd9Sstevel@tonic-gate		`
3997c478bd9Sstevel@tonic-gate		backup=`echo "$#/$#" | sed 's/.//g'`
4007c478bd9Sstevel@tonic-gate		fwidth=`echo "$#\c" | wc -c`
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate		echo "Converting obsolete repository entries: \c" > /dev/msglog
4037c478bd9Sstevel@tonic-gate		i=1; n=$#
4047c478bd9Sstevel@tonic-gate		while [ $# -gt 0 ]; do
4057c478bd9Sstevel@tonic-gate			printf "%${fwidth}s/%${fwidth}s" $i $n > /dev/msglog
4067c478bd9Sstevel@tonic-gate			echo $1 | sed 's:/: :' | (
4077c478bd9Sstevel@tonic-gate				read pg value
4087c478bd9Sstevel@tonic-gate
4097c478bd9Sstevel@tonic-gate				(echo "select /smf/manifest"; echo "delpg v$pg") |
4107c478bd9Sstevel@tonic-gate				    /usr/sbin/svccfg 2>/dev/null >/dev/null
4117c478bd9Sstevel@tonic-gate				(echo "select /smf/manifest"; echo "delpg $pg") |
4127c478bd9Sstevel@tonic-gate				    /usr/sbin/svccfg 2>/dev/null >/dev/null
4137c478bd9Sstevel@tonic-gate				(echo "select /smf/manifest";
4147c478bd9Sstevel@tonic-gate				    echo "addpg v$pg framework") |
4157c478bd9Sstevel@tonic-gate				    /usr/sbin/svccfg 2>/dev/null >/dev/null
4167c478bd9Sstevel@tonic-gate				(echo "select /smf/manifest";
4177c478bd9Sstevel@tonic-gate				    echo "setprop v$pg/md5sum = opaque: $value") |
4187c478bd9Sstevel@tonic-gate				    /usr/sbin/svccfg 2>/dev/null >/dev/null
4197c478bd9Sstevel@tonic-gate			)
4207c478bd9Sstevel@tonic-gate			i=`expr $i + 1`
4217c478bd9Sstevel@tonic-gate			shift
4227c478bd9Sstevel@tonic-gate			echo "$backup\c" > /dev/msglog
4237c478bd9Sstevel@tonic-gate		done
4247c478bd9Sstevel@tonic-gate		echo > /dev/msglog
4257c478bd9Sstevel@tonic-gate		echo "Converted $n obsolete repository entries"
4267c478bd9Sstevel@tonic-gate		activity=true
4277c478bd9Sstevel@tonic-gate	fi
4287c478bd9Sstevel@tonic-gate
4297c478bd9Sstevel@tonic-gatefi
4307c478bd9Sstevel@tonic-gate
4317c478bd9Sstevel@tonic-gate#
432*293e3ab3STruong Q. Nguyen# If the alternate repository and directory are specified, simply set
433*293e3ab3STruong Q. Nguyen# SVCCFG_REPOSITORY env, run svccfg import on the given directory, and
434*293e3ab3STruong Q. Nguyen# exit.
435*293e3ab3STruong Q. Nguyen#
436*293e3ab3STruong Q. Nguyenif [ -n "$ALT_REPOSITORY" -a -n "$ALT_MFST_DIR" ]; then
437*293e3ab3STruong Q. Nguyen	SVCCFG_REPOSITORY=$ALT_REPOSITORY export SVCCFG_REPOSITORY
438*293e3ab3STruong Q. Nguyen	import_manifests "$ALT_MFST_DIR" false
439*293e3ab3STruong Q. Nguyen	unset SVCCFG_REPOSITORY
440*293e3ab3STruong Q. Nguyen	exit 0
441*293e3ab3STruong Q. Nguyenfi
442*293e3ab3STruong Q. Nguyen
443*293e3ab3STruong Q. Nguyen#
4449444c26fSTom Whitten# Call import and apply profiles here
4457c478bd9Sstevel@tonic-gate#
4469444c26fSTom Whittenif [ "$early" = "true" ]; then
447*293e3ab3STruong Q. Nguyen	import_manifests "/lib/svc/manifest" true
4489444c26fSTom Whitten	apply_profile
449*293e3ab3STruong Q. Nguyen	apply_site_profile "/etc/svc/profile"
4509444c26fSTom Whittenelse
4519444c26fSTom Whitten	#
452*293e3ab3STruong Q. Nguyen	# Process both /lib/svc/manifest and /var/svc/manifest
4539444c26fSTom Whitten	# during late manifest-import
4549444c26fSTom Whitten	#
4559444c26fSTom Whitten	# First import the manifests
4569444c26fSTom Whitten	#
457*293e3ab3STruong Q. Nguyen	import_manifests "/lib/svc/manifest" true
458*293e3ab3STruong Q. Nguyen	import_manifests "/var/svc/manifest" true
4597c478bd9Sstevel@tonic-gate
4607c478bd9Sstevel@tonic-gate	#
4619444c26fSTom Whitten	# Apply profiles
4627c478bd9Sstevel@tonic-gate	#
4639444c26fSTom Whitten	apply_profile
464*293e3ab3STruong Q. Nguyen	apply_site_profile "/etc/svc/profile"
4657c478bd9Sstevel@tonic-gate
466c0889d7aSstevep	#
4679444c26fSTom Whitten	# Run the upgrade script
468c0889d7aSstevep	#
4699444c26fSTom Whitten	handle_upgrade
470*293e3ab3STruong Q. Nguyen	apply_site_profile "/var/svc/profile"
4719444c26fSTom Whittenfi
472c0889d7aSstevep
4739444c26fSTom Whitten
4749444c26fSTom Whitten#
4759444c26fSTom Whitten# 6.  Final actions.
4769444c26fSTom Whitten#
4779444c26fSTom Whitten
4789444c26fSTom Whittenif $activity; then
4799444c26fSTom Whitten	/usr/sbin/svcadm _smf_backup "manifest_import" || true
4809444c26fSTom Whittenfi
4819444c26fSTom Whitten
4829444c26fSTom Whitten#
4839444c26fSTom Whitten# If the filesystem is NOT read only then move the repo back to perm
4849444c26fSTom Whitten# There is no care wether the switch was made or not, but just want
4859444c26fSTom Whitten# to move it.  If it is already perm this does not affect anything
4869444c26fSTom Whitten# at least on the surface.  REALLY want to improve on this...
4879444c26fSTom Whitten#
4889444c26fSTom Whittentouch /etc/svc/smf_rwtest.$$ > /dev/null 2>&1
48923294c7dSSean Wilcoxif [ $? -eq 0 ]; then
4909444c26fSTom Whitten	rm -f /etc/svc/smf_rwtest.$$
491c0889d7aSstevep	/usr/sbin/svcadm _smf_repository_switch perm || { \
492c0889d7aSstevep	    echo "Repository switch back operation failed, \c"
493c0889d7aSstevep	    echo "please check the system log for the"
494c0889d7aSstevep	    echo "possible fatal error messages."
495c0889d7aSstevep	    exit $SMF_EXIT_ERR_FATAL
496c0889d7aSstevep	    }
497c0889d7aSstevepfi
498c0889d7aSstevep
4997c478bd9Sstevel@tonic-gateif $activity; then
5009444c26fSTom Whitten	/usr/sbin/svccfg cleanup | /usr/bin/tee /dev/msglog
5019444c26fSTom Whittenelse
5029444c26fSTom Whitten	cleanup_needwork
5039444c26fSTom Whitten	if [ $? -ne 0 ]; then
5049444c26fSTom Whitten		/usr/sbin/svccfg cleanup -a | /usr/bin/tee /dev/msglog
5057c478bd9Sstevel@tonic-gate	fi
5069444c26fSTom Whittenfi
50723294c7dSSean Wilcox
5087c478bd9Sstevel@tonic-gateexit 0
509