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