xref: /illumos-gate/usr/src/cmd/cmd-crypto/scripts/r.kmfconf (revision 2722387f30847b828b57ba9ca59d2b47ee9244ec)
1#
2# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3# Use is subject to license terms.
4#
5# CDDL HEADER START
6#
7# The contents of this file are subject to the terms of the
8# Common Development and Distribution License (the "License").
9# You may not use this file except in compliance with the License.
10#
11# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
12# or http://www.opensolaris.org/os/licensing.
13# See the License for the specific language governing permissions
14# and limitations under the License.
15#
16# When distributing Covered Code, include this CDDL HEADER in each
17# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
18# If applicable, add the following below this CDDL HEADER, with the
19# fields enclosed by brackets "[]" replaced with your own identifying
20# information: Portions Copyright [yyyy] [name of copyright owner]
21#
22# CDDL HEADER END
23#
24# ident	"%Z%%M%	%I%	%E% SMI"
25#
26# Removal class action script for "kmfconf" class files.
27#
28# This script removes entries belonging to the package from the
29# /etc/crypto/kmf.conf file.
30#
31
32pkg_start="# Start $PKGINST"
33pkg_end="# End $PKGINST"
34tmpfile=/tmp/$$kmfconf
35error=no
36
37while read dest
38do
39	# For multiple input files; exit if error occurred in preious
40	# input file.
41	if [ "$error" = yes ]
42	then
43		echo "$0: failed to update $lastdest for $PKGINST."
44		exit 2
45	fi
46	lastdest=$dest
47
48	# Strip all entries belonging to this package
49	start=0
50	end=0
51	egrep -s "$pkg_start" $dest && start=1
52	egrep -s "$pkg_end" $dest && end=1
53
54	if [ $start -ne $end ] ; then
55		echo "$0: missing Start or End delimiters for $PKGINST in \
56		    $dest."
57		echo "$0: $dest may be corrupted and was not updated."
58		error=yes
59		continue
60	fi
61
62	if [ $start -eq 1 ]
63    	then
64		sed -e "/$pkg_start/,/$pkg_end/d" $dest > $tmpfile || error=yes
65		if [ "$error" = no ]
66                then
67			mv $tmpfile $dest || error=yes
68		fi
69		rm -f $tmpfile
70	else
71		echo "$0: WARNING - no entries found in $dest for $PKGINST."
72		exit 0
73	fi
74done
75
76if [ "$error" = yes ]
77then
78	echo "$0: ERROR - failed to update $lastdest for $PKGINST."
79	exit 2
80fi
81exit 0
82