#!/bin/sh

. ./ansi.sh
isright=0

if [ -f /etc/slackware-version ]; then
	if [ -f /etc/rc.d/rc.sendmail ]; then
		isright=1
		rcfile=/etc/rc.d/rc.sendmail
	
	elif [ -f /etc/rc.d/rc.M ]; then
		isright=1
		rcfile=/etc/rc.d/rc.M
	fi	
fi

if [ $isright -eq 0 ]; then
	exit 1
	fi


xamimepath=$1

alreadydone=`grep xamime $rcfile | wc -l`

if [ $alreadydone -gt 0 ]; then
        printf "Slackware init alterations to start Xamime already done.\n"
        exit 0
fi


if [ -e /etc/rc.d/rc.M ]
then
	linecount=`grep sendmail $rcfile | grep " -bd" | wc -l`
	if [ $linecount -gt 0 ]
	then
		printf "Sendmail daemon startline located..."
		./replaceit --input=$rcfile "sendmail" "sendmail -C $xamimepath/xamime.cf" "-xamime.cf" "-if" "+-bd" "-echo"
		linecount=`grep "xamime.cf" $rcfile | wc -l`
		if [ $linecount -gt 0 ]
		then
			printf "${dg}successful update${doff}..."
		else
			printf "${dg}Update did not succeed, please add '-C $xamimepath/xamime.cf' manually\n\
to your $rcfile sendmail startup routine...${doff}"
		fi
		printf "${don}done${doff}\n"
	fi
fi


