1da978630SJohn Beck#!/sbin/sh
2da978630SJohn Beck#
3da978630SJohn Beck# CDDL HEADER START
4da978630SJohn Beck#
5da978630SJohn Beck# The contents of this file are subject to the terms of the
6da978630SJohn Beck# Common Development and Distribution License (the "License").
7da978630SJohn Beck# You may not use this file except in compliance with the License.
8da978630SJohn Beck#
9da978630SJohn Beck# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10da978630SJohn Beck# or http://www.opensolaris.org/os/licensing.
11da978630SJohn Beck# See the License for the specific language governing permissions
12da978630SJohn Beck# and limitations under the License.
13da978630SJohn Beck#
14da978630SJohn Beck# When distributing Covered Code, include this CDDL HEADER in each
15da978630SJohn Beck# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16da978630SJohn Beck# If applicable, add the following below this CDDL HEADER, with the
17da978630SJohn Beck# fields enclosed by brackets "[]" replaced with your own identifying
18da978630SJohn Beck# information: Portions Copyright [yyyy] [name of copyright owner]
19da978630SJohn Beck#
20da978630SJohn Beck# CDDL HEADER END
21da978630SJohn Beck#
22da978630SJohn Beck# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23da978630SJohn Beck# Use is subject to license terms.
24da978630SJohn Beck
25da978630SJohn BeckDEFAULT_FILE="/etc/default/sendmail"
26*287247a8SAlexander PyhalovSENDMAIL="/usr/lib/smtp/sendmail/sendmail"
27da978630SJohn BeckPATH="/usr/bin:/usr/sbin:/usr/ccs/bin"
28da978630SJohn Beckexport PATH
29da978630SJohn Beck
30da978630SJohn Beckcheck_queue_interval_syntax()
31da978630SJohn Beck{
32da978630SJohn Beck	default="15m"
33da978630SJohn Beck	if [ $# -lt 1 ]; then
34da978630SJohn Beck		answer=$default
35da978630SJohn Beck		return
36da978630SJohn Beck	fi
37da978630SJohn Beck	if echo $1 | egrep '^([0-9]*[1-9][0-9]*[smhdw])+$' >/dev/null 2>&1; then
38da978630SJohn Beck		answer=$1
39da978630SJohn Beck	else
40da978630SJohn Beck		answer=$default
41da978630SJohn Beck	fi
42da978630SJohn Beck}
43da978630SJohn Beck
44da978630SJohn Beckcheck_and_kill()
45da978630SJohn Beck{
46da978630SJohn Beck	PID=`head -1 $1`
47da978630SJohn Beck	kill -0 $PID > /dev/null 2>&1
48da978630SJohn Beck	[ $? -eq 0 ] && kill $PID
49da978630SJohn Beck}
50da978630SJohn Beck
51da978630SJohn Beckexist_or_exit()
52da978630SJohn Beck{
53da978630SJohn Beck	if [ ! -f $1 ]; then
54da978630SJohn Beck		echo "$1 does not exist" >&2
55da978630SJohn Beck		exit $SMF_EXIT_ERR_CONFIG
56da978630SJohn Beck	fi
57da978630SJohn Beck}
58da978630SJohn Beck
59da978630SJohn Beckturn_m4_crank()
60da978630SJohn Beck{
61da978630SJohn Beck	# expected to be called with two arguments: .cf path & path to m4 file
62da978630SJohn Beck	[ $# -lt 2 ] && return
63da978630SJohn Beck	cf_path=$1
64da978630SJohn Beck	m4_path=$2
65da978630SJohn Beck	if [ "$m4_path" = "_DONT_TOUCH_THIS" ]; then
66da978630SJohn Beck		if [ -f "${cf_path}.old" ]; then
67da978630SJohn Beck			mv "$cf_path" "${cf_path}.new"
68da978630SJohn Beck			[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
69da978630SJohn Beck			mv "${cf_path}.old" "$cf_path"
70da978630SJohn Beck			[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
71da978630SJohn Beck		fi
72da978630SJohn Beck		#
73da978630SJohn Beck		# If ${cf_path}.old does not exist, assume it was taken care
74da978630SJohn Beck		# of on a previous run.
75da978630SJohn Beck		#
76da978630SJohn Beck	else
7739b0b3b7SJohn Beck		case "$m4_path" in
7839b0b3b7SJohn Beck		/*)	;;	# absolute path
7939b0b3b7SJohn Beck		*)	return;;
8039b0b3b7SJohn Beck		esac
81da978630SJohn Beck		exist_or_exit "$m4_path"
82da978630SJohn Beck		cd `dirname "$m4_path"`
83da978630SJohn Beck		base=`basename "$m4_path"`
84da978630SJohn Beck		name=`basename "$m4_path" .mc`
85da978630SJohn Beck		info=`svcprop -p config/include_info $SMF_FMRI 2>/dev/null`
86da978630SJohn Beck		if [ "$info" = "true" ]; then
87da978630SJohn Beck			m4flags=""
88da978630SJohn Beck		else
89da978630SJohn Beck			m4flags="-DSUN_HIDE_INTERNAL_DETAILS"
90da978630SJohn Beck		fi
91da978630SJohn Beck		m4 $m4flags /etc/mail/cf/m4/cf.m4 "$base" > "${name}.cf"
92da978630SJohn Beck		[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
93da978630SJohn Beck		cmp -s "${name}.cf" "$cf_path" || (
94da978630SJohn Beck			cp "${name}.cf" "${cf_path}.tmp" &&
95da978630SJohn Beck			chown root:bin "${cf_path}.tmp" &&
96da978630SJohn Beck			chmod 444 "${cf_path}.tmp" &&
97da978630SJohn Beck			mv "${cf_path}.tmp" "$cf_path"
98da978630SJohn Beck		)
99da978630SJohn Beck		[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
100da978630SJohn Beck	fi
101da978630SJohn Beck}
102