xref: /onnv-gate/usr/src/cmd/svc/shell/sendmail_include.sh (revision 9856:3fc693339c20)
18838SJohn.Beck@Sun.COM#!/sbin/sh
28838SJohn.Beck@Sun.COM#
38838SJohn.Beck@Sun.COM# CDDL HEADER START
48838SJohn.Beck@Sun.COM#
58838SJohn.Beck@Sun.COM# The contents of this file are subject to the terms of the
68838SJohn.Beck@Sun.COM# Common Development and Distribution License (the "License").
78838SJohn.Beck@Sun.COM# You may not use this file except in compliance with the License.
88838SJohn.Beck@Sun.COM#
98838SJohn.Beck@Sun.COM# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
108838SJohn.Beck@Sun.COM# or http://www.opensolaris.org/os/licensing.
118838SJohn.Beck@Sun.COM# See the License for the specific language governing permissions
128838SJohn.Beck@Sun.COM# and limitations under the License.
138838SJohn.Beck@Sun.COM#
148838SJohn.Beck@Sun.COM# When distributing Covered Code, include this CDDL HEADER in each
158838SJohn.Beck@Sun.COM# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
168838SJohn.Beck@Sun.COM# If applicable, add the following below this CDDL HEADER, with the
178838SJohn.Beck@Sun.COM# fields enclosed by brackets "[]" replaced with your own identifying
188838SJohn.Beck@Sun.COM# information: Portions Copyright [yyyy] [name of copyright owner]
198838SJohn.Beck@Sun.COM#
208838SJohn.Beck@Sun.COM# CDDL HEADER END
218838SJohn.Beck@Sun.COM#
228838SJohn.Beck@Sun.COM# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
238838SJohn.Beck@Sun.COM# Use is subject to license terms.
248838SJohn.Beck@Sun.COM
258838SJohn.Beck@Sun.COMDEFAULT_FILE="/etc/default/sendmail"
268838SJohn.Beck@Sun.COMSENDMAIL="/usr/lib/sendmail"
278838SJohn.Beck@Sun.COMPATH="/usr/bin:/usr/sbin:/usr/ccs/bin"
288838SJohn.Beck@Sun.COMexport PATH
298838SJohn.Beck@Sun.COM
308838SJohn.Beck@Sun.COMcheck_queue_interval_syntax()
318838SJohn.Beck@Sun.COM{
328838SJohn.Beck@Sun.COM	default="15m"
338838SJohn.Beck@Sun.COM	if [ $# -lt 1 ]; then
348838SJohn.Beck@Sun.COM		answer=$default
358838SJohn.Beck@Sun.COM		return
368838SJohn.Beck@Sun.COM	fi
378838SJohn.Beck@Sun.COM	if echo $1 | egrep '^([0-9]*[1-9][0-9]*[smhdw])+$' >/dev/null 2>&1; then
388838SJohn.Beck@Sun.COM		answer=$1
398838SJohn.Beck@Sun.COM	else
408838SJohn.Beck@Sun.COM		answer=$default
418838SJohn.Beck@Sun.COM	fi
428838SJohn.Beck@Sun.COM}
438838SJohn.Beck@Sun.COM
448838SJohn.Beck@Sun.COMcheck_and_kill()
458838SJohn.Beck@Sun.COM{
468838SJohn.Beck@Sun.COM	PID=`head -1 $1`
478838SJohn.Beck@Sun.COM	kill -0 $PID > /dev/null 2>&1
488838SJohn.Beck@Sun.COM	[ $? -eq 0 ] && kill $PID
498838SJohn.Beck@Sun.COM}
508838SJohn.Beck@Sun.COM
518838SJohn.Beck@Sun.COMexist_or_exit()
528838SJohn.Beck@Sun.COM{
538838SJohn.Beck@Sun.COM	if [ ! -f $1 ]; then
548838SJohn.Beck@Sun.COM		echo "$1 does not exist" >&2
558838SJohn.Beck@Sun.COM		exit $SMF_EXIT_ERR_CONFIG
568838SJohn.Beck@Sun.COM	fi
578838SJohn.Beck@Sun.COM}
588838SJohn.Beck@Sun.COM
598838SJohn.Beck@Sun.COMturn_m4_crank()
608838SJohn.Beck@Sun.COM{
618838SJohn.Beck@Sun.COM	# expected to be called with two arguments: .cf path & path to m4 file
628838SJohn.Beck@Sun.COM	[ $# -lt 2 ] && return
638838SJohn.Beck@Sun.COM	cf_path=$1
648838SJohn.Beck@Sun.COM	m4_path=$2
658838SJohn.Beck@Sun.COM	if [ "$m4_path" = "_DONT_TOUCH_THIS" ]; then
668838SJohn.Beck@Sun.COM		if [ -f "${cf_path}.old" ]; then
678838SJohn.Beck@Sun.COM			mv "$cf_path" "${cf_path}.new"
688838SJohn.Beck@Sun.COM			[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
698838SJohn.Beck@Sun.COM			mv "${cf_path}.old" "$cf_path"
708838SJohn.Beck@Sun.COM			[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
718838SJohn.Beck@Sun.COM		fi
728838SJohn.Beck@Sun.COM		#
738838SJohn.Beck@Sun.COM		# If ${cf_path}.old does not exist, assume it was taken care
748838SJohn.Beck@Sun.COM		# of on a previous run.
758838SJohn.Beck@Sun.COM		#
768838SJohn.Beck@Sun.COM	else
77*9856SJohn.Beck@Sun.COM		case "$m4_path" in
78*9856SJohn.Beck@Sun.COM		/*)	;;	# absolute path
79*9856SJohn.Beck@Sun.COM		*)	return;;
80*9856SJohn.Beck@Sun.COM		esac
818838SJohn.Beck@Sun.COM		exist_or_exit "$m4_path"
828838SJohn.Beck@Sun.COM		cd `dirname "$m4_path"`
838838SJohn.Beck@Sun.COM		base=`basename "$m4_path"`
848838SJohn.Beck@Sun.COM		name=`basename "$m4_path" .mc`
858838SJohn.Beck@Sun.COM		info=`svcprop -p config/include_info $SMF_FMRI 2>/dev/null`
868838SJohn.Beck@Sun.COM		if [ "$info" = "true" ]; then
878838SJohn.Beck@Sun.COM			m4flags=""
888838SJohn.Beck@Sun.COM		else
898838SJohn.Beck@Sun.COM			m4flags="-DSUN_HIDE_INTERNAL_DETAILS"
908838SJohn.Beck@Sun.COM		fi
918838SJohn.Beck@Sun.COM		m4 $m4flags /etc/mail/cf/m4/cf.m4 "$base" > "${name}.cf"
928838SJohn.Beck@Sun.COM		[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
938838SJohn.Beck@Sun.COM		cmp -s "${name}.cf" "$cf_path" || (
948838SJohn.Beck@Sun.COM			cp "${name}.cf" "${cf_path}.tmp" &&
958838SJohn.Beck@Sun.COM			chown root:bin "${cf_path}.tmp" &&
968838SJohn.Beck@Sun.COM			chmod 444 "${cf_path}.tmp" &&
978838SJohn.Beck@Sun.COM			mv "${cf_path}.tmp" "$cf_path"
988838SJohn.Beck@Sun.COM		)
998838SJohn.Beck@Sun.COM		[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
1008838SJohn.Beck@Sun.COM	fi
1018838SJohn.Beck@Sun.COM}
102