#!/bin/sh -
#
# @(#)mk-afs-odmfix-sendmail	1.3 (hursley) 10/31/96
# /afs/hursley.ibm.com/common/src/afs/@cell/rs_aix32/usr/local/sbin/mk-afs-odmfix-sendmail/SCCS/s.mk-afs-odmfix-sendmail
#
# NAME		mk-afs-odmfix-sendmail
# AUTHOR	Paul Blackburn <mpb@acm.org>
# PURPOSE	Script to change ODM SRCsubsys so that sendmail invocation
#		is replaced by program (wrapper) that gets AFS authentication
#		then starts sendmail.
#
#		Default wrapper is:
#			${afs_install_base}/usr/local/sbin/mk-afs-sendmail
#		or you can
#		supply the name of the wrapper file on the command line:
#		mk-afs-odmfix wrapper_file_name
#
#		Once the ODM change is made, you can stop and start the
#		AFS authenticating version by using normal srcmstr commands.
#		eg: stopsrc -s sendmail
#		    startsrc -s sendmail -a "-bd -q30m"
#
# USAGE		This program is run once to set up AFS authenticated
#		mail delivery.
#
# DEINSTALL	To recover the ODM to its default state run:
#		mk-afs-odmfix /usr/lib/sendmail
#
# CAUTION	Do not attempt to use the mk-afs-sendmail wrapper program
#		unless you have:
#		a) a working reauth installed
#		b) configured mk-afs-sendmail to authenticate as an AFS ID
#		   (eg postman) authorised to deliver mail into $HOMEs
#		c) Set an ACL on $HOMEs to allow mail delivery
#		   (eg: fs sa $HOME postman liwk)
#
#		See: ftp://grand.central.org:/pub/afs-contrib/tools/reauth

CMD=$(basename ${0})

ODMDIR=/etc/objrepos; export ODMDIR
old=/tmp/${CMD}.$$

if [ -z "${1}" ]; then
	wrapper=${afs_install_base}/usr/local/sbin/mk-afs-wrap-sendmail
else
	wrapper=${1}
	if [ ! -f ${wrapper} ]; then
		echo "no such file: ${wrapper}" >&2
		exit 1
	else
		if [ ! -x ${wrapper} ]; then
			echo "${wrapper} not executable" >&2
			exit 1
		fi
	fi
fi

odmget -q "subsysname = sendmail" SRCsubsys > ${old}

ed - ${old} <<%
/path =
d
i
	path = ${wrapper}
.
w
q
%

odmdelete -o SRCsubsys -q "subsysname = sendmail"
odmadd ${old}
odmget -q "subsysname = sendmail" SRCsubsys
