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