xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.lib/inetd/inetd-upgrade.sh (revision 11996:91b62f7b8186)
10Sstevel@tonic-gate#! /usr/bin/sh
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
64352Scarlsonj# Common Development and Distribution License (the "License").
74352Scarlsonj# 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#
220Sstevel@tonic-gate#
23*11996SThomas.Whitten@Sun.COM# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate# Use is subject to license terms.
250Sstevel@tonic-gate#
260Sstevel@tonic-gate
270Sstevel@tonic-gate# Start by cleaning out obsolete instances.  For each one that
280Sstevel@tonic-gate# exists in the repository, remove it.
290Sstevel@tonic-gateinetd_obsolete_instances="
300Sstevel@tonic-gate	network/nfs/rquota:ticlts
310Sstevel@tonic-gate	network/nfs/rquota:udp
320Sstevel@tonic-gate	network/rexec:tcp
330Sstevel@tonic-gate	network/rexec:tcp6
340Sstevel@tonic-gate	network/rpc/gss:ticotsord
350Sstevel@tonic-gate	network/rpc/mdcomm:tcp
360Sstevel@tonic-gate	network/rpc/mdcomm:tcp6
370Sstevel@tonic-gate	network/rpc/meta:tcp
380Sstevel@tonic-gate	network/rpc/meta:tcp6
390Sstevel@tonic-gate	network/rpc/metamed:tcp
400Sstevel@tonic-gate	network/rpc/metamed:tcp6
410Sstevel@tonic-gate	network/rpc/metamh:tcp
420Sstevel@tonic-gate	network/rpc/metamh:tcp6
430Sstevel@tonic-gate	network/rpc/rex:tcp
440Sstevel@tonic-gate	network/rpc/rstat:ticlts
450Sstevel@tonic-gate	network/rpc/rstat:udp
460Sstevel@tonic-gate	network/rpc/rstat:udp6
470Sstevel@tonic-gate	network/rpc/rusers:udp
480Sstevel@tonic-gate	network/rpc/rusers:udp6
490Sstevel@tonic-gate	network/rpc/rusers:ticlts
500Sstevel@tonic-gate	network/rpc/rusers:tcp
510Sstevel@tonic-gate	network/rpc/rusers:tcp6
520Sstevel@tonic-gate	network/rpc/rusers:ticotsord
530Sstevel@tonic-gate	network/rpc/rusers:ticots
540Sstevel@tonic-gate	network/rpc/spray:ticlts
550Sstevel@tonic-gate	network/rpc/spray:udp
560Sstevel@tonic-gate	network/rpc/spray:udp6
570Sstevel@tonic-gate	network/rpc/wall:ticlts
580Sstevel@tonic-gate	network/rpc/wall:udp
590Sstevel@tonic-gate	network/rpc/wall:udp6
600Sstevel@tonic-gate	network/security/krb5_prop:tcp
610Sstevel@tonic-gate	network/security/ktkt_warn:ticotsord
620Sstevel@tonic-gate	network/shell:tcp
630Sstevel@tonic-gate	network/shell:tcp6only
640Sstevel@tonic-gate	platform/sun4u/dcs:tcp
650Sstevel@tonic-gate	platform/sun4u/dcs:tcp6
660Sstevel@tonic-gate"
670Sstevel@tonic-gate
680Sstevel@tonic-gatefor i in $inetd_obsolete_instances; do
690Sstevel@tonic-gate	enable=`svcprop -p general/enabled $i`
700Sstevel@tonic-gate	if [ $? = 0 ]; then
710Sstevel@tonic-gate		# Instance found, so disable and delete
720Sstevel@tonic-gate		svcadm disable $i
730Sstevel@tonic-gate		svccfg delete $i
740Sstevel@tonic-gate		if [ "$enable" = "true" ]; then
750Sstevel@tonic-gate			# Instance was enabled, so enable the replacement.
760Sstevel@tonic-gate			# We must do this here because the profile which
770Sstevel@tonic-gate			# normally enables these is only applied on first
780Sstevel@tonic-gate			# install of smf.
790Sstevel@tonic-gate			s=`echo $i | cut -f1 -d:`
800Sstevel@tonic-gate			svcadm enable $s:default
810Sstevel@tonic-gate		fi
820Sstevel@tonic-gate	fi
830Sstevel@tonic-gatedone
840Sstevel@tonic-gate
850Sstevel@tonic-gate
860Sstevel@tonic-gate# The Following blocks of code cause the inetconv generated services to be
870Sstevel@tonic-gate# re-generated, so that the latest inetconv modifications are applied to all
880Sstevel@tonic-gate# services generated by it.
890Sstevel@tonic-gate
900Sstevel@tonic-gateinetdconf_entries_file=/tmp/iconf_entries.$$
910Sstevel@tonic-gate
920Sstevel@tonic-gate# Create sed script that prints out inetd.conf src line from inetconv generated
930Sstevel@tonic-gate# manifest.
940Sstevel@tonic-gatecat <<EOF > /tmp/inetd-upgrade.$$.sed
950Sstevel@tonic-gate/propval name='source_line'/{
960Sstevel@tonic-gaten
970Sstevel@tonic-gates/'//g
980Sstevel@tonic-gatep
990Sstevel@tonic-gate}
1000Sstevel@tonic-gate/from the inetd.conf(4) format line/{
1010Sstevel@tonic-gaten
1020Sstevel@tonic-gatep
1030Sstevel@tonic-gate}
1040Sstevel@tonic-gateEOF
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate# get list of inetconv generated manifests
107*11996SThomas.Whitten@Sun.COMinetconv_manifests=`/usr/bin/find /lib/svc/manifest -type f -name \*.xml | \
1080Sstevel@tonic-gate    /usr/bin/xargs /usr/bin/grep -l "Generated by inetconv"`
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate# For each inetconv generated manifest determine the instances that should
1110Sstevel@tonic-gate# be disabled when the new manifests are imported, and generate a file with
1120Sstevel@tonic-gate# the inetd.conf entries from all the manifests for consumption by inetconv.
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate> $inetdconf_entries_file
1150Sstevel@tonic-gateinetconv_services=""
1160Sstevel@tonic-gateinstances_to_disable=""
1170Sstevel@tonic-gate
1180Sstevel@tonic-gatefor manifest in $inetconv_manifests; do
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate	manifest_instances=`/usr/sbin/svccfg inventory $manifest | \
1210Sstevel@tonic-gate	    egrep "svc:/.*:.*"`
1220Sstevel@tonic-gate	manifest_service=`/usr/sbin/svccfg inventory $manifest | \
1230Sstevel@tonic-gate	    egrep -v "svc:/.*:.*"`
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate	instance_disabled=""
1260Sstevel@tonic-gate	default_enabled=""
1270Sstevel@tonic-gate	enabled=""
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate	for instance in $manifest_instances; do
1300Sstevel@tonic-gate		# if the instance doesn't exist in the repository skip it
1310Sstevel@tonic-gate		svcprop -q $instance
1320Sstevel@tonic-gate		if [ $? -ne 0 ]; then
1330Sstevel@tonic-gate			continue
1340Sstevel@tonic-gate		fi
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate		enabled=`svcprop -p general/enabled $instance`
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate		default_instance=`echo $instance | grep ":default"`
1390Sstevel@tonic-gate		if [ "$default_instance" != "" ]; then
1400Sstevel@tonic-gate			default_enabled=$enabled
1410Sstevel@tonic-gate		else
1420Sstevel@tonic-gate			# add all non-default instances to disable list
1430Sstevel@tonic-gate			instances_to_disable="$instances_to_disable \
1440Sstevel@tonic-gate			    $instance"
1450Sstevel@tonic-gate			if [ "$enabled" != "true" ]; then
1460Sstevel@tonic-gate				instance_disabled="true"
1470Sstevel@tonic-gate			fi
1480Sstevel@tonic-gate		fi
1490Sstevel@tonic-gate	done
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate	# if none of the manifest's instances existed, skip this manifest
1520Sstevel@tonic-gate	if [ "$enabled" = "" ]; then
1530Sstevel@tonic-gate		continue
1540Sstevel@tonic-gate	fi
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate	# If the default instance existed and was disabled, or if didn't
1570Sstevel@tonic-gate	# exist and one of the other instances was disabled, add the default
1580Sstevel@tonic-gate	# to the list of instances to disable.
1590Sstevel@tonic-gate	if [ "$default_enabled" = "false" -o "$default_enabled" = "" -a \
1600Sstevel@tonic-gate	    "$instance_disabled" = "true" ]; then
1610Sstevel@tonic-gate		instances_to_disable="$instances_to_disable \
1620Sstevel@tonic-gate		    $manifest_service:default"
1630Sstevel@tonic-gate	fi
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate	# add the manifest's inetd.conf src line to file for inetconv
1660Sstevel@tonic-gate	sed -n -f /tmp/inetd-upgrade.$$.sed $manifest >> \
1670Sstevel@tonic-gate	    $inetdconf_entries_file
1680Sstevel@tonic-gatedone
1690Sstevel@tonic-gate
1700Sstevel@tonic-gaterm /tmp/inetd-upgrade.$$.sed
1710Sstevel@tonic-gate
1724352Scarlsonj# Check whether we've ever run inetconv before by looking for the
1734352Scarlsonj# configuration file hash.  If we haven't run it before, then we need
1744352Scarlsonj# to enable services based on inetd.conf.  If we have, then the
1754352Scarlsonj# repository is authoritative.  `unimported' will be 0 if the hash exists.
1764352Scarlsonjsvcprop -qp hash svc:/network/inetd:default
1774352Scarlsonjunimported=$?
1784352Scarlsonj
1790Sstevel@tonic-gate# Run inetconv on generated file, overwriting previous manifests and values
1800Sstevel@tonic-gate# in repository.
1810Sstevel@tonic-gate/usr/sbin/inetconv -f -i $inetdconf_entries_file
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate# disable the necessary instances
1840Sstevel@tonic-gatefor inst in $instances_to_disable; do
1850Sstevel@tonic-gate	svcadm disable $inst
1860Sstevel@tonic-gatedone
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate
1894352Scarlsonj# If there is a saved config file from upgrade, use it to enable services,
1904352Scarlsonj# but only if we're coming from a release that didn't have SMF.
1910Sstevel@tonic-gatesaved_config=/etc/inet/inetd.conf.preupgrade
1924352Scarlsonjif [ $unimported -ne 0 -a -f $saved_config ]; then
1934352Scarlsonj	/usr/sbin/inetconv -e -i $saved_config
1940Sstevel@tonic-gatefi
1950Sstevel@tonic-gate
1960Sstevel@tonic-gate# Now convert the remaining entries in inetd.conf to service manifests
1970Sstevel@tonic-gate/usr/sbin/inetconv
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate# Now disable myself as the upgrade is done
2000Sstevel@tonic-gatesvcadm disable network/inetd-upgrade
2010Sstevel@tonic-gate
2020Sstevel@tonic-gateexit 0
203