#!/bin/sh
## init_rhat
## changes RedHat sendmail.conf in /etc/mail

# Set our ANSI codes
don="\033[0;33m"
doff="\033[0m"
dg="\033[0;32m"
dw="\033[0;37m"
dr="\033[0;31m"
dbw="\033[1;37m"
dnw="\033[0;37m"
dbb="\033[1;34m"
dnb="\033[0;34m"
dbg="\033[1;32m"
dng="\033[0;32m"
bon=$don
boff=$doff


xamimepath=$1
rcfile="/etc/init.d/sendmail"

if [ -f $rcfile ]; then
	isright=1
	else
	exit 1
	fi

alreadydone=`grep xamime $rcfile | wc -l`
if [ $alreadydone -gt 0 ]; then
	printf "RedHat init alterations to start Inflex already done.\n"
	exit 0
fi


if [ -e $rcfile ]
	then
	printf "$dg Altering init.d sendmail file.. $doff"
	./replaceit --input=$rcfile "sendmail" "sendmail -C $xamimepath/xamime.cf" "{daemon" "}DAEMON" "-xamime"

	sleep 2
	count=`grep "xamime.cf" $rcfile | wc -l`
	if [ $count -gt 0 ]
		then
		printf "${don}Success.. $doff\n"
		else
			printf "${dr}Update did not succeed, please add '-C $xamimepath/xamime.cf' manually\n\
			to your $conf_file sendmail startup routine...$doff"
			fi
	else
	printf "$dr Sorry, could not find sendmail startup file\n\
	You have to manually find out how sendmail is started and append\n\n
		$dg -C $xamimepath/xamime.cf$doff\n\n
	${dr}to it.$doff\n"
	fi

