logadm-upgrade revision f6e214c7418f43af38bd8c3a557e3d0a1d311cfa
0N/A#!/sbin/sh
3081N/A#
0N/A# CDDL HEADER START
0N/A#
0N/A# The contents of this file are subject to the terms of the
0N/A# Common Development and Distribution License (the "License").
2362N/A# You may not use this file except in compliance with the License.
0N/A#
2362N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0N/A# or http://www.opensolaris.org/os/licensing.
0N/A# See the License for the specific language governing permissions
0N/A# and limitations under the License.
0N/A#
0N/A# When distributing Covered Code, include this CDDL HEADER in each
0N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0N/A# If applicable, add the following below this CDDL HEADER, with the
0N/A# fields enclosed by brackets "[]" replaced with your own identifying
0N/A# information: Portions Copyright [yyyy] [name of copyright owner]
0N/A#
0N/A# CDDL HEADER END
2362N/A#
2362N/A#
2362N/A# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
0N/A#
0N/A
0N/A. /lib/svc/share/smf_include.sh
0N/A
0N/ALOGADM=/etc/logadm.conf
0N/ALOGADM_D=${LOGADM%conf}d
0N/ALS=/usr/bin/ls
0N/AAWK=/usr/bin/awk
0N/AGREP=/usr/bin/grep
0N/A
0N/A#
0N/A# This is a temporary service to allow addition (only) to /etc/logadm.conf
0N/A# It is temporary in the sense that logadm(1M) should have its configuration
0N/A# migrated to SMF in the future.
0N/A#
0N/A
0N/A#
0N/A# Display error message and exits with error code
0N/A#
0N/Amsg_exit()
0N/A{
0N/A exit_code=$1
0N/A msg=$2
0N/A
0N/A echo "${msg}"
0N/A exit ${exit_code}
0N/A}
0N/A
0N/A#
0N/A# If there is no /etc/logadm.d we can bail
0N/A#
0N/Aif [ ! -d ${LOGADM_D} ]; then
0N/A exit ${SMF_EXIT_OK}
0N/Afi
0N/A
0N/A#
0N/A# Cache files
0N/A#
0N/Afiles=$(${LS} -t ${LOGADM} ${LOGADM_D}/*)
0N/A
0N/A#
0N/A# If there is no /etc/logadm.conf create it and make sure it has the
0N/A# right ownership and permissions.
0N/A# Make sure this is done AFTER $files is set. Otherwise /etc/logadm.conf will be
0N/A# newer than all files is /etc/logadm.d and they will be skipped.
0N/A#
0N/Aif [ ! -f ${LOGADM} ]; then
0N/A touch ${LOGADM}
0N/A chmod 644 ${LOGADM}
0N/A chown root:sys ${LOGADM}
0N/Afi
0N/A
4138N/Afor f in ${files}
4138N/Ado
4138N/A #
4138N/A # If it is not a file, we skip it.
4138N/A #
4138N/A if [ ! -f ${f} ]; then
0N/A continue
0N/A fi
0N/A
0N/A #
0N/A # We stop when files at /etc/logadm.d are older than /etc/logadm.conf
4138N/A #
4138N/A if [ ${f} = ${LOGADM} ]; then
4138N/A break
4138N/A fi
4138N/A
4138N/A #
4138N/A # We ignore files that are not owned by root, group sys
4138N/A # and have permissions different than 444
4138N/A #
4138N/A perm=$(${LS} -l ${f} | ${AWK} '{printf("%s %s:%s", $1, $3, $4)}')
4138N/A if [ $? != 0 ]; then
4138N/A msg_exit ${SMF_EXIT_ERR_FATAL} "${perm}"
4138N/A fi
4138N/A if [ "${perm}" != "-r--r--r-- root:sys" ]; then
4138N/A echo "Unexpected permission/ownership for ${f}"
4138N/A echo " expected -r--r--r-- root:sys but got ${perm}"
4138N/A echo " skipping ${f}"
4138N/A continue
4138N/A fi
4138N/A
0N/A #
0N/A # Discard comments (lines starting with #)
0N/A #
0N/A ${GREP} -v '^#' ${f} | while read entry
0N/A do
0N/A sig=$(echo ${entry} | ${AWK} '{printf("%s\>", $1);}' 2>&1)
0N/A if [ $? != 0 ]; then # only happens if awk(1) fails
0N/A msg_exit ${SMF_EXIT_ERR_FATAL} "${sig}"
0N/A fi
0N/A
0N/A #
0N/A # if ${sig} is null but the previous command succeeded, we skip
0N/A #
0N/A if [ ! ${sig} ]; then
0N/A continue;
0N/A fi
0N/A
0N/A err_msg=$(${GREP} ^${sig} ${LOGADM} 2>&1)
0N/A case $? in
0N/A '1')
0N/A echo "${entry}" >> ${LOGADM}
0N/A ;;
0N/A '0')
0N/A ;;
0N/A *)
0N/A msg_exit ${SMF_EXIT_ERR_FATAL} "${err_msg}"
0N/A esac
0N/A done
0N/Adone
0N/A
0N/Aexit ${SMF_EXIT_OK}
0N/A
0N/A