Current File : //lib/svc/share/sendmail_include.sh
#!/usr/sbin/sh
#
# Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.

DEFAULT_FILE="/etc/default/sendmail"
SENDMAIL="/usr/lib/inet/sendmail"
PATH="/usr/bin:/usr/sbin"
export PATH

check_queue_interval_syntax()
{
	default="15m"
	if [ $# -lt 1 ]; then
		answer=$default
		return
	fi
	if echo $1 | egrep '^([0-9]*[1-9][0-9]*[smhdw])+$' >/dev/null 2>&1; then
		answer=$1
	else
		answer=$default
	fi
}

check_and_kill()
{
	PID=`head -1 $1`
	kill -0 $PID > /dev/null 2>&1
	[ $? -eq 0 ] && kill $PID
}

exist_or_exit()
{
	if [ ! -f $1 ]; then
		echo "$1 does not exist" >&2
		exit $SMF_EXIT_ERR_CONFIG
	fi
}

turn_m4_crank()
{
	# expected to be called with two arguments: .cf path & path to m4 file
	[ $# -lt 2 ] && return
	cf_path=$1
	m4_path=$2
	if [ "$m4_path" = "_DONT_TOUCH_THIS" ]; then
		if [ -f "${cf_path}.old" ]; then
			mv "$cf_path" "${cf_path}.new"
			[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
			mv "${cf_path}.old" "$cf_path"
			[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
		fi
		#
		# If ${cf_path}.old does not exist, assume it was taken care
		# of on a previous run.
		#
	else
		case "$m4_path" in
		/*)	;;	# absolute path
		*)	return;;
		esac
		exist_or_exit "$m4_path"
		cd `dirname "$m4_path"`
		base=`basename "$m4_path"`
		name=`basename "$m4_path" .mc`
		m4flags="-D_CF_DIR_=/etc/mail/cf/"
		info=`svcprop -p config/include_info $SMF_FMRI 2>/dev/null`
		if [ "$info" != "true" ]; then
			m4flags="$m4flags -DSUN_HIDE_INTERNAL_DETAILS"
		fi
		m4 $m4flags /etc/mail/cf/m4/cf.m4 "$base" > "${name}.cf"
		[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
		cmp -s "${name}.cf" "$cf_path" || (
			cp "${name}.cf" "${cf_path}.tmp" &&
			chown root:bin "${cf_path}.tmp" &&
			chmod 444 "${cf_path}.tmp" &&
			mv "${cf_path}.tmp" "$cf_path"
		)
		[ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG
	fi
}