17c478bd9Sstevel@tonic-gate#! /usr/bin/sh
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
6781c49dbScarlsonj# Common Development and Distribution License (the "License").
7781c49dbScarlsonj# 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#
227c478bd9Sstevel@tonic-gate#
239444c26fSTom Whitten# Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate# Use is subject to license terms.
257c478bd9Sstevel@tonic-gate#
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate# Start by cleaning out obsolete instances.  For each one that
287c478bd9Sstevel@tonic-gate# exists in the repository, remove it.
297c478bd9Sstevel@tonic-gateinetd_obsolete_instances="
307c478bd9Sstevel@tonic-gate	network/nfs/rquota:ticlts
317c478bd9Sstevel@tonic-gate	network/nfs/rquota:udp
327c478bd9Sstevel@tonic-gate	network/rexec:tcp
337c478bd9Sstevel@tonic-gate	network/rexec:tcp6
347c478bd9Sstevel@tonic-gate	network/rpc/gss:ticotsord
357c478bd9Sstevel@tonic-gate	network/rpc/mdcomm:tcp
367c478bd9Sstevel@tonic-gate	network/rpc/mdcomm:tcp6
377c478bd9Sstevel@tonic-gate	network/rpc/meta:tcp
387c478bd9Sstevel@tonic-gate	network/rpc/meta:tcp6
397c478bd9Sstevel@tonic-gate	network/rpc/metamed:tcp
407c478bd9Sstevel@tonic-gate	network/rpc/metamed:tcp6
417c478bd9Sstevel@tonic-gate	network/rpc/metamh:tcp
427c478bd9Sstevel@tonic-gate	network/rpc/metamh:tcp6
437c478bd9Sstevel@tonic-gate	network/rpc/rex:tcp
447c478bd9Sstevel@tonic-gate	network/rpc/rstat:ticlts
457c478bd9Sstevel@tonic-gate	network/rpc/rstat:udp
467c478bd9Sstevel@tonic-gate	network/rpc/rstat:udp6
477c478bd9Sstevel@tonic-gate	network/rpc/rusers:udp
487c478bd9Sstevel@tonic-gate	network/rpc/rusers:udp6
497c478bd9Sstevel@tonic-gate	network/rpc/rusers:ticlts
507c478bd9Sstevel@tonic-gate	network/rpc/rusers:tcp
517c478bd9Sstevel@tonic-gate	network/rpc/rusers:tcp6
527c478bd9Sstevel@tonic-gate	network/rpc/rusers:ticotsord
537c478bd9Sstevel@tonic-gate	network/rpc/rusers:ticots
547c478bd9Sstevel@tonic-gate	network/rpc/spray:ticlts
557c478bd9Sstevel@tonic-gate	network/rpc/spray:udp
567c478bd9Sstevel@tonic-gate	network/rpc/spray:udp6
577c478bd9Sstevel@tonic-gate	network/rpc/wall:ticlts
587c478bd9Sstevel@tonic-gate	network/rpc/wall:udp
597c478bd9Sstevel@tonic-gate	network/rpc/wall:udp6
607c478bd9Sstevel@tonic-gate	network/security/krb5_prop:tcp
617c478bd9Sstevel@tonic-gate	network/security/ktkt_warn:ticotsord
627c478bd9Sstevel@tonic-gate	network/shell:tcp
637c478bd9Sstevel@tonic-gate	network/shell:tcp6only
647c478bd9Sstevel@tonic-gate	platform/sun4u/dcs:tcp
657c478bd9Sstevel@tonic-gate	platform/sun4u/dcs:tcp6
667c478bd9Sstevel@tonic-gate"
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gatefor i in $inetd_obsolete_instances; do
697c478bd9Sstevel@tonic-gate	enable=`svcprop -p general/enabled $i`
707c478bd9Sstevel@tonic-gate	if [ $? = 0 ]; then
717c478bd9Sstevel@tonic-gate		# Instance found, so disable and delete
727c478bd9Sstevel@tonic-gate		svcadm disable $i
737c478bd9Sstevel@tonic-gate		svccfg delete $i
747c478bd9Sstevel@tonic-gate		if [ "$enable" = "true" ]; then
757c478bd9Sstevel@tonic-gate			# Instance was enabled, so enable the replacement.
767c478bd9Sstevel@tonic-gate			# We must do this here because the profile which
777c478bd9Sstevel@tonic-gate			# normally enables these is only applied on first
787c478bd9Sstevel@tonic-gate			# install of smf.
797c478bd9Sstevel@tonic-gate			s=`echo $i | cut -f1 -d:`
807c478bd9Sstevel@tonic-gate			svcadm enable $s:default
817c478bd9Sstevel@tonic-gate		fi
827c478bd9Sstevel@tonic-gate	fi
837c478bd9Sstevel@tonic-gatedone
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate# The Following blocks of code cause the inetconv generated services to be
877c478bd9Sstevel@tonic-gate# re-generated, so that the latest inetconv modifications are applied to all
887c478bd9Sstevel@tonic-gate# services generated by it.
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gateinetdconf_entries_file=/tmp/iconf_entries.$$
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate# Create sed script that prints out inetd.conf src line from inetconv generated
937c478bd9Sstevel@tonic-gate# manifest.
947c478bd9Sstevel@tonic-gatecat <<EOF > /tmp/inetd-upgrade.$$.sed
957c478bd9Sstevel@tonic-gate/propval name='source_line'/{
967c478bd9Sstevel@tonic-gaten
977c478bd9Sstevel@tonic-gates/'//g
987c478bd9Sstevel@tonic-gatep
997c478bd9Sstevel@tonic-gate}
100*bbf21555SRichard Lowe/from the inetd.conf(5) format line/{
1017c478bd9Sstevel@tonic-gaten
1027c478bd9Sstevel@tonic-gatep
1037c478bd9Sstevel@tonic-gate}
1047c478bd9Sstevel@tonic-gateEOF
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate# get list of inetconv generated manifests
1079444c26fSTom Whitteninetconv_manifests=`/usr/bin/find /lib/svc/manifest -type f -name \*.xml | \
1087c478bd9Sstevel@tonic-gate    /usr/bin/xargs /usr/bin/grep -l "Generated by inetconv"`
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate# For each inetconv generated manifest determine the instances that should
1117c478bd9Sstevel@tonic-gate# be disabled when the new manifests are imported, and generate a file with
1127c478bd9Sstevel@tonic-gate# the inetd.conf entries from all the manifests for consumption by inetconv.
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate> $inetdconf_entries_file
1157c478bd9Sstevel@tonic-gateinetconv_services=""
1167c478bd9Sstevel@tonic-gateinstances_to_disable=""
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gatefor manifest in $inetconv_manifests; do
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate	manifest_instances=`/usr/sbin/svccfg inventory $manifest | \
1217c478bd9Sstevel@tonic-gate	    egrep "svc:/.*:.*"`
1227c478bd9Sstevel@tonic-gate	manifest_service=`/usr/sbin/svccfg inventory $manifest | \
1237c478bd9Sstevel@tonic-gate	    egrep -v "svc:/.*:.*"`
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate	instance_disabled=""
1267c478bd9Sstevel@tonic-gate	default_enabled=""
1277c478bd9Sstevel@tonic-gate	enabled=""
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate	for instance in $manifest_instances; do
1307c478bd9Sstevel@tonic-gate		# if the instance doesn't exist in the repository skip it
1317c478bd9Sstevel@tonic-gate		svcprop -q $instance
1327c478bd9Sstevel@tonic-gate		if [ $? -ne 0 ]; then
1337c478bd9Sstevel@tonic-gate			continue
1347c478bd9Sstevel@tonic-gate		fi
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate		enabled=`svcprop -p general/enabled $instance`
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate		default_instance=`echo $instance | grep ":default"`
1397c478bd9Sstevel@tonic-gate		if [ "$default_instance" != "" ]; then
1407c478bd9Sstevel@tonic-gate			default_enabled=$enabled
1417c478bd9Sstevel@tonic-gate		else
1427c478bd9Sstevel@tonic-gate			# add all non-default instances to disable list
1437c478bd9Sstevel@tonic-gate			instances_to_disable="$instances_to_disable \
1447c478bd9Sstevel@tonic-gate			    $instance"
1457c478bd9Sstevel@tonic-gate			if [ "$enabled" != "true" ]; then
1467c478bd9Sstevel@tonic-gate				instance_disabled="true"
1477c478bd9Sstevel@tonic-gate			fi
1487c478bd9Sstevel@tonic-gate		fi
1497c478bd9Sstevel@tonic-gate	done
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate	# if none of the manifest's instances existed, skip this manifest
1527c478bd9Sstevel@tonic-gate	if [ "$enabled" = "" ]; then
1537c478bd9Sstevel@tonic-gate		continue
1547c478bd9Sstevel@tonic-gate	fi
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate	# If the default instance existed and was disabled, or if didn't
1577c478bd9Sstevel@tonic-gate	# exist and one of the other instances was disabled, add the default
1587c478bd9Sstevel@tonic-gate	# to the list of instances to disable.
1597c478bd9Sstevel@tonic-gate	if [ "$default_enabled" = "false" -o "$default_enabled" = "" -a \
1607c478bd9Sstevel@tonic-gate	    "$instance_disabled" = "true" ]; then
1617c478bd9Sstevel@tonic-gate		instances_to_disable="$instances_to_disable \
1627c478bd9Sstevel@tonic-gate		    $manifest_service:default"
1637c478bd9Sstevel@tonic-gate	fi
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate	# add the manifest's inetd.conf src line to file for inetconv
1667c478bd9Sstevel@tonic-gate	sed -n -f /tmp/inetd-upgrade.$$.sed $manifest >> \
1677c478bd9Sstevel@tonic-gate	    $inetdconf_entries_file
1687c478bd9Sstevel@tonic-gatedone
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gaterm /tmp/inetd-upgrade.$$.sed
1717c478bd9Sstevel@tonic-gate
172781c49dbScarlsonj# Check whether we've ever run inetconv before by looking for the
173781c49dbScarlsonj# configuration file hash.  If we haven't run it before, then we need
174781c49dbScarlsonj# to enable services based on inetd.conf.  If we have, then the
175781c49dbScarlsonj# repository is authoritative.  `unimported' will be 0 if the hash exists.
176781c49dbScarlsonjsvcprop -qp hash svc:/network/inetd:default
177781c49dbScarlsonjunimported=$?
178781c49dbScarlsonj
1797c478bd9Sstevel@tonic-gate# Run inetconv on generated file, overwriting previous manifests and values
1807c478bd9Sstevel@tonic-gate# in repository.
1817c478bd9Sstevel@tonic-gate/usr/sbin/inetconv -f -i $inetdconf_entries_file
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate# disable the necessary instances
1847c478bd9Sstevel@tonic-gatefor inst in $instances_to_disable; do
1857c478bd9Sstevel@tonic-gate	svcadm disable $inst
1867c478bd9Sstevel@tonic-gatedone
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate
189781c49dbScarlsonj# If there is a saved config file from upgrade, use it to enable services,
190781c49dbScarlsonj# but only if we're coming from a release that didn't have SMF.
1917c478bd9Sstevel@tonic-gatesaved_config=/etc/inet/inetd.conf.preupgrade
192781c49dbScarlsonjif [ $unimported -ne 0 -a -f $saved_config ]; then
193781c49dbScarlsonj	/usr/sbin/inetconv -e -i $saved_config
1947c478bd9Sstevel@tonic-gatefi
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate# Now convert the remaining entries in inetd.conf to service manifests
1977c478bd9Sstevel@tonic-gate/usr/sbin/inetconv
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate# Now disable myself as the upgrade is done
2007c478bd9Sstevel@tonic-gatesvcadm disable network/inetd-upgrade
2017c478bd9Sstevel@tonic-gate
2027c478bd9Sstevel@tonic-gateexit 0
203