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