110461SSean.Wilcox@Sun.COM#!/bin/ksh 20Sstevel@tonic-gate# 30Sstevel@tonic-gate# CDDL HEADER START 40Sstevel@tonic-gate# 50Sstevel@tonic-gate# The contents of this file are subject to the terms of the 65895Syz147064# Common Development and Distribution License (the "License"). 75895Syz147064# You may not use this file except in compliance with the License. 80Sstevel@tonic-gate# 90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate# See the License for the specific language governing permissions 120Sstevel@tonic-gate# and limitations under the License. 130Sstevel@tonic-gate# 140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate# 200Sstevel@tonic-gate# CDDL HEADER END 210Sstevel@tonic-gate# 2212418STruong.Q.Nguyen@Sun.COM# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 230Sstevel@tonic-gate# 240Sstevel@tonic-gate 257475SPhilippe.Jung@Sun.COM# 0a Initialization. 260Sstevel@tonic-gate 270Sstevel@tonic-gate[ -f /lib/svc/share/smf_include.sh ] || exit 1 280Sstevel@tonic-gate 296035Sstevep. /lib/svc/share/smf_include.sh 306035Sstevep 310Sstevel@tonic-gateactivity=false 320Sstevel@tonic-gate 3311996SThomas.Whitten@Sun.COMEMI_SERVICE="svc:/system/early-manifest-import:default" 3412418STruong.Q.Nguyen@Sun.COMPROFILE_DIR_SITE="/etc/svc/profile/site" 3511996SThomas.Whitten@Sun.COM 360Sstevel@tonic-gateX= 37*13112STony.Q.Nguyen@oracle.comALT_REPOSITORY= 38*13112STony.Q.Nguyen@oracle.comALT_MFST_DIR= 3911996SThomas.Whitten@Sun.COMearly=false 4011996SThomas.Whitten@Sun.COM[ "$SMF_FMRI" == "$EMI_SERVICE" ] && early=true 41*13112STony.Q.Nguyen@oracle.com 42*13112STony.Q.Nguyen@oracle.comusage() 43*13112STony.Q.Nguyen@oracle.com{ 44*13112STony.Q.Nguyen@oracle.com echo "Usage: /lib/svc/method/manifest-import [-n]" \ 45*13112STony.Q.Nguyen@oracle.com "[-f repository-file -d manifest-directory]" 46*13112STony.Q.Nguyen@oracle.com echo "\nOptions:" 47*13112STony.Q.Nguyen@oracle.com echo "-n dryrun" 48*13112STony.Q.Nguyen@oracle.com echo "-f and -d specify alternate repository and" \ 49*13112STony.Q.Nguyen@oracle.com "manifest directory for import\n" 50*13112STony.Q.Nguyen@oracle.com exit 2 51*13112STony.Q.Nguyen@oracle.com} 52*13112STony.Q.Nguyen@oracle.com 53*13112STony.Q.Nguyen@oracle.comwhile getopts "nd:f:" opt; do 540Sstevel@tonic-gate case $opt in 550Sstevel@tonic-gate n) X=echo;; 56*13112STony.Q.Nguyen@oracle.com d) ALT_MFST_DIR=$OPTARG;; 57*13112STony.Q.Nguyen@oracle.com f) ALT_REPOSITORY=$OPTARG;; 58*13112STony.Q.Nguyen@oracle.com ?) usage;; 590Sstevel@tonic-gate esac 600Sstevel@tonic-gatedone 610Sstevel@tonic-gate 62*13112STony.Q.Nguyen@oracle.com# 63*13112STony.Q.Nguyen@oracle.com# Both -f and -d options must be specified together or not specified at all 64*13112STony.Q.Nguyen@oracle.com# 65*13112STony.Q.Nguyen@oracle.com[ -n "$ALT_REPOSITORY" -a -z "$ALT_MFST_DIR" ] && usage 66*13112STony.Q.Nguyen@oracle.com[ -n "$ALT_MFST_DIR" -a -z "$ALT_REPOSITORY" ] && usage 67*13112STony.Q.Nguyen@oracle.com 6810461SSean.Wilcox@Sun.COMfunction svccfg_apply { 690Sstevel@tonic-gate $X /usr/sbin/svccfg apply $1 700Sstevel@tonic-gate if [ $? -ne 0 ]; then 710Sstevel@tonic-gate echo "WARNING: svccfg apply $1 failed" | tee /dev/msglog 720Sstevel@tonic-gate fi 730Sstevel@tonic-gate} 740Sstevel@tonic-gate 7511996SThomas.Whitten@Sun.COM# 7611996SThomas.Whitten@Sun.COM# If the smf/manifest table has file entries that are missing 7711996SThomas.Whitten@Sun.COM# then there is work to be done by the cleanup process. 7811996SThomas.Whitten@Sun.COM# 7911996SThomas.Whitten@Sun.COMfunction cleanup_needwork { 8011996SThomas.Whitten@Sun.COM if [ "$early" == true ]; then 8111996SThomas.Whitten@Sun.COM smfmfiles=`/usr/bin/svcprop smf/manifest | \ 8212418STruong.Q.Nguyen@Sun.COM awk '(/^lib_/ && /\/manifestfile /) {print $3}'` 830Sstevel@tonic-gate else 8411996SThomas.Whitten@Sun.COM smfmfiles=`/usr/bin/svcprop smf/manifest | \ 8511996SThomas.Whitten@Sun.COM awk '/\/manifestfile / {print $3}'` 860Sstevel@tonic-gate fi 870Sstevel@tonic-gate 8811996SThomas.Whitten@Sun.COM nw=`/lib/svc/bin/mfstscan $smfmfiles 2>&1 1>/dev/null` 8911996SThomas.Whitten@Sun.COM [ "$nw" ] && return 1 900Sstevel@tonic-gate 9111996SThomas.Whitten@Sun.COM return 0 920Sstevel@tonic-gate} 930Sstevel@tonic-gate 9411996SThomas.Whitten@Sun.COM# 9511996SThomas.Whitten@Sun.COM# Upon upgrading to early manifest import code, preserve hashes of system 9611996SThomas.Whitten@Sun.COM# profiles which lived under /var/svc/profile so that svccfg apply would 9711996SThomas.Whitten@Sun.COM# not re-apply the profiles and overwrite user customizations. Simply 9811996SThomas.Whitten@Sun.COM# migrate manifestfile and hash values to new property groups named after 9911996SThomas.Whitten@Sun.COM# profiles under /etc/svc/profile. If the profiles don't really exist, 10011996SThomas.Whitten@Sun.COM# svccfg cleanup will remove the property groups in a later step. 10111996SThomas.Whitten@Sun.COM# 10211996SThomas.Whitten@Sun.COM# Existing generic.xml, inetd_services.xml, and name_service.xml symlinks 10311996SThomas.Whitten@Sun.COM# need to be preserved. 10411996SThomas.Whitten@Sun.COM# 10511996SThomas.Whitten@Sun.COM# Don't process site.xml profile since it is still supported under 10611996SThomas.Whitten@Sun.COM# /var/svc/profile directory. 10711996SThomas.Whitten@Sun.COM# 10811996SThomas.Whitten@Sun.COMfunction preserve_system_profiles { 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate # 11111996SThomas.Whitten@Sun.COM # If /var is a separate fs, return and let Late Import 11211996SThomas.Whitten@Sun.COM # preserves the hashes. 11311996SThomas.Whitten@Sun.COM # 11411996SThomas.Whitten@Sun.COM [ -d "/var/svc/profile" ] || return 1 1150Sstevel@tonic-gate 11611996SThomas.Whitten@Sun.COM # 11711996SThomas.Whitten@Sun.COM # Preserve hashes for the following profiles: generic (two 11811996SThomas.Whitten@Sun.COM # cases) and platform (uname -i, uname -m outputs). 11911996SThomas.Whitten@Sun.COM # 1200Sstevel@tonic-gate gn="var_svc_profile_generic_open_xml" 1210Sstevel@tonic-gate gh=`/usr/bin/svcprop -p ${gn}/md5sum smf/manifest 2>/dev/null` 1220Sstevel@tonic-gate [ $? = 0 ] || gh="" 12311996SThomas.Whitten@Sun.COM gn="etc_svc_profile_generic_open_xml" 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate gln="var_svc_profile_generic_limited_net_xml" 1260Sstevel@tonic-gate glh=`/usr/bin/svcprop -p ${gln}/md5sum smf/manifest 2>/dev/null` 1270Sstevel@tonic-gate [ $? = 0 ] || glh="" 12811996SThomas.Whitten@Sun.COM gln="etc_svc_profile_generic_limited_net_xml" 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate LC_ALL=C pl=`/usr/bin/uname -i | /usr/bin/tr , _` 1310Sstevel@tonic-gate pln="var_svc_profile_platform_${pl}_xml" 1320Sstevel@tonic-gate plh=`/usr/bin/svcprop -p ${pln}/md5sum smf/manifest 2>/dev/null` 1330Sstevel@tonic-gate [ $? = 0 ] || plh="" 13411996SThomas.Whitten@Sun.COM pln="etc_svc_profile_platform_${pl}_xml" 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate LC_ALL=C plm=`/usr/bin/uname -m | /usr/bin/tr , _` 1370Sstevel@tonic-gate if [ $plm != $pl ]; then 1380Sstevel@tonic-gate plmn="var_svc_profile_platform_${plm}_xml" 1390Sstevel@tonic-gate plmh=`/usr/bin/svcprop -p ${plmn}/md5sum smf/manifest \ 1400Sstevel@tonic-gate 2>/dev/null` 1410Sstevel@tonic-gate [ $? = 0 ] || plmh="" 14211996SThomas.Whitten@Sun.COM plmn="etc_svc_profile_platform_${plm}_xml" 1430Sstevel@tonic-gate else 1440Sstevel@tonic-gate plmh="" 1450Sstevel@tonic-gate fi 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate [ -n "$gh" ] && { 1480Sstevel@tonic-gate echo "Preserving generic hash ($gh)." 1490Sstevel@tonic-gate /usr/sbin/svccfg -s smf/manifest addpg ${gn} framework 1500Sstevel@tonic-gate /usr/sbin/svccfg -s smf/manifest setprop ${gn}/md5sum = \ 1510Sstevel@tonic-gate opaque: $gh 15211996SThomas.Whitten@Sun.COM /usr/sbin/svccfg -s smf/manifest setprop ${gn}/manifestfile = \ 15311996SThomas.Whitten@Sun.COM astring: "/etc/svc/profile/generic.xml" 1540Sstevel@tonic-gate } 1550Sstevel@tonic-gate [ -n "$glh" ] && { 1560Sstevel@tonic-gate echo "Preserving generic_limited hash ($glh)." 1570Sstevel@tonic-gate /usr/sbin/svccfg -s smf/manifest addpg ${gln} framework 1580Sstevel@tonic-gate /usr/sbin/svccfg -s smf/manifest setprop ${gln}/md5sum = \ 1590Sstevel@tonic-gate opaque: $glh 16011996SThomas.Whitten@Sun.COM /usr/sbin/svccfg -s smf/manifest setprop ${gln}/manifestfile = \ 16111996SThomas.Whitten@Sun.COM astring: "/etc/svc/profile/generic.xml" 1620Sstevel@tonic-gate } 1630Sstevel@tonic-gate [ -n "$plh" ] && { 1640Sstevel@tonic-gate echo "Preserving platform hash ($plh)." 1650Sstevel@tonic-gate /usr/sbin/svccfg -s smf/manifest addpg $pln framework 1660Sstevel@tonic-gate /usr/sbin/svccfg -s smf/manifest setprop $pln/md5sum = \ 1670Sstevel@tonic-gate opaque: $plh 16811996SThomas.Whitten@Sun.COM /usr/sbin/svccfg -s smf/manifest setprop ${pln}/manifestfile = \ 16911996SThomas.Whitten@Sun.COM astring: "/etc/svc/profile/platform_${pl}_xml" 1700Sstevel@tonic-gate } 1710Sstevel@tonic-gate [ -n "$plmh" ] && { 1720Sstevel@tonic-gate echo "Preserving platform hash ($plmh)." 1730Sstevel@tonic-gate /usr/sbin/svccfg -s smf/manifest addpg $plmn framework 1740Sstevel@tonic-gate /usr/sbin/svccfg -s smf/manifest setprop $plmn/md5sum = \ 1750Sstevel@tonic-gate opaque: $plmh 17611996SThomas.Whitten@Sun.COM /usr/sbin/svccfg -s smf/manifest setprop \ 17711996SThomas.Whitten@Sun.COM ${plmn}/manifestfile = \ 17811996SThomas.Whitten@Sun.COM astring: "/etc/svc/profile/platform_${plm}_xml" 1790Sstevel@tonic-gate } 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate # 18211996SThomas.Whitten@Sun.COM # Move symlinks from /var/svc/profile to /etc/svc/profile 1830Sstevel@tonic-gate # 18411996SThomas.Whitten@Sun.COM generic_prof="/var/svc/profile/generic.xml" 18511996SThomas.Whitten@Sun.COM ns_prof="/var/svc/profile/name_service.xml" 18611996SThomas.Whitten@Sun.COM inetd_prof="/var/svc/profile/inetd_services.xml" 18712418STruong.Q.Nguyen@Sun.COM platform_prof="/var/svc/profile/platform.xml" 18811996SThomas.Whitten@Sun.COM [ -L "$generic_prof" ] && mv $generic_prof /etc/svc/profile/ 18911996SThomas.Whitten@Sun.COM [ -L "$ns_prof" ] && mv $ns_prof /etc/svc/profile/ 19011996SThomas.Whitten@Sun.COM [ -L "$inetd_prof" ] && mv $inetd_prof /etc/svc/profile/ 19112418STruong.Q.Nguyen@Sun.COM [ -L "$platform_prof" ] && mv $platform_prof /etc/svc/profile/ 1920Sstevel@tonic-gate 19311996SThomas.Whitten@Sun.COM return 0 19411996SThomas.Whitten@Sun.COM} 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate# 1970Sstevel@tonic-gate# 2. Manifest import. Application directories first, then 1980Sstevel@tonic-gate# site-specific manifests. 1990Sstevel@tonic-gate# 20011996SThomas.Whitten@Sun.COMfunction import_manifests { 20111996SThomas.Whitten@Sun.COM typeset basedir=$1 202*13112STony.Q.Nguyen@oracle.com typeset console_print=$2 20311996SThomas.Whitten@Sun.COM typeset logf="/etc/svc/volatile/manifest_import.$$" 2040Sstevel@tonic-gate 20511996SThomas.Whitten@Sun.COM rm -f $logf 2060Sstevel@tonic-gate 207*13112STony.Q.Nguyen@oracle.com nonsite_dirs=`/usr/bin/find $basedir/* -name site \ 20811996SThomas.Whitten@Sun.COM -prune -o -type d -print -prune` 2090Sstevel@tonic-gate 21011996SThomas.Whitten@Sun.COM if [ -n "$_MFST_DEBUG" ]; then 21111996SThomas.Whitten@Sun.COM nonsite_manifests=`/lib/svc/bin/mfstscan $nonsite_dirs` 212*13112STony.Q.Nguyen@oracle.com site_manifests=`/lib/svc/bin/mfstscan $basedir/site` 2130Sstevel@tonic-gate 21411996SThomas.Whitten@Sun.COM manifests="$nonsite_manifests $site_manifests" 2150Sstevel@tonic-gate 21611996SThomas.Whitten@Sun.COM echo "Changed manifests to import:" 21711996SThomas.Whitten@Sun.COM for m in $manifests; do echo " $m"; done 21811996SThomas.Whitten@Sun.COM fi 2190Sstevel@tonic-gate 2206035Sstevep # 221*13112STony.Q.Nguyen@oracle.com # Upon boot, attempt to move the repository to tmpfs. 2226035Sstevep # 223*13112STony.Q.Nguyen@oracle.com if [ -z "$ALT_REPOSITORY" -a -z "$ALT_MFST_DIR" ]; then 224*13112STony.Q.Nguyen@oracle.com /usr/sbin/svcadm _smf_repository_switch fast 225*13112STony.Q.Nguyen@oracle.com fi 2266035Sstevep 22711996SThomas.Whitten@Sun.COM # 22811996SThomas.Whitten@Sun.COM # Import the manifests while giving a running display of imports on 22911996SThomas.Whitten@Sun.COM # console, and a final count in the logfile. 23011996SThomas.Whitten@Sun.COM # 231*13112STony.Q.Nguyen@oracle.com dirs="$nonsite_dirs" 232*13112STony.Q.Nguyen@oracle.com [ -d "$basedir/site" ] && dirs="$dirs $basedir/site" 233*13112STony.Q.Nguyen@oracle.com 234*13112STony.Q.Nguyen@oracle.com if [ "$console_print" = "true" ]; then 235*13112STony.Q.Nguyen@oracle.com $X /usr/sbin/svccfg import -p /dev/msglog $dirs > $logf 2>&1 236*13112STony.Q.Nguyen@oracle.com else 237*13112STony.Q.Nguyen@oracle.com $X /usr/sbin/svccfg import $dirs > $logf 2>&1 238*13112STony.Q.Nguyen@oracle.com fi 2390Sstevel@tonic-gate 24011996SThomas.Whitten@Sun.COM grep "Loaded .*. smf(5) service descriptions" $logf > /dev/null 2>&1 24111996SThomas.Whitten@Sun.COM if [ $? -eq 0 ]; then 24211996SThomas.Whitten@Sun.COM activity=true 2436035Sstevep fi 2446035Sstevep 24511996SThomas.Whitten@Sun.COM if [ -s $logf ]; then 24611996SThomas.Whitten@Sun.COM grep "smf(5) service descriptions failed to load" $logf > /dev/null 2>&1 24711996SThomas.Whitten@Sun.COM failures=$? 24811996SThomas.Whitten@Sun.COM if [ $failures -eq 0 ]; then 24911996SThomas.Whitten@Sun.COM echo "svccfg warnings:" 25011996SThomas.Whitten@Sun.COM fi 25111996SThomas.Whitten@Sun.COM cat $logf 2520Sstevel@tonic-gate 253*13112STony.Q.Nguyen@oracle.com if [ $failures -eq 0 -a "$console_print" = "true" ]; then 25411996SThomas.Whitten@Sun.COM msg="svccfg import warnings. See" 25511996SThomas.Whitten@Sun.COM msg="$msg /var/svc/log/system-manifest-import:default.log ." 25611996SThomas.Whitten@Sun.COM echo $msg > /dev/msglog 25711996SThomas.Whitten@Sun.COM fi 2580Sstevel@tonic-gate fi 25911996SThomas.Whitten@Sun.COM rm -f $logf 26011996SThomas.Whitten@Sun.COM} 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate# 2630Sstevel@tonic-gate# 3. Profile application. We must create the platform profile upon 2640Sstevel@tonic-gate# first boot, as we may be a diskless client of a platform or 2650Sstevel@tonic-gate# architecture distinct from our NFS server. 2660Sstevel@tonic-gate# 26711996SThomas.Whitten@Sun.COM# Generic and platform profiles are only supported in /etc. 26811996SThomas.Whitten@Sun.COM# 26911996SThomas.Whitten@Sun.COMfunction apply_profile { 27011996SThomas.Whitten@Sun.COM # 27111996SThomas.Whitten@Sun.COM # If smf/manifest doesn't have any profile under /etc/var/profile, 27211996SThomas.Whitten@Sun.COM # this is very likely an import after upgrade so call 27311996SThomas.Whitten@Sun.COM # preserve_system_profiles in that case. 27411996SThomas.Whitten@Sun.COM # 27511996SThomas.Whitten@Sun.COM LC_ALL=C pl=`/usr/bin/uname -i | /usr/bin/tr , _` 27611996SThomas.Whitten@Sun.COM pln="etc_svc_profile_platform_${pl}_xml" 2770Sstevel@tonic-gate 27811996SThomas.Whitten@Sun.COM LC_ALL=C plm=`/usr/bin/uname -m | /usr/bin/tr , _` 27911996SThomas.Whitten@Sun.COM [ $plm != $pl ] && plmn="etc_svc_profile_platform_${plm}_xml" 2800Sstevel@tonic-gate 28111996SThomas.Whitten@Sun.COM preserve_profiles=1 28211996SThomas.Whitten@Sun.COM for prof in $pln $plmn etc_svc_profile_platform_none_xml \ 28311996SThomas.Whitten@Sun.COM etc_svc_profile_generic_limited_net_xml \ 28411996SThomas.Whitten@Sun.COM etc_svc_profile_generic_open_xml; do 28511996SThomas.Whitten@Sun.COM if /usr/bin/svcprop -p $prof smf/manifest >/dev/null 2>&1 28611996SThomas.Whitten@Sun.COM then 28711996SThomas.Whitten@Sun.COM preserve_profiles=0 28811996SThomas.Whitten@Sun.COM break 28911996SThomas.Whitten@Sun.COM fi 29011996SThomas.Whitten@Sun.COM done 29111996SThomas.Whitten@Sun.COM 29211996SThomas.Whitten@Sun.COM if [ $preserve_profiles -eq 1 ]; then 29311996SThomas.Whitten@Sun.COM echo "/etc/svc system profiles not found: upgrade system profiles" 29411996SThomas.Whitten@Sun.COM preserve_system_profiles || return 2950Sstevel@tonic-gate fi 2960Sstevel@tonic-gate 29711996SThomas.Whitten@Sun.COM typeset prefix="/etc/svc/profile" 29811996SThomas.Whitten@Sun.COM svccfg_apply $prefix/generic.xml 29911996SThomas.Whitten@Sun.COM if [ ! -f $prefix/platform.xml ]; then 30011996SThomas.Whitten@Sun.COM this_karch=`uname -m` 30111996SThomas.Whitten@Sun.COM this_plat=`uname -i` 3020Sstevel@tonic-gate 30311996SThomas.Whitten@Sun.COM if [ -f $prefix/platform_$this_plat.xml ]; then 30411996SThomas.Whitten@Sun.COM platform_profile=platform_$this_plat.xml 30511996SThomas.Whitten@Sun.COM elif [ -f $prefix/platform_$this_karch.xml ]; then 30611996SThomas.Whitten@Sun.COM platform_profile=platform_$this_karch.xml 30711996SThomas.Whitten@Sun.COM else 30811996SThomas.Whitten@Sun.COM platform_profile=platform_none.xml 30911996SThomas.Whitten@Sun.COM fi 31011996SThomas.Whitten@Sun.COM 31111996SThomas.Whitten@Sun.COM ln -s $platform_profile $prefix/platform.xml 31211996SThomas.Whitten@Sun.COM fi 31311996SThomas.Whitten@Sun.COM 31411996SThomas.Whitten@Sun.COM svccfg_apply $prefix/platform.xml 31511996SThomas.Whitten@Sun.COM} 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate# 3180Sstevel@tonic-gate# 4. Upgrade handling. The upgrade file generally consists of a series 3190Sstevel@tonic-gate# of svcadm(1M) and svccfg(1M) commands. 3200Sstevel@tonic-gate# 32111996SThomas.Whitten@Sun.COMfunction handle_upgrade { 32211996SThomas.Whitten@Sun.COM 32311996SThomas.Whitten@Sun.COM [ -f /var/svc/profile/upgrade ] && activity=true 32411996SThomas.Whitten@Sun.COM 32511996SThomas.Whitten@Sun.COM ( 32611996SThomas.Whitten@Sun.COM unset SVCCFG_CHECKHASH 3270Sstevel@tonic-gate 32811996SThomas.Whitten@Sun.COM if [ -f /var/svc/profile/upgrade ]; then 32911996SThomas.Whitten@Sun.COM . /var/svc/profile/upgrade 3300Sstevel@tonic-gate 33111996SThomas.Whitten@Sun.COM /usr/bin/mv /var/svc/profile/upgrade \ 33211996SThomas.Whitten@Sun.COM /var/svc/profile/upgrade.app.`date +\%Y\%m\%d\%H\%M\%S` 33311996SThomas.Whitten@Sun.COM fi 3345895Syz147064 33511996SThomas.Whitten@Sun.COM # 33611996SThomas.Whitten@Sun.COM # Rename the datalink upgrade script file. This script is used in the 33711996SThomas.Whitten@Sun.COM # network/physical service to upgrade datalink configuration, but 33811996SThomas.Whitten@Sun.COM # the file cannot be renamed until now (when the file system becomes 33911996SThomas.Whitten@Sun.COM # read-write). 34011996SThomas.Whitten@Sun.COM # 34111996SThomas.Whitten@Sun.COM datalink_script=/var/svc/profile/upgrade_datalink 34211996SThomas.Whitten@Sun.COM if [ -f "${datalink_script}" ]; then 34311996SThomas.Whitten@Sun.COM /usr/bin/mv "${datalink_script}" \ 34411996SThomas.Whitten@Sun.COM "${datalink_script}".app.`date +\%Y\%m\%d\%H\%M\%S` 34511996SThomas.Whitten@Sun.COM fi 34611996SThomas.Whitten@Sun.COM ) 34711996SThomas.Whitten@Sun.COM} 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate# 35012418STruong.Q.Nguyen@Sun.COM# 5. Giving administrator the final say, apply site.xml profile and profiles 35112418STruong.Q.Nguyen@Sun.COM# under /etc/svc/profile/site directory. 3520Sstevel@tonic-gate# 35311996SThomas.Whitten@Sun.COMfunction apply_site_profile { 354*13112STony.Q.Nguyen@oracle.com typeset prefix="$1" 35511996SThomas.Whitten@Sun.COM [ -f $prefix/site.xml ] && svccfg_apply $prefix/site.xml 35612418STruong.Q.Nguyen@Sun.COM 357*13112STony.Q.Nguyen@oracle.com if [ -d $PROFILE_DIR_SITE -a "$1" = "/etc/svc/profile" ]; then 35812418STruong.Q.Nguyen@Sun.COM svccfg_apply $PROFILE_DIR_SITE 35912418STruong.Q.Nguyen@Sun.COM fi 36011996SThomas.Whitten@Sun.COM} 36111996SThomas.Whitten@Sun.COM 36211996SThomas.Whitten@Sun.COM# 36311996SThomas.Whitten@Sun.COM# 0b Cleanup deathrow 36411996SThomas.Whitten@Sun.COM# 36511996SThomas.Whitten@Sun.COMif [ "$early" = "false" ];then 36611996SThomas.Whitten@Sun.COM deathrow=/etc/svc/deathrow 36711996SThomas.Whitten@Sun.COM if [ -s $deathrow ];then 36811996SThomas.Whitten@Sun.COM # 36911996SThomas.Whitten@Sun.COM # svc.startd has unconfigured the services found in deathrow, 37011996SThomas.Whitten@Sun.COM # clean them now. 37111996SThomas.Whitten@Sun.COM # 37211996SThomas.Whitten@Sun.COM while read fmri mfst pkgname; do 37311996SThomas.Whitten@Sun.COM # Delete services and instances from the deathrow file. 37411996SThomas.Whitten@Sun.COM /usr/sbin/svccfg delete -f $fmri >/dev/null 2>&1 37511996SThomas.Whitten@Sun.COM # Remove deathrow manifest hash. 37611996SThomas.Whitten@Sun.COM /usr/sbin/svccfg delhash -d $mfst >/dev/null 2>&1 37711996SThomas.Whitten@Sun.COM done < $deathrow 37811996SThomas.Whitten@Sun.COM /usr/bin/mv $deathrow $deathrow.old 37911996SThomas.Whitten@Sun.COM fi 3800Sstevel@tonic-gatefi 3810Sstevel@tonic-gate 38211996SThomas.Whitten@Sun.COMSVCCFG_CHECKHASH=1 export SVCCFG_CHECKHASH 38311996SThomas.Whitten@Sun.COM 38411996SThomas.Whitten@Sun.COM# 38511996SThomas.Whitten@Sun.COM# 0c Clean up repository 38611996SThomas.Whitten@Sun.COM# 38711996SThomas.Whitten@Sun.COMif [ "$early" = "false" ]; then 38811996SThomas.Whitten@Sun.COM if [ -z "$X" ] && /usr/bin/svcprop smf/manifest 2>/dev/null | 38911996SThomas.Whitten@Sun.COM /usr/bin/grep '^ar_svc_[^/]*/md5sum opaque ' >/dev/null 39011996SThomas.Whitten@Sun.COM then 39111996SThomas.Whitten@Sun.COM set -- ` 39211996SThomas.Whitten@Sun.COM /usr/bin/svcprop smf/manifest 2>/dev/null | 39311996SThomas.Whitten@Sun.COM /usr/bin/grep '^ar_svc[^/]*/md5sum opaque ' | 39411996SThomas.Whitten@Sun.COM /usr/bin/tr '/' ' ' | 39511996SThomas.Whitten@Sun.COM while read pg prop type value; do 39611996SThomas.Whitten@Sun.COM echo "$pg/$value" 39711996SThomas.Whitten@Sun.COM done 39811996SThomas.Whitten@Sun.COM ` 39911996SThomas.Whitten@Sun.COM backup=`echo "$#/$#" | sed 's/.//g'` 40011996SThomas.Whitten@Sun.COM fwidth=`echo "$#\c" | wc -c` 40111996SThomas.Whitten@Sun.COM 40211996SThomas.Whitten@Sun.COM echo "Converting obsolete repository entries: \c" > /dev/msglog 40311996SThomas.Whitten@Sun.COM i=1; n=$# 40411996SThomas.Whitten@Sun.COM while [ $# -gt 0 ]; do 40511996SThomas.Whitten@Sun.COM printf "%${fwidth}s/%${fwidth}s" $i $n > /dev/msglog 40611996SThomas.Whitten@Sun.COM echo $1 | sed 's:/: :' | ( 40711996SThomas.Whitten@Sun.COM read pg value 40811996SThomas.Whitten@Sun.COM 40911996SThomas.Whitten@Sun.COM (echo "select /smf/manifest"; echo "delpg v$pg") | 41011996SThomas.Whitten@Sun.COM /usr/sbin/svccfg 2>/dev/null >/dev/null 41111996SThomas.Whitten@Sun.COM (echo "select /smf/manifest"; echo "delpg $pg") | 41211996SThomas.Whitten@Sun.COM /usr/sbin/svccfg 2>/dev/null >/dev/null 41311996SThomas.Whitten@Sun.COM (echo "select /smf/manifest"; 41411996SThomas.Whitten@Sun.COM echo "addpg v$pg framework") | 41511996SThomas.Whitten@Sun.COM /usr/sbin/svccfg 2>/dev/null >/dev/null 41611996SThomas.Whitten@Sun.COM (echo "select /smf/manifest"; 41711996SThomas.Whitten@Sun.COM echo "setprop v$pg/md5sum = opaque: $value") | 41811996SThomas.Whitten@Sun.COM /usr/sbin/svccfg 2>/dev/null >/dev/null 41911996SThomas.Whitten@Sun.COM ) 42011996SThomas.Whitten@Sun.COM i=`expr $i + 1` 42111996SThomas.Whitten@Sun.COM shift 42211996SThomas.Whitten@Sun.COM echo "$backup\c" > /dev/msglog 42311996SThomas.Whitten@Sun.COM done 42411996SThomas.Whitten@Sun.COM echo > /dev/msglog 42511996SThomas.Whitten@Sun.COM echo "Converted $n obsolete repository entries" 42611996SThomas.Whitten@Sun.COM activity=true 42711996SThomas.Whitten@Sun.COM fi 42811996SThomas.Whitten@Sun.COM 42911996SThomas.Whitten@Sun.COMfi 43011996SThomas.Whitten@Sun.COM 43111996SThomas.Whitten@Sun.COM# 432*13112STony.Q.Nguyen@oracle.com# If the alternate repository and directory are specified, simply set 433*13112STony.Q.Nguyen@oracle.com# SVCCFG_REPOSITORY env, run svccfg import on the given directory, and 434*13112STony.Q.Nguyen@oracle.com# exit. 435*13112STony.Q.Nguyen@oracle.com# 436*13112STony.Q.Nguyen@oracle.comif [ -n "$ALT_REPOSITORY" -a -n "$ALT_MFST_DIR" ]; then 437*13112STony.Q.Nguyen@oracle.com SVCCFG_REPOSITORY=$ALT_REPOSITORY export SVCCFG_REPOSITORY 438*13112STony.Q.Nguyen@oracle.com import_manifests "$ALT_MFST_DIR" false 439*13112STony.Q.Nguyen@oracle.com unset SVCCFG_REPOSITORY 440*13112STony.Q.Nguyen@oracle.com exit 0 441*13112STony.Q.Nguyen@oracle.comfi 442*13112STony.Q.Nguyen@oracle.com 443*13112STony.Q.Nguyen@oracle.com# 44411996SThomas.Whitten@Sun.COM# Call import and apply profiles here 44511996SThomas.Whitten@Sun.COM# 44611996SThomas.Whitten@Sun.COMif [ "$early" = "true" ]; then 447*13112STony.Q.Nguyen@oracle.com import_manifests "/lib/svc/manifest" true 44811996SThomas.Whitten@Sun.COM apply_profile 449*13112STony.Q.Nguyen@oracle.com apply_site_profile "/etc/svc/profile" 45011996SThomas.Whitten@Sun.COMelse 45111996SThomas.Whitten@Sun.COM # 452*13112STony.Q.Nguyen@oracle.com # Process both /lib/svc/manifest and /var/svc/manifest 45311996SThomas.Whitten@Sun.COM # during late manifest-import 45411996SThomas.Whitten@Sun.COM # 45511996SThomas.Whitten@Sun.COM # First import the manifests 45611996SThomas.Whitten@Sun.COM # 457*13112STony.Q.Nguyen@oracle.com import_manifests "/lib/svc/manifest" true 458*13112STony.Q.Nguyen@oracle.com import_manifests "/var/svc/manifest" true 45911996SThomas.Whitten@Sun.COM 46011996SThomas.Whitten@Sun.COM # 46111996SThomas.Whitten@Sun.COM # Apply profiles 46211996SThomas.Whitten@Sun.COM # 46311996SThomas.Whitten@Sun.COM apply_profile 464*13112STony.Q.Nguyen@oracle.com apply_site_profile "/etc/svc/profile" 46511996SThomas.Whitten@Sun.COM 46611996SThomas.Whitten@Sun.COM # 46711996SThomas.Whitten@Sun.COM # Run the upgrade script 46811996SThomas.Whitten@Sun.COM # 46911996SThomas.Whitten@Sun.COM handle_upgrade 470*13112STony.Q.Nguyen@oracle.com apply_site_profile "/var/svc/profile" 47111996SThomas.Whitten@Sun.COMfi 47211996SThomas.Whitten@Sun.COM 47311996SThomas.Whitten@Sun.COM 4740Sstevel@tonic-gate# 4750Sstevel@tonic-gate# 6. Final actions. 4760Sstevel@tonic-gate# 4770Sstevel@tonic-gate 4780Sstevel@tonic-gateif $activity; then 47911996SThomas.Whitten@Sun.COM /usr/sbin/svcadm _smf_backup "manifest_import" || true 4800Sstevel@tonic-gatefi 4810Sstevel@tonic-gate 48211996SThomas.Whitten@Sun.COM# 48311996SThomas.Whitten@Sun.COM# If the filesystem is NOT read only then move the repo back to perm 48411996SThomas.Whitten@Sun.COM# There is no care wether the switch was made or not, but just want 48511996SThomas.Whitten@Sun.COM# to move it. If it is already perm this does not affect anything 48611996SThomas.Whitten@Sun.COM# at least on the surface. REALLY want to improve on this... 48711996SThomas.Whitten@Sun.COM# 48811996SThomas.Whitten@Sun.COMtouch /etc/svc/smf_rwtest.$$ > /dev/null 2>&1 48911996SThomas.Whitten@Sun.COMif [ $? -eq 0 ]; then 49011996SThomas.Whitten@Sun.COM rm -f /etc/svc/smf_rwtest.$$ 49111996SThomas.Whitten@Sun.COM /usr/sbin/svcadm _smf_repository_switch perm || { \ 49211996SThomas.Whitten@Sun.COM echo "Repository switch back operation failed, \c" 49311996SThomas.Whitten@Sun.COM echo "please check the system log for the" 49411996SThomas.Whitten@Sun.COM echo "possible fatal error messages." 49511996SThomas.Whitten@Sun.COM exit $SMF_EXIT_ERR_FATAL 49611996SThomas.Whitten@Sun.COM } 49711996SThomas.Whitten@Sun.COMfi 49811996SThomas.Whitten@Sun.COM 49911996SThomas.Whitten@Sun.COMif $activity; then 50011996SThomas.Whitten@Sun.COM /usr/sbin/svccfg cleanup | /usr/bin/tee /dev/msglog 50111996SThomas.Whitten@Sun.COMelse 50211996SThomas.Whitten@Sun.COM cleanup_needwork 50311996SThomas.Whitten@Sun.COM if [ $? -ne 0 ]; then 50411996SThomas.Whitten@Sun.COM /usr/sbin/svccfg cleanup -a | /usr/bin/tee /dev/msglog 50511996SThomas.Whitten@Sun.COM fi 50611996SThomas.Whitten@Sun.COMfi 50710461SSean.Wilcox@Sun.COM 5080Sstevel@tonic-gateexit 0 509