#sccs	"@(#)term513:Install	1.13"


LIST1="ELD.ft BLD.ft VBM.ft SCLD.ft UK.ft ROMC.ft ROMG.ft"
LIST2="te.hlp"

NAME=`cat /etc/.phinit`

# Can only install ATE if AT&T PHMGR currently exist on the system

if [ "$NAME" != "/etc/ph" ]
then
	message  -i "This system will install ATE only if AT&T Phone Manager has been installed.  Please install AT&T Phone Manager first.  This ATE will NOT be installed."

	exit 64
fi

if [ -f /usr/bin/async_main ]
then
	message -i "This system already has ATE, please remove it before installing this ATE.  This ATE will NOT be installed."
	
	exit 64
fi

SWAP=false

for i in $LIST1
do
	if [ -f /usr/lib/wfont/$i ]
	then
		diff /usr/lib/wfont/$i $i >/dev/null 2>&1
		if [ "$?" != 0 ]
		then
			SWAP=true
			break
		fi
	else
		SWAP=true
		break
	fi
done


if $SWAP
then
	message -c "ATE font files already exist in the system but are different or some ATE font files are missing.  Therefore, this install will swap in new ATE font files."
	if [ "$?" != 0 ]
	then
		exit 64
	fi
fi


echo '               Installing ATE ...'

#save foundation version of umodem

mv /usr/bin/umodem /usr/bin/.umodem.tmp 2>/dev/null

mv async_main /usr/bin
chown root /usr/bin/async_main
chgrp root /usr/bin/async_main
chmod 755 /usr/bin/async_main

mv umodem /usr/bin
chown root /usr/bin/umodem
chgrp root /usr/bin/umodem
chmod 755 /usr/bin/umodem


echo '               Installing font files ...'

# save foundation version of ATE required fonts

for i in $LIST1
do
	if $SWAP
	then
		mv /usr/lib/wfont/$i /usr/lib/wfont/.$i.tmp 2>/dev/null
		mv $i /usr/lib/wfont
	fi
	chown root /usr/lib/wfont/$i
	chgrp sys /usr/lib/wfont/$i
	chmod 644 /usr/lib/wfont/$i
done

for i in $LIST2
do
	mv $i /usr/lib/ua
	chown bin /usr/lib/ua/$i
	chgrp bin /usr/lib/ua/$i
	chmod 644 /usr/lib/ua/$i
done

# Add ATE entries to Suffixes

echo "               Updating Suffixes file ..."

cat > /tmp/t << -END-

Name= Modem Profile
Suffix =:Am
Default = Open
Description =*Modem Profile
Location = Profiles
Open = EXEC -d /usr/bin/async_main r %o e
Create = EXEC -d /usr/bin/async_main r %o e
Help   = EXEC -d /usr/bin/uahelp -h $UA/ua.hlp -t "Profile file"
Print = ERROR Can't print Modem Profile
-END-

uaupd -r "Modem Profile" -a /tmp/t Suffixes

cat > /tmp/t << -END-

Name= RS-232 Profile
Suffix =:A2
Default = Open
Description =*RS-232 Profile
Location = Profiles
Open = EXEC -d /usr/bin/async_main r %o e
Create = EXEC -d /usr/bin/async_main r %o e
Help   = EXEC -d /usr/bin/uahelp -h $UA/ua.hlp -t "Profile file"
Print = ERROR Can't print RS-232 Profile
-END-

uaupd -r "RS-232 Profile" -a /tmp/t Suffixes

rm -f /tmp/t

# Add ATE entries to Comm_pkgs

# Make sure file exist

touch /usr/lib/ua/Comm_pkgs

echo "               Updating Comm_pkgs ..."
echo > /tmp/t
echo "Name=ATE_Modem" >> /tmp/t
echo "Suffix=:Am" >> /tmp/t
echo "Connection=OBM" >> /tmp/t
echo "Setup=/usr/bin/async_main r PROFNAME f DEVICE p PID i FN" >> /tmp/t
echo "Nosetup=/usr/bin/async_main r PROFNAME f DEVICE p PID" >> /tmp/t
echo "Create=/usr/bin/async_main r PROFNAME e" >> /tmp/t
echo "Modify=/usr/bin/async_main r PROFNAME e" >> /tmp/t
echo "Originate=BOTH" >> /tmp/t

uaupd -r ATE_Modem -a /tmp/t Comm_pkgs

rm -f /tmp/t

echo > /tmp/t
echo "Name=ATE_Serial" >> /tmp/t
echo "Connection=DIR" >> /tmp/t
echo "Suffix=:A2" >> /tmp/t
echo "Setup=/usr/bin/async_main r PROFNAME f DEVICE p PID i FN" >> /tmp/t
echo "Nosetup=/usr/bin/async_main r PROFNAME f DEVICE p PID" >> /tmp/t
echo "Create=/usr/bin/async_main r PROFNAME e" >> /tmp/t
echo "Modify=/usr/bin/async_main r PROFNAME e" >> /tmp/t
echo "Originate=BOTH" >> /tmp/t

uaupd -r ATE_Serial -a /tmp/t Comm_pkgs
rm -f /tmp/t

echo "            ATE installation is completed."

# Test if update comm_packages file exist - exit if file don't exist

if [ ! -f /etc/cpupd ]
then
	exit 0
fi

# file exist, EXEC /etc/cpupd to inform phone manager to update comm packages

/etc/cpupd
