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