Home | History | Annotate | Download | only in common_files
      1 #
      2 # Copyright 2005 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, Version 1.0 only
      9 # (the "License").  You may not use this file except in compliance
     10 # with the License.
     11 #
     12 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     13 # or http://www.opensolaris.org/os/licensing.
     14 # See the License for the specific language governing permissions
     15 # and limitations under the License.
     16 #
     17 # When distributing Covered Code, include this CDDL HEADER in each
     18 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     19 # If applicable, add the following below this CDDL HEADER, with the
     20 # fields enclosed by brackets "[]" replaced with your own identifying
     21 # information: Portions Copyright [yyyy] [name of copyright owner]
     22 #
     23 # CDDL HEADER END
     24 #
     25 # ident	"%Z%%M%	%I%	%E% SMI"
     26 #
     27 # proc.inetd_remove -- common code for inetd.conf entry removal
     28 #
     29 # inetd_init	: call before any other functions
     30 # inetd_remove	: remove daemons specified as arguments by removing
     31 #		  lines from inetd.conf that match the regular
     32 #		  expressions provided on stdin (one per line)
     33 # inetd_undo	: call if rest of procedure script fails
     34 # inetd_fini	: call if rest of procedure script succeeds
     35 #
     36 # inetd_init and inetd_remove will perform necessary clean-up and
     37 # return a non-zero exit code on failure.
     38 
     39 inetconf=${PKG_INSTALL_ROOT:-/}/etc/inet/inetd.conf
     40 inetold=/tmp/inetd.conf.$$
     41 inetsed=/tmp/inetd.sed.$$
     42 inettmp=/tmp/inetd.tmp.$$
     43 
     44 inetd_init() {
     45 	cat $inetconf > $inetold
     46 	if [ $? -ne 0 ]; then
     47 		echo "can't create $inetold"
     48 		return 1
     49 	fi
     50 	return 0
     51 }
     52 
     53 inetd_fini() {
     54 	rm -f -- $inetold $inetsed $inettmp
     55 	return 0
     56 }
     57 
     58 inetd_undo() {
     59 	cat $inetold > $inetconf
     60 	inetd_fini
     61 }
     62 
     63 # inetd_check verifies whether any processes are running for the
     64 # supplied FMRI, fails if there are, if not it sends the service to
     65 # maintenance mode.
     66 #
     67 inetd_check() {
     68     	# Return if we're not removing from the running system
     69     	if [ "${PKG_INSTALL_ROOT:-/}" != "/" ]; then
     70 	    	return 0
     71 	fi
     72 
     73 	for i in "$@"; do
     74 	    	cts=`svcprop -p restarter/contract $i 2>/dev/null`
     75 		if [ -n "$cts" ]; then
     76 			echo "$i running; unable to remove package"
     77 			return 1
     78 		fi
     79 		svcadm mark maintenance $i
     80 	done
     81 
     82 	return 0
     83 }
     84 
     85 inetd_remove() {
     86     	inetd_check "$@" || return 1;
     87 	INSTALLED_PKGS=`pkginfo $PKG\\* | wc -l`
     88 	if [ $INSTALLED_PKGS -eq 1 ]; then
     89 		#
     90 		# Remove the additions that were made to /etc/inetd.conf
     91 		#
     92 		sed -e 's:/:\\/:g' -e 's:.*:/&/ d:' > $inetsed
     93 		if [ $? -ne 0 ]; then
     94 			echo "couldn't create $inetsed"
     95 			inetd_undo
     96 			return 1
     97 		fi
     98 		sed -f $inetsed < $inetconf > $inettmp
     99 		if [ $? -ne 0 ]; then
    100 			echo "couldn't create $inettmp"
    101 			inetd_undo
    102 			return 1
    103 		fi
    104 
    105 		cmp -s $inetconf $inettmp
    106 		case $? in
    107 		0)	;;
    108 		1)	cat $inettmp > $inetconf
    109 			if [ $? -ne 0 ]; then
    110 				echo "couldn't edit $inetconf"
    111 				inetd_undo
    112 				return 1
    113 			fi
    114 
    115 			;;
    116 
    117 		*)	echo "couldn't read $inetconf or $inettmp"
    118 			inetd_undo
    119 			return 1
    120 			;;
    121 		esac
    122 	fi
    123 	return 0
    124 }
    125