Merge commit 'b1e7e97d3b60469b243b3b2e22c7d8cbd11c7c90'
[unleashed.git] / usr / src / cmd / logadm / logadm-upgrade
blob04a1114af5b70e8d788a4cbaf60765e7e7b26389
1 #!/sbin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
20 # CDDL HEADER END
23 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
26 . /lib/svc/share/smf_include.sh
28 LOGADM=/etc/logadm.conf
29 LOGADM_D=${LOGADM%conf}d
30 LS=/usr/bin/ls
31 AWK=/usr/bin/awk
32 GREP=/usr/bin/grep
35 # This is a temporary service to allow addition (only) to /etc/logadm.conf
36 # It is temporary in the sense that logadm(8) should have its configuration
37 # migrated to SMF in the future.
41 # Display error message and exits with error code
43 msg_exit()
45 exit_code=$1
46 msg=$2
48 echo "${msg}"
49 exit ${exit_code}
53 # If there is no /etc/logadm.d we can bail
55 if [ ! -d ${LOGADM_D} ]; then
56 exit ${SMF_EXIT_OK}
60 # Cache files
62 files=$(${LS} -t ${LOGADM} ${LOGADM_D}/*)
65 # If there is no /etc/logadm.conf create it and make sure it has the
66 # right ownership and permissions.
67 # Make sure this is done AFTER $files is set. Otherwise /etc/logadm.conf will be
68 # newer than all files is /etc/logadm.d and they will be skipped.
70 if [ ! -f ${LOGADM} ]; then
71 touch ${LOGADM}
72 chmod 644 ${LOGADM}
73 chown root:sys ${LOGADM}
76 for f in ${files}
79 # If it is not a file, we skip it.
81 if [ ! -f ${f} ]; then
82 continue
86 # We stop when files at /etc/logadm.d are older than /etc/logadm.conf
88 if [ ${f} = ${LOGADM} ]; then
89 break
93 # We ignore files that are not owned by root, group sys
94 # and have permissions different than 444
96 perm=$(${LS} -l ${f} | ${AWK} '{printf("%s %s:%s", $1, $3, $4)}')
97 if [ $? != 0 ]; then
98 msg_exit ${SMF_EXIT_ERR_FATAL} "${perm}"
100 if [ "${perm}" != "-r--r--r-- root:sys" ]; then
101 echo "Unexpected permission/ownership for ${f}"
102 echo " expected -r--r--r-- root:sys but got ${perm}"
103 echo " skipping ${f}"
104 continue
108 # Discard comments (lines starting with #)
110 ${GREP} -v '^#' ${f} | while read entry
112 sig=$(echo ${entry} | ${AWK} '{printf("%s\>", $1);}' 2>&1)
113 if [ $? != 0 ]; then # only happens if awk(1) fails
114 msg_exit ${SMF_EXIT_ERR_FATAL} "${sig}"
118 # if ${sig} is null but the previous command succeeded, we skip
120 if [ ! ${sig} ]; then
121 continue;
124 err_msg=$(${GREP} ^${sig} ${LOGADM} 2>&1)
125 case $? in
126 '1')
127 echo "${entry}" >> ${LOGADM}
129 '0')
132 msg_exit ${SMF_EXIT_ERR_FATAL} "${err_msg}"
133 esac
134 done
135 done
137 exit ${SMF_EXIT_OK}