#!/bin/sh
# Copyright (c) 1992, 1993 Black Market Technologies, Inc.
# This is proprietary software.  You must purchase a license for each computer
# on which you want to use this software.  For complete licensing information, 
# check the license agreement that came with this software or contact
# Black Market Technologies at +1 718 522-5090.
# 
# Usage: $0 port
# $Id: is-mailhost,v 1.6 1993/08/15 07:52:37 treed Exp $
# $Author: treed $ $Date: 1993/08/15 07:52:37 $

# get mailhost name

CIN=22

PROMPT="Connect It: ${CIN}: "
APP_PATH=$1
shift
PATH="${APP_PATH}/Scripts:${APP_PATH}:/etc:/usr/etc:/usr/ucb:/bin:/usr/bin"
export PATH

YES=0
NO=1
PROBLEM=9

MAILHOST="`niutil -read . /locations/sendmail | grep mailhost: | awk '{print $2}'`"
SENDMAIL_FILENAME="`${APP_PATH}/Scripts/get-sendmail.cf-filename ${APP_PATH}`"

if test $# != 1 ; then
#   echo "${PROMPT} No mailhost specified" >&2
  exit ${NO}
fi

if test "${MAILHOST}" != "" ; then
#   echo "${PROMPT} Mailhost entry found" >&2
  if test "${MAILHOST}" = $1 ; then
#     echo "${PROMPT} mailhost confirmed" >&2
    exit ${YES}
  else
#     echo "${PROMPT} mailhost not confirmed" >&2
    exit ${NO}
  fi
fi

if test ! -f ${SENDMAIL_FILENAME} ; then
#   echo "${PROMPT} Could not locate sendmail file ${SENDMAIL_FILENAME}" >&2
  exit ${PROBLEM}
fi

MAILHOST="`egrep '^DR' ${SENDMAIL_FILENAME} | sed 's/^DR//'`"

if test "${MAILHOST}" = "" ; then
#   echo "${PROMPT} No mailhost found in file" >&2
  exit ${NO}
elif test "${MAILHOST}" = $1 ; then
#   echo "${PROMPT} Mailhost found in file" >&2
  exit ${YES}
else
  # Check this out
  exit ${NO}
fi
