xref: /onnv-gate/usr/src/cmd/logadm/logadm-upgrade (revision 12967:ab9ae749152f)
1*12967Sgavin.maltby@oracle.com#!/sbin/sh
2*12967Sgavin.maltby@oracle.com#
3*12967Sgavin.maltby@oracle.com# CDDL HEADER START
4*12967Sgavin.maltby@oracle.com#
5*12967Sgavin.maltby@oracle.com# The contents of this file are subject to the terms of the
6*12967Sgavin.maltby@oracle.com# Common Development and Distribution License (the "License").
7*12967Sgavin.maltby@oracle.com# You may not use this file except in compliance with the License.
8*12967Sgavin.maltby@oracle.com#
9*12967Sgavin.maltby@oracle.com# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*12967Sgavin.maltby@oracle.com# or http://www.opensolaris.org/os/licensing.
11*12967Sgavin.maltby@oracle.com# See the License for the specific language governing permissions
12*12967Sgavin.maltby@oracle.com# and limitations under the License.
13*12967Sgavin.maltby@oracle.com#
14*12967Sgavin.maltby@oracle.com# When distributing Covered Code, include this CDDL HEADER in each
15*12967Sgavin.maltby@oracle.com# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*12967Sgavin.maltby@oracle.com# If applicable, add the following below this CDDL HEADER, with the
17*12967Sgavin.maltby@oracle.com# fields enclosed by brackets "[]" replaced with your own identifying
18*12967Sgavin.maltby@oracle.com# information: Portions Copyright [yyyy] [name of copyright owner]
19*12967Sgavin.maltby@oracle.com#
20*12967Sgavin.maltby@oracle.com# CDDL HEADER END
21*12967Sgavin.maltby@oracle.com#
22*12967Sgavin.maltby@oracle.com#
23*12967Sgavin.maltby@oracle.com# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24*12967Sgavin.maltby@oracle.com#
25*12967Sgavin.maltby@oracle.com
26*12967Sgavin.maltby@oracle.com. /lib/svc/share/smf_include.sh
27*12967Sgavin.maltby@oracle.com
28*12967Sgavin.maltby@oracle.comLOGADM=/etc/logadm.conf
29*12967Sgavin.maltby@oracle.comLOGADM_D=${LOGADM%conf}d
30*12967Sgavin.maltby@oracle.comLS=/usr/bin/ls
31*12967Sgavin.maltby@oracle.comAWK=/usr/bin/awk
32*12967Sgavin.maltby@oracle.comGREP=/usr/bin/grep
33*12967Sgavin.maltby@oracle.com
34*12967Sgavin.maltby@oracle.com#
35*12967Sgavin.maltby@oracle.com# This is a temporary service to allow addition (only) to /etc/logadm.conf
36*12967Sgavin.maltby@oracle.com# It is temporary in the sense that logadm(1M) should have its configuration
37*12967Sgavin.maltby@oracle.com# migrated to SMF in the future.
38*12967Sgavin.maltby@oracle.com#
39*12967Sgavin.maltby@oracle.com
40*12967Sgavin.maltby@oracle.com#
41*12967Sgavin.maltby@oracle.com# Display error message and exits with error code
42*12967Sgavin.maltby@oracle.com#
43*12967Sgavin.maltby@oracle.commsg_exit()
44*12967Sgavin.maltby@oracle.com{
45*12967Sgavin.maltby@oracle.com	exit_code=$1
46*12967Sgavin.maltby@oracle.com	msg=$2
47*12967Sgavin.maltby@oracle.com
48*12967Sgavin.maltby@oracle.com	echo "${msg}"
49*12967Sgavin.maltby@oracle.com	exit ${exit_code}
50*12967Sgavin.maltby@oracle.com}
51*12967Sgavin.maltby@oracle.com
52*12967Sgavin.maltby@oracle.com#
53*12967Sgavin.maltby@oracle.com# If there is no /etc/logadm.d we can bail
54*12967Sgavin.maltby@oracle.com#
55*12967Sgavin.maltby@oracle.comif [ ! -d ${LOGADM_D} ]; then
56*12967Sgavin.maltby@oracle.com	exit ${SMF_EXIT_OK}
57*12967Sgavin.maltby@oracle.comfi
58*12967Sgavin.maltby@oracle.com
59*12967Sgavin.maltby@oracle.com#
60*12967Sgavin.maltby@oracle.com# Cache files
61*12967Sgavin.maltby@oracle.com#
62*12967Sgavin.maltby@oracle.comfiles=$(${LS} -t  ${LOGADM} ${LOGADM_D}/*)
63*12967Sgavin.maltby@oracle.com
64*12967Sgavin.maltby@oracle.com#
65*12967Sgavin.maltby@oracle.com# If there is no /etc/logadm.conf create it and make sure it has the
66*12967Sgavin.maltby@oracle.com# right ownership and permissions.
67*12967Sgavin.maltby@oracle.com# Make sure this is done AFTER $files is set. Otherwise /etc/logadm.conf will be
68*12967Sgavin.maltby@oracle.com# newer than all files is /etc/logadm.d and they will be skipped.
69*12967Sgavin.maltby@oracle.com#
70*12967Sgavin.maltby@oracle.comif [ ! -f ${LOGADM} ]; then
71*12967Sgavin.maltby@oracle.com	touch ${LOGADM}
72*12967Sgavin.maltby@oracle.com	chmod 644 ${LOGADM}
73*12967Sgavin.maltby@oracle.com	chown root:sys ${LOGADM}
74*12967Sgavin.maltby@oracle.comfi
75*12967Sgavin.maltby@oracle.com
76*12967Sgavin.maltby@oracle.comfor f in ${files}
77*12967Sgavin.maltby@oracle.comdo
78*12967Sgavin.maltby@oracle.com	#
79*12967Sgavin.maltby@oracle.com	# If it is not a file, we skip it.
80*12967Sgavin.maltby@oracle.com	#
81*12967Sgavin.maltby@oracle.com	if [ ! -f ${f} ]; then
82*12967Sgavin.maltby@oracle.com		continue
83*12967Sgavin.maltby@oracle.com	fi
84*12967Sgavin.maltby@oracle.com
85*12967Sgavin.maltby@oracle.com	#
86*12967Sgavin.maltby@oracle.com	# We stop when files at /etc/logadm.d are older than /etc/logadm.conf
87*12967Sgavin.maltby@oracle.com	#
88*12967Sgavin.maltby@oracle.com	if [ ${f} = ${LOGADM} ]; then
89*12967Sgavin.maltby@oracle.com		break
90*12967Sgavin.maltby@oracle.com	fi
91*12967Sgavin.maltby@oracle.com
92*12967Sgavin.maltby@oracle.com	#
93*12967Sgavin.maltby@oracle.com	# We ignore files that are not owned by root, group sys
94*12967Sgavin.maltby@oracle.com	# and have permissions different than 444
95*12967Sgavin.maltby@oracle.com	#
96*12967Sgavin.maltby@oracle.com	perm=$(${LS} -l ${f} | ${AWK} '{printf("%s %s:%s", $1, $3, $4)}')
97*12967Sgavin.maltby@oracle.com	if [ $? != 0 ]; then
98*12967Sgavin.maltby@oracle.com		msg_exit ${SMF_EXIT_ERR_FATAL} "${perm}"
99*12967Sgavin.maltby@oracle.com	fi
100*12967Sgavin.maltby@oracle.com	if [ "${perm}" != "-r--r--r-- root:sys" ]; then
101*12967Sgavin.maltby@oracle.com		echo "Unexpected permission/ownership for ${f}"
102*12967Sgavin.maltby@oracle.com		echo "    expected -r--r--r-- root:sys but got ${perm}"
103*12967Sgavin.maltby@oracle.com		echo "    skipping ${f}"
104*12967Sgavin.maltby@oracle.com		continue
105*12967Sgavin.maltby@oracle.com	fi
106*12967Sgavin.maltby@oracle.com
107*12967Sgavin.maltby@oracle.com	#
108*12967Sgavin.maltby@oracle.com	# Discard comments (lines starting with #)
109*12967Sgavin.maltby@oracle.com	#
110*12967Sgavin.maltby@oracle.com	${GREP} -v '^#' ${f} | while read entry
111*12967Sgavin.maltby@oracle.com	do
112*12967Sgavin.maltby@oracle.com		sig=$(echo ${entry} | ${AWK} '{printf("%s\>", $1);}' 2>&1)
113*12967Sgavin.maltby@oracle.com		if [ $? != 0 ]; then # only happens if awk(1) fails
114*12967Sgavin.maltby@oracle.com			msg_exit ${SMF_EXIT_ERR_FATAL} "${sig}"
115*12967Sgavin.maltby@oracle.com		fi
116*12967Sgavin.maltby@oracle.com
117*12967Sgavin.maltby@oracle.com		#
118*12967Sgavin.maltby@oracle.com		# if ${sig} is null but the previous command succeeded, we skip
119*12967Sgavin.maltby@oracle.com		#
120*12967Sgavin.maltby@oracle.com		if [ ! ${sig} ]; then
121*12967Sgavin.maltby@oracle.com			continue;
122*12967Sgavin.maltby@oracle.com		fi
123*12967Sgavin.maltby@oracle.com
124*12967Sgavin.maltby@oracle.com		err_msg=$(${GREP} ^${sig} ${LOGADM} 2>&1)
125*12967Sgavin.maltby@oracle.com		case $? in
126*12967Sgavin.maltby@oracle.com		'1')
127*12967Sgavin.maltby@oracle.com			echo "${entry}" >> ${LOGADM}
128*12967Sgavin.maltby@oracle.com			;;
129*12967Sgavin.maltby@oracle.com		'0')
130*12967Sgavin.maltby@oracle.com			;;
131*12967Sgavin.maltby@oracle.com		*)
132*12967Sgavin.maltby@oracle.com			msg_exit ${SMF_EXIT_ERR_FATAL} "${err_msg}"
133*12967Sgavin.maltby@oracle.com		esac
134*12967Sgavin.maltby@oracle.com	done
135*12967Sgavin.maltby@oracle.comdone
136*12967Sgavin.maltby@oracle.com
137*12967Sgavin.maltby@oracle.comexit ${SMF_EXIT_OK}
138*12967Sgavin.maltby@oracle.com
139