1*0Sstevel@tonic-gate#! /usr/bin/sh
2*0Sstevel@tonic-gate#
3*0Sstevel@tonic-gate# CDDL HEADER START
4*0Sstevel@tonic-gate#
5*0Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*0Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
7*0Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
8*0Sstevel@tonic-gate# with the License.
9*0Sstevel@tonic-gate#
10*0Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*0Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
12*0Sstevel@tonic-gate# See the License for the specific language governing permissions
13*0Sstevel@tonic-gate# and limitations under the License.
14*0Sstevel@tonic-gate#
15*0Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
16*0Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*0Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
18*0Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
19*0Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
20*0Sstevel@tonic-gate#
21*0Sstevel@tonic-gate# CDDL HEADER END
22*0Sstevel@tonic-gate#
23*0Sstevel@tonic-gate#
24*0Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
25*0Sstevel@tonic-gate#
26*0Sstevel@tonic-gate# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
27*0Sstevel@tonic-gate# Use is subject to license terms.
28*0Sstevel@tonic-gate#
29*0Sstevel@tonic-gate
30*0Sstevel@tonic-gate# Start by cleaning out obsolete instances.  For each one that
31*0Sstevel@tonic-gate# exists in the repository, remove it.
32*0Sstevel@tonic-gateinetd_obsolete_instances="
33*0Sstevel@tonic-gate	network/nfs/rquota:ticlts
34*0Sstevel@tonic-gate	network/nfs/rquota:udp
35*0Sstevel@tonic-gate	network/rexec:tcp
36*0Sstevel@tonic-gate	network/rexec:tcp6
37*0Sstevel@tonic-gate	network/rpc/gss:ticotsord
38*0Sstevel@tonic-gate	network/rpc/mdcomm:tcp
39*0Sstevel@tonic-gate	network/rpc/mdcomm:tcp6
40*0Sstevel@tonic-gate	network/rpc/meta:tcp
41*0Sstevel@tonic-gate	network/rpc/meta:tcp6
42*0Sstevel@tonic-gate	network/rpc/metamed:tcp
43*0Sstevel@tonic-gate	network/rpc/metamed:tcp6
44*0Sstevel@tonic-gate	network/rpc/metamh:tcp
45*0Sstevel@tonic-gate	network/rpc/metamh:tcp6
46*0Sstevel@tonic-gate	network/rpc/rex:tcp
47*0Sstevel@tonic-gate	network/rpc/rstat:ticlts
48*0Sstevel@tonic-gate	network/rpc/rstat:udp
49*0Sstevel@tonic-gate	network/rpc/rstat:udp6
50*0Sstevel@tonic-gate	network/rpc/rusers:udp
51*0Sstevel@tonic-gate	network/rpc/rusers:udp6
52*0Sstevel@tonic-gate	network/rpc/rusers:ticlts
53*0Sstevel@tonic-gate	network/rpc/rusers:tcp
54*0Sstevel@tonic-gate	network/rpc/rusers:tcp6
55*0Sstevel@tonic-gate	network/rpc/rusers:ticotsord
56*0Sstevel@tonic-gate	network/rpc/rusers:ticots
57*0Sstevel@tonic-gate	network/rpc/spray:ticlts
58*0Sstevel@tonic-gate	network/rpc/spray:udp
59*0Sstevel@tonic-gate	network/rpc/spray:udp6
60*0Sstevel@tonic-gate	network/rpc/wall:ticlts
61*0Sstevel@tonic-gate	network/rpc/wall:udp
62*0Sstevel@tonic-gate	network/rpc/wall:udp6
63*0Sstevel@tonic-gate	network/security/krb5_prop:tcp
64*0Sstevel@tonic-gate	network/security/ktkt_warn:ticotsord
65*0Sstevel@tonic-gate	network/shell:tcp
66*0Sstevel@tonic-gate	network/shell:tcp6only
67*0Sstevel@tonic-gate	platform/sun4u/dcs:tcp
68*0Sstevel@tonic-gate	platform/sun4u/dcs:tcp6
69*0Sstevel@tonic-gate"
70*0Sstevel@tonic-gate
71*0Sstevel@tonic-gatefor i in $inetd_obsolete_instances; do
72*0Sstevel@tonic-gate	enable=`svcprop -p general/enabled $i`
73*0Sstevel@tonic-gate	if [ $? = 0 ]; then
74*0Sstevel@tonic-gate		# Instance found, so disable and delete
75*0Sstevel@tonic-gate		svcadm disable $i
76*0Sstevel@tonic-gate		svccfg delete $i
77*0Sstevel@tonic-gate		if [ "$enable" = "true" ]; then
78*0Sstevel@tonic-gate			# Instance was enabled, so enable the replacement.
79*0Sstevel@tonic-gate			# We must do this here because the profile which
80*0Sstevel@tonic-gate			# normally enables these is only applied on first
81*0Sstevel@tonic-gate			# install of smf.
82*0Sstevel@tonic-gate			s=`echo $i | cut -f1 -d:`
83*0Sstevel@tonic-gate			svcadm enable $s:default
84*0Sstevel@tonic-gate		fi
85*0Sstevel@tonic-gate	fi
86*0Sstevel@tonic-gatedone
87*0Sstevel@tonic-gate
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate# The Following blocks of code cause the inetconv generated services to be
90*0Sstevel@tonic-gate# re-generated, so that the latest inetconv modifications are applied to all
91*0Sstevel@tonic-gate# services generated by it.
92*0Sstevel@tonic-gate
93*0Sstevel@tonic-gateinetdconf_entries_file=/tmp/iconf_entries.$$
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate# Create sed script that prints out inetd.conf src line from inetconv generated
96*0Sstevel@tonic-gate# manifest.
97*0Sstevel@tonic-gatecat <<EOF > /tmp/inetd-upgrade.$$.sed
98*0Sstevel@tonic-gate/propval name='source_line'/{
99*0Sstevel@tonic-gaten
100*0Sstevel@tonic-gates/'//g
101*0Sstevel@tonic-gatep
102*0Sstevel@tonic-gate}
103*0Sstevel@tonic-gate/from the inetd.conf(4) format line/{
104*0Sstevel@tonic-gaten
105*0Sstevel@tonic-gatep
106*0Sstevel@tonic-gate}
107*0Sstevel@tonic-gateEOF
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gate# get list of inetconv generated manifests
110*0Sstevel@tonic-gateinetconv_manifests=`/usr/bin/find /var/svc/manifest -type f -name \*.xml | \
111*0Sstevel@tonic-gate    /usr/bin/xargs /usr/bin/grep -l "Generated by inetconv"`
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gate# For each inetconv generated manifest determine the instances that should
114*0Sstevel@tonic-gate# be disabled when the new manifests are imported, and generate a file with
115*0Sstevel@tonic-gate# the inetd.conf entries from all the manifests for consumption by inetconv.
116*0Sstevel@tonic-gate
117*0Sstevel@tonic-gate> $inetdconf_entries_file
118*0Sstevel@tonic-gateinetconv_services=""
119*0Sstevel@tonic-gateinstances_to_disable=""
120*0Sstevel@tonic-gate
121*0Sstevel@tonic-gatefor manifest in $inetconv_manifests; do
122*0Sstevel@tonic-gate
123*0Sstevel@tonic-gate	manifest_instances=`/usr/sbin/svccfg inventory $manifest | \
124*0Sstevel@tonic-gate	    egrep "svc:/.*:.*"`
125*0Sstevel@tonic-gate	manifest_service=`/usr/sbin/svccfg inventory $manifest | \
126*0Sstevel@tonic-gate	    egrep -v "svc:/.*:.*"`
127*0Sstevel@tonic-gate
128*0Sstevel@tonic-gate	instance_disabled=""
129*0Sstevel@tonic-gate	default_enabled=""
130*0Sstevel@tonic-gate	enabled=""
131*0Sstevel@tonic-gate
132*0Sstevel@tonic-gate	for instance in $manifest_instances; do
133*0Sstevel@tonic-gate		# if the instance doesn't exist in the repository skip it
134*0Sstevel@tonic-gate		svcprop -q $instance
135*0Sstevel@tonic-gate		if [ $? -ne 0 ]; then
136*0Sstevel@tonic-gate			continue
137*0Sstevel@tonic-gate		fi
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate		enabled=`svcprop -p general/enabled $instance`
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate		default_instance=`echo $instance | grep ":default"`
142*0Sstevel@tonic-gate		if [ "$default_instance" != "" ]; then
143*0Sstevel@tonic-gate			default_enabled=$enabled
144*0Sstevel@tonic-gate		else
145*0Sstevel@tonic-gate			# add all non-default instances to disable list
146*0Sstevel@tonic-gate			instances_to_disable="$instances_to_disable \
147*0Sstevel@tonic-gate			    $instance"
148*0Sstevel@tonic-gate			if [ "$enabled" != "true" ]; then
149*0Sstevel@tonic-gate				instance_disabled="true"
150*0Sstevel@tonic-gate			fi
151*0Sstevel@tonic-gate		fi
152*0Sstevel@tonic-gate	done
153*0Sstevel@tonic-gate
154*0Sstevel@tonic-gate	# if none of the manifest's instances existed, skip this manifest
155*0Sstevel@tonic-gate	if [ "$enabled" = "" ]; then
156*0Sstevel@tonic-gate		continue
157*0Sstevel@tonic-gate	fi
158*0Sstevel@tonic-gate
159*0Sstevel@tonic-gate	# If the default instance existed and was disabled, or if didn't
160*0Sstevel@tonic-gate	# exist and one of the other instances was disabled, add the default
161*0Sstevel@tonic-gate	# to the list of instances to disable.
162*0Sstevel@tonic-gate	if [ "$default_enabled" = "false" -o "$default_enabled" = "" -a \
163*0Sstevel@tonic-gate	    "$instance_disabled" = "true" ]; then
164*0Sstevel@tonic-gate		instances_to_disable="$instances_to_disable \
165*0Sstevel@tonic-gate		    $manifest_service:default"
166*0Sstevel@tonic-gate	fi
167*0Sstevel@tonic-gate
168*0Sstevel@tonic-gate	# add the manifest's inetd.conf src line to file for inetconv
169*0Sstevel@tonic-gate	sed -n -f /tmp/inetd-upgrade.$$.sed $manifest >> \
170*0Sstevel@tonic-gate	    $inetdconf_entries_file
171*0Sstevel@tonic-gatedone
172*0Sstevel@tonic-gate
173*0Sstevel@tonic-gaterm /tmp/inetd-upgrade.$$.sed
174*0Sstevel@tonic-gate
175*0Sstevel@tonic-gate# Run inetconv on generated file, overwriting previous manifests and values
176*0Sstevel@tonic-gate# in repository.
177*0Sstevel@tonic-gate/usr/sbin/inetconv -f -i $inetdconf_entries_file
178*0Sstevel@tonic-gate
179*0Sstevel@tonic-gate# disable the necessary instances
180*0Sstevel@tonic-gatefor inst in $instances_to_disable; do
181*0Sstevel@tonic-gate	svcadm disable $inst
182*0Sstevel@tonic-gatedone
183*0Sstevel@tonic-gate
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gate# If there is a saved config file from upgrade, use it to enable services
186*0Sstevel@tonic-gatesaved_config=/etc/inet/inetd.conf.preupgrade
187*0Sstevel@tonic-gate
188*0Sstevel@tonic-gateif [ -f ${saved_config} ]; then
189*0Sstevel@tonic-gate	/usr/sbin/inetconv -e -i ${saved_config}
190*0Sstevel@tonic-gatefi
191*0Sstevel@tonic-gate
192*0Sstevel@tonic-gate# Now convert the remaining entries in inetd.conf to service manifests
193*0Sstevel@tonic-gate/usr/sbin/inetconv
194*0Sstevel@tonic-gate
195*0Sstevel@tonic-gate# Now disable myself as the upgrade is done
196*0Sstevel@tonic-gatesvcadm disable network/inetd-upgrade
197*0Sstevel@tonic-gate
198*0Sstevel@tonic-gateexit 0
199