#sccs	"@(#) /b4/law/sccs/ph/s.Remove 1.1"

set +x

LIST0="phpinks phnum phcreate phpref phstub Phones.sh"
LIST1="phone.hlp Phones.form"
LIST2="ph cpupd"


# check if async_ma is an active process

ps -e | grep async_ma | \
  while read PID TTY TIME COMMAND
do
	if [ "$COMMAND" = "async_ma" ]
	then	
	message -i "Currently someone is using ATE, and ATE depends on the Phone Manager, therefore; this Phone Manager REMOVE will not take place."
	exit 64
	fi
done

if [ $? = 64 ]
then
	exit 64
fi

message  -c "Warning: Be sure no users are using the Phone Manager.  The following will remove all previous phone related files and kill any active phone process.  Also, some terminal emulator programs may depend on the Phone Manager to execute properly."

if [ "$?" != 0 ]
then
	exit 64
fi

# Kill old phone manager process

zap ph

echo '               Removing Phone Manager ...'

for i in $LIST0
do

	rm -f /usr/bin/$i
done

for i in $LIST1
do
	rm -f /usr/lib/ua/$i
done

for i in $LIST2
do
	rm -f /etc/$i
done

# Remove phone entries in Office, Prefernces and Suffixes

echo "               Updating Office files ..."

uaupd -r Telephone Office

uaupd -r "Phone Manager" Preferences

uaupd -r "Phone Directory" Suffixes

uaupd -r "Phone Number" Suffixes

uaupd -r "Text Phone Directory" Suffixes

# Restore initial Phones.sh and Phones.form

mv /usr/bin/Phonesinit.sh /usr/bin/Phones.sh
mv /usr/lib/ua/Phonesinit.form /usr/lib/ua/Phones.form

# Remove the LOCK files set up by phone manager

PHPID=`cat $UA/phpid`

if [ -f /usr/spool/uucp/LCK..ph0 ]
then
	set `od -d /usr/spool/uucp/LCK..ph0`
	LCKPID0=$2$3
	RESULT0=`expr $LCKPID0 - $PHPID`

	if [ "$RESULT0" = "0" ]
	then
		rm -f /usr/spool/uucp/LCK..ph0
	fi
fi

if [ -f /usr/spool/uucp/LCK..ph1 ]
then
	set `od -d /usr/spool/uucp/LCK..ph1`
	LCKPID1=$2$3
	RESULT1=`expr $LCKPID1 - $PHPID`

	if [ "$RESULT1" = "1" ]
	then
		rm -f /usr/spool/uucp/LCK..ph1
	fi
fi

# remove the LTMP files

rm -f /usr/spool/uucp/LTMP* 

# write /etc/.phclr to /etc/.phinit and EXEC /etc/.phclr

echo "/etc/.phclr" > /etc/.phinit

/etc/.phclr
