xref: /illumos-gate/usr/src/cmd/svc/milestone/manifest-import (revision bbf215553c7233fbab8a0afdf1fac74c44781867)
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.
2356bce609SAndrew Stormont# Copyright 2017 RackTop Systems.
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate
2670cbfe41SPhilippe Jung# 0a  Initialization.
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate[ -f /lib/svc/share/smf_include.sh ] || exit 1
297c478bd9Sstevel@tonic-gate
30c0889d7aSstevep. /lib/svc/share/smf_include.sh
31c0889d7aSstevep
327c478bd9Sstevel@tonic-gateactivity=false
337c478bd9Sstevel@tonic-gate
349444c26fSTom WhittenEMI_SERVICE="svc:/system/early-manifest-import:default"
35adfc3118STruong NguyenPROFILE_DIR_SITE="/etc/svc/profile/site"
369444c26fSTom Whitten
377c478bd9Sstevel@tonic-gateX=
38293e3ab3STruong Q. NguyenALT_REPOSITORY=
39293e3ab3STruong Q. NguyenALT_MFST_DIR=
409444c26fSTom Whittenearly=false
419444c26fSTom Whitten[ "$SMF_FMRI" == "$EMI_SERVICE" ] && early=true
42293e3ab3STruong Q. Nguyen
43293e3ab3STruong Q. Nguyenusage()
44293e3ab3STruong Q. Nguyen{
45293e3ab3STruong Q. Nguyen	echo "Usage: /lib/svc/method/manifest-import [-n]" \
46293e3ab3STruong Q. Nguyen	    "[-f repository-file -d manifest-directory]"
47293e3ab3STruong Q. Nguyen	echo "\nOptions:"
48293e3ab3STruong Q. Nguyen	echo "-n dryrun"
49293e3ab3STruong Q. Nguyen	echo "-f and -d specify alternate repository and" \
50293e3ab3STruong Q. Nguyen	    "manifest directory for import\n"
51293e3ab3STruong Q. Nguyen	exit 2
52293e3ab3STruong Q. Nguyen}
53293e3ab3STruong Q. Nguyen
54293e3ab3STruong Q. Nguyenwhile getopts "nd:f:" opt; do
557c478bd9Sstevel@tonic-gate	case $opt in
567c478bd9Sstevel@tonic-gate		n)	X=echo;;
57293e3ab3STruong Q. Nguyen		d)	ALT_MFST_DIR=$OPTARG;;
58293e3ab3STruong Q. Nguyen		f)	ALT_REPOSITORY=$OPTARG;;
59293e3ab3STruong Q. Nguyen		?)	usage;;
607c478bd9Sstevel@tonic-gate	esac
617c478bd9Sstevel@tonic-gatedone
627c478bd9Sstevel@tonic-gate
63293e3ab3STruong Q. Nguyen#
64293e3ab3STruong Q. Nguyen# Both -f and -d options must be specified together or not specified at all
65293e3ab3STruong Q. Nguyen#
66293e3ab3STruong Q. Nguyen[ -n "$ALT_REPOSITORY" -a -z "$ALT_MFST_DIR" ] && usage
67293e3ab3STruong Q. Nguyen[ -n "$ALT_MFST_DIR" -a -z "$ALT_REPOSITORY" ] && usage
68293e3ab3STruong Q. Nguyen
6923294c7dSSean Wilcoxfunction svccfg_apply {
707c478bd9Sstevel@tonic-gate	$X /usr/sbin/svccfg apply $1
717c478bd9Sstevel@tonic-gate	if [ $? -ne 0 ]; then
727c478bd9Sstevel@tonic-gate		echo "WARNING: svccfg apply $1 failed" | tee /dev/msglog
737c478bd9Sstevel@tonic-gate	fi
747c478bd9Sstevel@tonic-gate}
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate#
7756bce609SAndrew Stormont# If the smf repository has file entries that are missing
789444c26fSTom Whitten# then there is work to be done by the cleanup process.
797c478bd9Sstevel@tonic-gate#
809444c26fSTom Whittenfunction cleanup_needwork {
8156bce609SAndrew Stormont	smfmfiles=`svcprop -p manifestfiles '*' 2>/dev/null |
8256bce609SAndrew Stormont	    nawk -v early="$early" '$2 == "astring" &&
8356bce609SAndrew Stormont	    (early != "true" || $3 ~ "^/lib/") { print $3 }'`
847c478bd9Sstevel@tonic-gate
859444c26fSTom Whitten	nw=`/lib/svc/bin/mfstscan $smfmfiles 2>&1 1>/dev/null`
869444c26fSTom Whitten	[ "$nw" ] && return 1
877c478bd9Sstevel@tonic-gate
889444c26fSTom Whitten	return 0
897c478bd9Sstevel@tonic-gate}
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate#
929444c26fSTom Whitten# Upon upgrading to early manifest import code, preserve hashes of system
939444c26fSTom Whitten# profiles which lived under /var/svc/profile so that svccfg apply would
949444c26fSTom Whitten# not re-apply the profiles and overwrite user customizations. Simply
959444c26fSTom Whitten# migrate manifestfile and hash values to new property groups named after
969444c26fSTom Whitten# profiles under /etc/svc/profile. If the profiles don't really exist,
979444c26fSTom Whitten# svccfg cleanup will remove the property groups in a later step.
987c478bd9Sstevel@tonic-gate#
999444c26fSTom Whitten# Existing generic.xml, inetd_services.xml, and name_service.xml symlinks
1009444c26fSTom Whitten# need to be preserved.
1017c478bd9Sstevel@tonic-gate#
1029444c26fSTom Whitten# Don't process site.xml profile since it is still supported under
1039444c26fSTom Whitten# /var/svc/profile directory.
1047c478bd9Sstevel@tonic-gate#
1059444c26fSTom Whittenfunction preserve_system_profiles {
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate	#
1089444c26fSTom Whitten	# If /var is a separate fs, return and let Late Import
1099444c26fSTom Whitten	# preserves the hashes.
1107c478bd9Sstevel@tonic-gate	#
1119444c26fSTom Whitten	[ -d "/var/svc/profile" ] || return 1
1127c478bd9Sstevel@tonic-gate
1139444c26fSTom Whitten	#
1149444c26fSTom Whitten	# Preserve hashes for the following profiles: generic (two
1159444c26fSTom Whitten	# cases) and platform (uname -i, uname -m outputs).
1169444c26fSTom Whitten	#
1177c478bd9Sstevel@tonic-gate	gn="var_svc_profile_generic_open_xml"
1187c478bd9Sstevel@tonic-gate	gh=`/usr/bin/svcprop -p ${gn}/md5sum smf/manifest 2>/dev/null`
1197c478bd9Sstevel@tonic-gate	[ $? = 0 ] || gh=""
1209444c26fSTom Whitten	gn="etc_svc_profile_generic_open_xml"
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate	gln="var_svc_profile_generic_limited_net_xml"
1237c478bd9Sstevel@tonic-gate	glh=`/usr/bin/svcprop -p ${gln}/md5sum smf/manifest 2>/dev/null`
1247c478bd9Sstevel@tonic-gate	[ $? = 0 ] || glh=""
1259444c26fSTom Whitten	gln="etc_svc_profile_generic_limited_net_xml"
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate	LC_ALL=C pl=`/usr/bin/uname -i | /usr/bin/tr , _`
1287c478bd9Sstevel@tonic-gate	pln="var_svc_profile_platform_${pl}_xml"
1297c478bd9Sstevel@tonic-gate	plh=`/usr/bin/svcprop -p ${pln}/md5sum smf/manifest 2>/dev/null`
1307c478bd9Sstevel@tonic-gate	[ $? = 0 ] || plh=""
1319444c26fSTom Whitten	pln="etc_svc_profile_platform_${pl}_xml"
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate	LC_ALL=C plm=`/usr/bin/uname -m | /usr/bin/tr , _`
1347c478bd9Sstevel@tonic-gate	if [ $plm != $pl ]; then
1357c478bd9Sstevel@tonic-gate		plmn="var_svc_profile_platform_${plm}_xml"
1367c478bd9Sstevel@tonic-gate		plmh=`/usr/bin/svcprop -p ${plmn}/md5sum smf/manifest \
1377c478bd9Sstevel@tonic-gate		    2>/dev/null`
1387c478bd9Sstevel@tonic-gate		[ $? = 0 ] || plmh=""
1399444c26fSTom Whitten		plmn="etc_svc_profile_platform_${plm}_xml"
1407c478bd9Sstevel@tonic-gate	else
1417c478bd9Sstevel@tonic-gate		plmh=""
1427c478bd9Sstevel@tonic-gate	fi
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate	[ -n "$gh" ] && {
1457c478bd9Sstevel@tonic-gate		echo "Preserving generic hash ($gh)."
1467c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest addpg ${gn} framework
1477c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest setprop ${gn}/md5sum = \
1487c478bd9Sstevel@tonic-gate		    opaque: $gh
1499444c26fSTom Whitten		/usr/sbin/svccfg -s smf/manifest setprop ${gn}/manifestfile = \
1509444c26fSTom Whitten		    astring: "/etc/svc/profile/generic.xml"
1517c478bd9Sstevel@tonic-gate	}
1527c478bd9Sstevel@tonic-gate	[ -n "$glh" ] && {
1537c478bd9Sstevel@tonic-gate		echo "Preserving generic_limited hash ($glh)."
1547c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest addpg ${gln} framework
1557c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest setprop ${gln}/md5sum = \
1567c478bd9Sstevel@tonic-gate		    opaque: $glh
1579444c26fSTom Whitten		/usr/sbin/svccfg -s smf/manifest setprop ${gln}/manifestfile = \
1589444c26fSTom Whitten		    astring: "/etc/svc/profile/generic.xml"
1597c478bd9Sstevel@tonic-gate	}
1607c478bd9Sstevel@tonic-gate	[ -n "$plh" ] && {
1617c478bd9Sstevel@tonic-gate		echo "Preserving platform hash ($plh)."
1627c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest addpg $pln framework
1637c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest setprop $pln/md5sum = \
1647c478bd9Sstevel@tonic-gate		    opaque: $plh
1659444c26fSTom Whitten		/usr/sbin/svccfg -s smf/manifest setprop ${pln}/manifestfile = \
1669444c26fSTom Whitten		    astring: "/etc/svc/profile/platform_${pl}_xml"
1677c478bd9Sstevel@tonic-gate	}
1687c478bd9Sstevel@tonic-gate	[ -n "$plmh" ] && {
1697c478bd9Sstevel@tonic-gate		echo "Preserving platform hash ($plmh)."
1707c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest addpg $plmn framework
1717c478bd9Sstevel@tonic-gate		/usr/sbin/svccfg -s smf/manifest setprop $plmn/md5sum = \
1727c478bd9Sstevel@tonic-gate		    opaque: $plmh
1739444c26fSTom Whitten		/usr/sbin/svccfg -s smf/manifest setprop \
1749444c26fSTom Whitten		    ${plmn}/manifestfile = \
1759444c26fSTom Whitten		    astring: "/etc/svc/profile/platform_${plm}_xml"
1767c478bd9Sstevel@tonic-gate	}
1779444c26fSTom Whitten
1789444c26fSTom Whitten	#
1799444c26fSTom Whitten	# Move symlinks from /var/svc/profile to /etc/svc/profile
1809444c26fSTom Whitten	#
1819444c26fSTom Whitten	generic_prof="/var/svc/profile/generic.xml"
1829444c26fSTom Whitten	ns_prof="/var/svc/profile/name_service.xml"
1839444c26fSTom Whitten	inetd_prof="/var/svc/profile/inetd_services.xml"
184adfc3118STruong Nguyen	platform_prof="/var/svc/profile/platform.xml"
1859444c26fSTom Whitten	[ -L "$generic_prof" ] && mv $generic_prof /etc/svc/profile/
1869444c26fSTom Whitten	[ -L "$ns_prof" ] && mv $ns_prof /etc/svc/profile/
1879444c26fSTom Whitten	[ -L "$inetd_prof" ] && mv $inetd_prof /etc/svc/profile/
188adfc3118STruong Nguyen	[ -L "$platform_prof" ] && mv $platform_prof /etc/svc/profile/
1899444c26fSTom Whitten
1909444c26fSTom Whitten	return 0
1917c478bd9Sstevel@tonic-gate}
1929444c26fSTom Whitten
1939444c26fSTom Whitten#
1949444c26fSTom Whitten# 2.  Manifest import.  Application directories first, then
1959444c26fSTom Whitten# site-specific manifests.
1969444c26fSTom Whitten#
1979444c26fSTom Whittenfunction import_manifests {
1989444c26fSTom Whitten	typeset basedir=$1
199293e3ab3STruong Q. Nguyen	typeset console_print=$2
2009444c26fSTom Whitten	typeset logf="/etc/svc/volatile/manifest_import.$$"
2019444c26fSTom Whitten
2029444c26fSTom Whitten	rm -f $logf
2039444c26fSTom Whitten
204293e3ab3STruong Q. Nguyen	nonsite_dirs=`/usr/bin/find $basedir/* -name site \
2059444c26fSTom Whitten	    -prune -o -type d -print -prune`
2069444c26fSTom Whitten
2079444c26fSTom Whitten	if [ -n "$_MFST_DEBUG" ]; then
2089444c26fSTom Whitten		nonsite_manifests=`/lib/svc/bin/mfstscan $nonsite_dirs`
209293e3ab3STruong Q. Nguyen		site_manifests=`/lib/svc/bin/mfstscan $basedir/site`
2109444c26fSTom Whitten
2119444c26fSTom Whitten		manifests="$nonsite_manifests $site_manifests"
2129444c26fSTom Whitten
2139444c26fSTom Whitten		echo "Changed manifests to import:"
2149444c26fSTom Whitten		for m in $manifests; do echo "  $m"; done
2159444c26fSTom Whitten	fi
2169444c26fSTom Whitten
2179444c26fSTom Whitten	#
218293e3ab3STruong Q. Nguyen	# Upon boot, attempt to move the repository to tmpfs.
2199444c26fSTom Whitten	#
220293e3ab3STruong Q. Nguyen	if [ -z "$ALT_REPOSITORY" -a -z "$ALT_MFST_DIR" ]; then
2219444c26fSTom Whitten		/usr/sbin/svcadm _smf_repository_switch fast
222293e3ab3STruong Q. Nguyen	fi
2239444c26fSTom Whitten
2249444c26fSTom Whitten	#
2259444c26fSTom Whitten	# Import the manifests while giving a running display of imports on
2269444c26fSTom Whitten	# console, and a final count in the logfile.
2279444c26fSTom Whitten	#
228293e3ab3STruong Q. Nguyen	dirs="$nonsite_dirs"
229293e3ab3STruong Q. Nguyen	[ -d "$basedir/site" ] && dirs="$dirs $basedir/site"
230293e3ab3STruong Q. Nguyen
231293e3ab3STruong Q. Nguyen	if [ "$console_print" = "true" ]; then
2329444c26fSTom Whitten		$X /usr/sbin/svccfg import -p /dev/msglog $dirs > $logf 2>&1
233293e3ab3STruong Q. Nguyen	else
234293e3ab3STruong Q. Nguyen		$X /usr/sbin/svccfg import $dirs > $logf 2>&1
235293e3ab3STruong Q. Nguyen	fi
2369444c26fSTom Whitten
237*bbf21555SRichard Lowe	grep "Loaded .*. smf(7) service descriptions" $logf > /dev/null 2>&1
2389444c26fSTom Whitten	if [ $? -eq 0 ]; then
2399444c26fSTom Whitten		activity=true
2409444c26fSTom Whitten	fi
2419444c26fSTom Whitten
2429444c26fSTom Whitten	if [ -s $logf ]; then
243*bbf21555SRichard Lowe		grep "smf(7) service descriptions failed to load" $logf > /dev/null 2>&1
2449444c26fSTom Whitten		failures=$?
2459444c26fSTom Whitten		if [ $failures -eq 0 ]; then
2469444c26fSTom Whitten			echo "svccfg warnings:"
2479444c26fSTom Whitten		fi
2489444c26fSTom Whitten		cat $logf
2499444c26fSTom Whitten
250293e3ab3STruong Q. Nguyen		if [ $failures -eq 0 -a "$console_print" = "true" ]; then
2519444c26fSTom Whitten			msg="svccfg import warnings.  See"
2529444c26fSTom Whitten			msg="$msg /var/svc/log/system-manifest-import:default.log ."
2539444c26fSTom Whitten			echo $msg > /dev/msglog
2549444c26fSTom Whitten		fi
2559444c26fSTom Whitten	fi
2569444c26fSTom Whitten	rm -f $logf
2579444c26fSTom Whitten}
2589444c26fSTom Whitten
2599444c26fSTom Whitten#
2609444c26fSTom Whitten# 3.  Profile application.  We must create the platform profile upon
2619444c26fSTom Whitten# first boot, as we may be a diskless client of a platform or
2629444c26fSTom Whitten# architecture distinct from our NFS server.
2639444c26fSTom Whitten#
2649444c26fSTom Whitten# Generic and platform profiles are only supported in /etc.
2659444c26fSTom Whitten#
2669444c26fSTom Whittenfunction apply_profile {
2679444c26fSTom Whitten	#
2689444c26fSTom Whitten	# If smf/manifest doesn't have any profile under /etc/var/profile,
2699444c26fSTom Whitten	# this is very likely an import after upgrade so call
2709444c26fSTom Whitten	# preserve_system_profiles in that case.
2719444c26fSTom Whitten	#
2729444c26fSTom Whitten	LC_ALL=C pl=`/usr/bin/uname -i | /usr/bin/tr , _`
2739444c26fSTom Whitten	pln="etc_svc_profile_platform_${pl}_xml"
2749444c26fSTom Whitten
2759444c26fSTom Whitten	LC_ALL=C plm=`/usr/bin/uname -m | /usr/bin/tr , _`
2769444c26fSTom Whitten	[ $plm != $pl ] && plmn="etc_svc_profile_platform_${plm}_xml"
2779444c26fSTom Whitten
2789444c26fSTom Whitten	preserve_profiles=1
2799444c26fSTom Whitten	for prof in $pln $plmn etc_svc_profile_platform_none_xml \
2809444c26fSTom Whitten	    etc_svc_profile_generic_limited_net_xml \
2819444c26fSTom Whitten	    etc_svc_profile_generic_open_xml; do
2829444c26fSTom Whitten		if /usr/bin/svcprop -p $prof smf/manifest >/dev/null 2>&1
2839444c26fSTom Whitten		then
2849444c26fSTom Whitten			preserve_profiles=0
2859444c26fSTom Whitten			break
2869444c26fSTom Whitten		fi
2879444c26fSTom Whitten	done
2889444c26fSTom Whitten
2899444c26fSTom Whitten	if [ $preserve_profiles -eq 1 ]; then
2909444c26fSTom Whitten		echo "/etc/svc system profiles not found: upgrade system profiles"
2919444c26fSTom Whitten		preserve_system_profiles || return
2929444c26fSTom Whitten	fi
2939444c26fSTom Whitten
2949444c26fSTom Whitten	typeset prefix="/etc/svc/profile"
2959444c26fSTom Whitten	svccfg_apply $prefix/generic.xml
2969444c26fSTom Whitten	if [ ! -f $prefix/platform.xml ]; then
2979444c26fSTom Whitten		this_karch=`uname -m`
2989444c26fSTom Whitten		this_plat=`uname -i`
2999444c26fSTom Whitten
3009444c26fSTom Whitten		if [ -f $prefix/platform_$this_plat.xml ]; then
3019444c26fSTom Whitten			platform_profile=platform_$this_plat.xml
3029444c26fSTom Whitten		elif [ -f $prefix/platform_$this_karch.xml ]; then
3039444c26fSTom Whitten			platform_profile=platform_$this_karch.xml
3049444c26fSTom Whitten		else
3059444c26fSTom Whitten			platform_profile=platform_none.xml
3069444c26fSTom Whitten		fi
3079444c26fSTom Whitten
3089444c26fSTom Whitten		ln -s $platform_profile $prefix/platform.xml
3099444c26fSTom Whitten	fi
3109444c26fSTom Whitten
3119444c26fSTom Whitten	svccfg_apply $prefix/platform.xml
3129444c26fSTom Whitten}
3139444c26fSTom Whitten
3149444c26fSTom Whitten#
3159444c26fSTom Whitten# 4.  Upgrade handling.  The upgrade file generally consists of a series
316*bbf21555SRichard Lowe# of svcadm(8) and svccfg(8) commands.
3179444c26fSTom Whitten#
3189444c26fSTom Whittenfunction handle_upgrade {
3199444c26fSTom Whitten
3209444c26fSTom Whitten	[ -f /var/svc/profile/upgrade ] && activity=true
3219444c26fSTom Whitten
3229444c26fSTom Whitten	(
3239444c26fSTom Whitten		unset SVCCFG_CHECKHASH
3249444c26fSTom Whitten
3259444c26fSTom Whitten		if [ -f /var/svc/profile/upgrade ]; then
3269444c26fSTom Whitten			. /var/svc/profile/upgrade
3279444c26fSTom Whitten
3289444c26fSTom Whitten			/usr/bin/mv /var/svc/profile/upgrade \
3299444c26fSTom Whitten			    /var/svc/profile/upgrade.app.`date +\%Y\%m\%d\%H\%M\%S`
3309444c26fSTom Whitten		fi
3319444c26fSTom Whitten
3329444c26fSTom Whitten		#
3339444c26fSTom Whitten		# Rename the datalink upgrade script file. This script is used in the
3349444c26fSTom Whitten		# network/physical service to upgrade datalink configuration, but
3359444c26fSTom Whitten		# the file cannot be renamed until now (when the file system becomes
3369444c26fSTom Whitten		# read-write).
3379444c26fSTom Whitten		#
3389444c26fSTom Whitten		datalink_script=/var/svc/profile/upgrade_datalink
3399444c26fSTom Whitten		if [ -f "${datalink_script}" ]; then
3409444c26fSTom Whitten			/usr/bin/mv "${datalink_script}" \
3419444c26fSTom Whitten			    "${datalink_script}".app.`date +\%Y\%m\%d\%H\%M\%S`
3429444c26fSTom Whitten		fi
3439444c26fSTom Whitten	)
3449444c26fSTom Whitten}
3459444c26fSTom Whitten
3469444c26fSTom Whitten#
347adfc3118STruong Nguyen# 5.  Giving administrator the final say, apply site.xml profile and profiles
348adfc3118STruong Nguyen#     under /etc/svc/profile/site directory.
3499444c26fSTom Whitten#
3509444c26fSTom Whittenfunction apply_site_profile {
351293e3ab3STruong Q. Nguyen        typeset prefix="$1"
3529444c26fSTom Whitten	[ -f $prefix/site.xml ] && svccfg_apply $prefix/site.xml
353adfc3118STruong Nguyen
354293e3ab3STruong Q. Nguyen	if [ -d $PROFILE_DIR_SITE -a "$1" = "/etc/svc/profile" ]; then
355adfc3118STruong Nguyen		svccfg_apply $PROFILE_DIR_SITE
356adfc3118STruong Nguyen	fi
3577c478bd9Sstevel@tonic-gate}
3587c478bd9Sstevel@tonic-gate
35970cbfe41SPhilippe Jung#
36070cbfe41SPhilippe Jung# 0b Cleanup deathrow
36170cbfe41SPhilippe Jung#
3629444c26fSTom Whittenif [ "$early" = "false" ];then
36370cbfe41SPhilippe Jung	deathrow=/etc/svc/deathrow
36470cbfe41SPhilippe Jung	if [ -s $deathrow ];then
36570cbfe41SPhilippe Jung		#
36670cbfe41SPhilippe Jung		# svc.startd has unconfigured the services found in deathrow,
36770cbfe41SPhilippe Jung		# clean them now.
36870cbfe41SPhilippe Jung		#
36970cbfe41SPhilippe Jung		while read fmri mfst pkgname; do
37070cbfe41SPhilippe Jung			# Delete services and instances from the deathrow file.
37170cbfe41SPhilippe Jung			/usr/sbin/svccfg delete -f $fmri >/dev/null 2>&1
37270cbfe41SPhilippe Jung			# Remove deathrow manifest hash.
37370cbfe41SPhilippe Jung			/usr/sbin/svccfg delhash -d $mfst >/dev/null 2>&1
37470cbfe41SPhilippe Jung		done < $deathrow
37570cbfe41SPhilippe Jung		/usr/bin/mv $deathrow $deathrow.old
37670cbfe41SPhilippe Jung	fi
3779444c26fSTom Whittenfi
3789444c26fSTom Whitten
3797c478bd9Sstevel@tonic-gateSVCCFG_CHECKHASH=1 export SVCCFG_CHECKHASH
3807c478bd9Sstevel@tonic-gate
3817c478bd9Sstevel@tonic-gate#
38270cbfe41SPhilippe Jung# 0c Clean up repository
3837c478bd9Sstevel@tonic-gate#
3849444c26fSTom Whittenif [ "$early" = "false" ]; then
3857c478bd9Sstevel@tonic-gate	if [ -z "$X" ] && /usr/bin/svcprop smf/manifest 2>/dev/null |
3867c478bd9Sstevel@tonic-gate	    /usr/bin/grep '^ar_svc_[^/]*/md5sum opaque ' >/dev/null
3877c478bd9Sstevel@tonic-gate	then
3887c478bd9Sstevel@tonic-gate		set -- `
3897c478bd9Sstevel@tonic-gate			/usr/bin/svcprop smf/manifest 2>/dev/null |
3907c478bd9Sstevel@tonic-gate			    /usr/bin/grep '^ar_svc[^/]*/md5sum opaque ' |
3917c478bd9Sstevel@tonic-gate			    /usr/bin/tr '/' ' ' |
3927c478bd9Sstevel@tonic-gate			    while read pg prop type value; do
3937c478bd9Sstevel@tonic-gate				echo "$pg/$value"
3947c478bd9Sstevel@tonic-gate			done
3957c478bd9Sstevel@tonic-gate		`
3967c478bd9Sstevel@tonic-gate		backup=`echo "$#/$#" | sed 's/.//g'`
3977c478bd9Sstevel@tonic-gate		fwidth=`echo "$#\c" | wc -c`
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate		echo "Converting obsolete repository entries: \c" > /dev/msglog
4007c478bd9Sstevel@tonic-gate		i=1; n=$#
4017c478bd9Sstevel@tonic-gate		while [ $# -gt 0 ]; do
4027c478bd9Sstevel@tonic-gate			printf "%${fwidth}s/%${fwidth}s" $i $n > /dev/msglog
4037c478bd9Sstevel@tonic-gate			echo $1 | sed 's:/: :' | (
4047c478bd9Sstevel@tonic-gate				read pg value
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate				(echo "select /smf/manifest"; echo "delpg v$pg") |
4077c478bd9Sstevel@tonic-gate				    /usr/sbin/svccfg 2>/dev/null >/dev/null
4087c478bd9Sstevel@tonic-gate				(echo "select /smf/manifest"; echo "delpg $pg") |
4097c478bd9Sstevel@tonic-gate				    /usr/sbin/svccfg 2>/dev/null >/dev/null
4107c478bd9Sstevel@tonic-gate				(echo "select /smf/manifest";
4117c478bd9Sstevel@tonic-gate				    echo "addpg v$pg framework") |
4127c478bd9Sstevel@tonic-gate				    /usr/sbin/svccfg 2>/dev/null >/dev/null
4137c478bd9Sstevel@tonic-gate				(echo "select /smf/manifest";
4147c478bd9Sstevel@tonic-gate				    echo "setprop v$pg/md5sum = opaque: $value") |
4157c478bd9Sstevel@tonic-gate				    /usr/sbin/svccfg 2>/dev/null >/dev/null
4167c478bd9Sstevel@tonic-gate			)
4177c478bd9Sstevel@tonic-gate			i=`expr $i + 1`
4187c478bd9Sstevel@tonic-gate			shift
4197c478bd9Sstevel@tonic-gate			echo "$backup\c" > /dev/msglog
4207c478bd9Sstevel@tonic-gate		done
4217c478bd9Sstevel@tonic-gate		echo > /dev/msglog
4227c478bd9Sstevel@tonic-gate		echo "Converted $n obsolete repository entries"
4237c478bd9Sstevel@tonic-gate		activity=true
4247c478bd9Sstevel@tonic-gate	fi
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gatefi
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate#
429293e3ab3STruong Q. Nguyen# If the alternate repository and directory are specified, simply set
430293e3ab3STruong Q. Nguyen# SVCCFG_REPOSITORY env, run svccfg import on the given directory, and
431293e3ab3STruong Q. Nguyen# exit.
432293e3ab3STruong Q. Nguyen#
433293e3ab3STruong Q. Nguyenif [ -n "$ALT_REPOSITORY" -a -n "$ALT_MFST_DIR" ]; then
434293e3ab3STruong Q. Nguyen	SVCCFG_REPOSITORY=$ALT_REPOSITORY export SVCCFG_REPOSITORY
435293e3ab3STruong Q. Nguyen	import_manifests "$ALT_MFST_DIR" false
436293e3ab3STruong Q. Nguyen	unset SVCCFG_REPOSITORY
437293e3ab3STruong Q. Nguyen	exit 0
438293e3ab3STruong Q. Nguyenfi
439293e3ab3STruong Q. Nguyen
440293e3ab3STruong Q. Nguyen#
4419444c26fSTom Whitten# Call import and apply profiles here
4427c478bd9Sstevel@tonic-gate#
4439444c26fSTom Whittenif [ "$early" = "true" ]; then
444293e3ab3STruong Q. Nguyen	import_manifests "/lib/svc/manifest" true
4459444c26fSTom Whitten	apply_profile
446293e3ab3STruong Q. Nguyen	apply_site_profile "/etc/svc/profile"
4479444c26fSTom Whittenelse
4489444c26fSTom Whitten	#
449293e3ab3STruong Q. Nguyen	# Process both /lib/svc/manifest and /var/svc/manifest
4509444c26fSTom Whitten	# during late manifest-import
4519444c26fSTom Whitten	#
4529444c26fSTom Whitten	# First import the manifests
4539444c26fSTom Whitten	#
454293e3ab3STruong Q. Nguyen	import_manifests "/lib/svc/manifest" true
455293e3ab3STruong Q. Nguyen	import_manifests "/var/svc/manifest" true
4567c478bd9Sstevel@tonic-gate
4577c478bd9Sstevel@tonic-gate	#
4589444c26fSTom Whitten	# Apply profiles
4597c478bd9Sstevel@tonic-gate	#
4609444c26fSTom Whitten	apply_profile
461293e3ab3STruong Q. Nguyen	apply_site_profile "/etc/svc/profile"
4627c478bd9Sstevel@tonic-gate
463c0889d7aSstevep	#
4649444c26fSTom Whitten	# Run the upgrade script
465c0889d7aSstevep	#
4669444c26fSTom Whitten	handle_upgrade
467293e3ab3STruong Q. Nguyen	apply_site_profile "/var/svc/profile"
4689444c26fSTom Whittenfi
469c0889d7aSstevep
4709444c26fSTom Whitten
4719444c26fSTom Whitten#
4729444c26fSTom Whitten# 6.  Final actions.
4739444c26fSTom Whitten#
4749444c26fSTom Whitten
4759444c26fSTom Whittenif $activity; then
4769444c26fSTom Whitten	/usr/sbin/svcadm _smf_backup "manifest_import" || true
4779444c26fSTom Whittenfi
4789444c26fSTom Whitten
4799444c26fSTom Whitten#
4809444c26fSTom Whitten# If the filesystem is NOT read only then move the repo back to perm
4819444c26fSTom Whitten# There is no care wether the switch was made or not, but just want
4829444c26fSTom Whitten# to move it.  If it is already perm this does not affect anything
4839444c26fSTom Whitten# at least on the surface.  REALLY want to improve on this...
4849444c26fSTom Whitten#
4859444c26fSTom Whittentouch /etc/svc/smf_rwtest.$$ > /dev/null 2>&1
48623294c7dSSean Wilcoxif [ $? -eq 0 ]; then
4879444c26fSTom Whitten	rm -f /etc/svc/smf_rwtest.$$
488c0889d7aSstevep	/usr/sbin/svcadm _smf_repository_switch perm || { \
489c0889d7aSstevep	    echo "Repository switch back operation failed, \c"
490c0889d7aSstevep	    echo "please check the system log for the"
491c0889d7aSstevep	    echo "possible fatal error messages."
492c0889d7aSstevep	    exit $SMF_EXIT_ERR_FATAL
493c0889d7aSstevep	    }
494c0889d7aSstevepfi
495c0889d7aSstevep
4967c478bd9Sstevel@tonic-gateif $activity; then
4979444c26fSTom Whitten	/usr/sbin/svccfg cleanup | /usr/bin/tee /dev/msglog
4989444c26fSTom Whittenelse
4999444c26fSTom Whitten	cleanup_needwork
5009444c26fSTom Whitten	if [ $? -ne 0 ]; then
5019444c26fSTom Whitten		/usr/sbin/svccfg cleanup -a | /usr/bin/tee /dev/msglog
5027c478bd9Sstevel@tonic-gate	fi
5039444c26fSTom Whittenfi
50423294c7dSSean Wilcox
5057c478bd9Sstevel@tonic-gateexit 0
506