#!/usr/bin/ksh
# *****************************************************************
# *                                                               *
# *    Copyright (c) Digital Equipment Corporation, 1999          *
# *                                                               *
# *   All Rights Reserved.  Unpublished rights  reserved  under   *
# *   the copyright laws of the United States.                    *
# *                                                               *
# *   The software contained on this media  is  proprietary  to   *
# *   and  embodies  the  confidential  technology  of  Digital   *
# *   Equipment Corporation.  Possession, use,  duplication  or   *
# *   dissemination of the software and media is authorized only  *
# *   pursuant to a valid written license from Digital Equipment  *
# *   Corporation.                                                *
# *                                                               *
# *   RESTRICTED RIGHTS LEGEND   Use, duplication, or disclosure  *
# *   by the U.S. Government is subject to restrictions  as  set  *
# *   forth in Subparagraph (c)(1)(ii)  of  DFARS  252.227-7013,  *
# *   or  in  FAR 52.227-19, as applicable.                       *
# *                                                               *
# *****************************************************************
#
# sendmail_patch.ksh
#
# This script fixes a problem with protocol configuration in the Open Source
# Internet Solutions V5.0 sendmail subset (IAFWSMTP500).
#
echo "Open Source Internet Solutions V5.0 sendmail patch script"

if [[ "`whoami`" != "root" ]]; then
  echo "Must be root to run this script."
  exit 1
fi

# patch only useful if user installed Sendmail from a version 5.0 kit.
if [[ ! -f /usr/.smdb./IAFWSMTP500.lk ]]; then
  echo "This patch only applies to the Open Source Internet Solutions V5.0"
  echo "sendmail subset (IAFWSMTP500) which is not installed."
  exit 1
fi

CONFIGURED=0

# Build list of files to patch

# Find if sendmail has been configured or not. If configured, then
# patch sendmail.cf file, else only patch sendmail.cf.pd file.

if [[ -e /var/adm/sendmail/sendmail.cf.orig ]]; then
    CONFIGURED=1
    if [[ -e /var/adm/sendmail/sendmail.cf ]]; then
	FILES="/var/adm/sendmail/sendmail.cf"
	cp /var/adm/sendmail/sendmail.cf /var/adm/sendmail/sendmail.cf.pre-patch
    fi
fi
if [[ -e /var/adm/sendmail/sendmail.cf.pd ]]; then
  FILES="${FILES} /var/adm/sendmail/sendmail.cf.pd"
fi

# Patch them
echo "Now patching sendmail configuration files... "
for file in ${FILES} ; do
  ed -s $file <<-endofinput >/dev/null 2>&1
	g/phaseV protocol /s/protocol/protocols/
	g/phaseIV protocol /s/protocol/protocols/
	g/uucp protocol /s/protocol/protocols/
	g/x25 protocol /s/protocol/protocols/
	w
	q
	endofinput
done
echo "done."

cp /var/adm/sendmail/sendmail.cf.pd /var/adm/sendmail/sendmail.m4

if [[ $CONFIGURED -ne 0 ]]; then
  . /usr/internet/cluster/cluster_support
  for_all_members '/sbin/init.d/sendmail restart'
  echo "The sendmail daemon has now been restarted."
else
  echo "You must now run the mail configuration utility."
  sleep 3
  /usr/sbin/mailconfig
fi

exit 0
#
# end of sendmail_patch.ksh
