#!/bin/sh
## init_fedora_x
## changes Fedora Core X sendmail.conf in /etc/mail

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

. ./ansi.sh

# Test for the right Redhat releases
if [ -f /etc/redhat-release ]; then
	grep -qiE 'red hat linux.*[789]\.?]' /etc/redhat-release
	if [ $? -eq 0 ]; then
		echo "Located a Red Hat 7/8/9.x release"
		isright=1
		fi
fi

if [ -f /etc/fedora-release ]; then
	grep -qiE 'fedora core release.*[123]' /etc/fedora-release
	if [ $? -eq 0 ]; then
		echo "Located a Fedora Core 1/2/3 release"
		isright=1
		fi
fi


if [ $isright -eq 0 ]; then
# This is not a RedHat or Fedora Core system
	exit 1
	fi



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


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

	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"
			printf "Press Return to continue..."
			read foo
			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"
	printf "Press Return to continue..."
	read foo
	fi


