#!/usr/bin/ksh 
# ###########################################################
# This is script configures an IBM or MegaHertz PCMCIA cards.
# Also, this script is specific to ONLY 28.8 Data/Fax cards.
# Reason for this is that each PCMCIA card is hardwired with
# a unique Manufacturer ID. This script, for the most part,
# would install (if already not installed) the device driver 
# from the AIX 4.1.4 CD. It then attemps to configure the 
# PCMCIA card.
#############################################################

#############################################################
# Requirement to run this script:
#	1) HAVE AIX 4.1.4 CDROM
#	2) HAVE THE ROOT PRIVILEDGES
#	3) Have either IBM or MegaHertz PC card
#############################################################

#############################################################
# Script courtesy of the PC Company HelpCeter, RTP, NC
# Script Created: March 13, 1996
#############################################################
USER=`whoami`
OS=`oslevel`
ODMSUCCESSFUL=FALSE
if [ "$USER" != "root" ] || [ "$OS" != "4.1.4.0" ]
	then
	clear
	echo 'Cannot run this script!!'
	echo "Either you are NOT logged in as root OR" 
	echo "You are at an earlier level of AIX then 4.1.4"
	echo "Exiting..."
	exit 1
fi
/usr/bin/clear 
function header { 
echo "               +=========================================+"
echo "               |       IBM PC COMPANY HELPCENTER         |"
echo "               | This script configures an UNSUPPORTED   |" 
echo "               |    IBM PCMCIA 28.8(V.34)/14.4 Kbs       |"
echo "               |  	   Data/FAX Modem                |"
echo "               |          Part Number: 25H6420           |"  
echo "               |                   OR                    |"
echo "               |     MegaHertz 28.8/14.4kbps Data/Fax    |"
echo "               |             on AIX 4.1.4.0              |"
echo "               +=========================================+"
}; header
echo "======================================================================="
echo "Please use this script with the following understanding:"
echo "IBM WILL NOT BE RESPONSIBLE FOR DAMAGES OF ANY KIND RESULTING "
echo "FROM ITS USE. THE USE OF THIS INFORMATION IS THE SOLE RESPONSIBILITY"
echo "OF THE CUSTOMER AND DEPENDS ON THE CUSTOMER'S ABILITY TO EVALUATE"
echo "AND INTEGRATE THIS SCRIPT INTO THE CUSTOMER'S OPERATIONAL ENVIRONNMENT"
echo ""
echo "======================================================================="
echo "This script has been tested with ONLY IBM & Megahertz 28.8 PCMCIA cards."
echo "During the test, configuration of the above PC cards were successful."
echo "This, however, doesn't imply any implicit or explicit guarentee"
echo "that the cards would configure in all the possible environments."
echo ""
echo "======================================================================="
echo "Do you still want to continue with modem config./install. (y/n)? \c"
read ANSWER
if [ "$ANSWER" = "y" ] || [ "$ANSWER" = "Y" ]
	then
	echo ""
	echo "1) Make sure that AIX 4.1.4 CDROM is in the Drive."
	echo "2) Make sure that PCMCIA (28.8) Card is in the Slot."
	echo "Press >>>>CONTROL+C<<<< to exit script if the above device and the media"
	echo "is not already in the machine."
fi
if [ "$ANSWER" = "y" ] || [ "$ANSWER" = "Y" ]
	then
	if [ ! -f /tmp/modem/attr.NEW.IBM ] && [ ! -f /tmp/modem/attr.NEW.MHz ]
	then
		echo "Error in finding script library files."
		echo "Exiting script without any confiuguration."
		exit 1
	fi
echo "Enter What Modem Type You are using, IBM or MHz.(ibm/mhz)"
echo "Modem Type? \c"
read MODEMTYPE 
	if [ "$MODEMTYPE" != "ibm" ] && [ "$MODEMTYPE" != "mhz" ]
	then
		echo "Error. Incorrect Modem Type Entered."
		echo "Exiting..."
		exit 1
	else
		echo ""
		echo "MAKE SURE THAT THE "
		echo "1) MODEM IS IN THE PCMCIA SLOT."
		echo "2) MODEM IS INSERTED PROPERLY."
		echo 'PRESS >>>control+C<<< if the card is NOT already'
		echo "in the slot and then Re-Run this script."
		echo "Sleeping for 7 seconds..."
		sleep 7
	fi
fi
if [ "$ANSWER" = "y" ] || [ "$ANSWER" = "Y" ]
then
	clear
	header
 	echo ""
	echo "===================================="
	echo "Check, Verify Device Driver Routine."
	echo "===================================="
	if [ -d /usr/lpp/devices.pcmcia.a4001d00 ]
	then
		echo "You already have the Needed Modem Driver Installed."
		echo "Now all we have to do is to configure it."
		echo "Sleeping for 10 seconds..."
		sleep 10
	else
		echo "Modem Device Driver NOT installed."
		echo "Ensure that AIX 4.1.4 CDROM is in the CDROM Drive."
		echo "Waiting for 10 seconds..."
		sleep 10
		echo "Driver Installation Initiated."
		/usr/lib/instl/sm_inst installp_cmd -T iems -L -q -a -d '/dev/cd0' -o '4.1.3.0 devices.pcmcia.a4001d00		ALL @@devices.pcmcia.a4001d00' '-c' '-N' '-g' '-X'  '-G'
		sleep 10
		if [ $? = 0 ]
			then
			echo "Installation Complete and Successful.."
			echo  "Sleeping for 10 secs..."
			sleep 10
			else
			echo "Installation Encountered a Problem.."
			echo "Sleeping for 5 seconds..."
			sleep 5
			echo "Aborting..."
			exit 1
		fi
	fi
echo ""
clear
header
echo ""
echo "===================================="
echo " RETRIEVE Device Attribute Routine. "
echo "===================================="
echo ""
echo "Next, device attribute for a4002900 will be RETRIEVED."
echo ""
echo "Saving Original Device Attributes to /tmp/attrs.ORIG"
echo ""
/usr/bin/odmget -q "uniquetype=adapter/pcmcia/a4001d00" PdAt > /tmp/attrs.ORIG
/usr/bin/odmget -q "uniquetype=adapter/pcmcia/a4001d00" PdCn >> /tmp/attrs.ORIG
/usr/bin/odmget -q "uniquetype=adapter/pcmcia/a4001d00" PdDv >> /tmp/attrs.ORIG
echo "Retrieval Done..."
echo "Sleeping for 10 seconds."
sleep 10
clear
header
echo ""
echo "===================================="
echo "  DELETE Device Attribute Routine.  "
echo "===================================="
echo ""
echo "Next, device attribute for a4002900 will be DELTED from ODM."
echo ""
/usr/bin/odmdelete -q "uniquetype=adapter/pcmcia/a4001d00" -o PdAt
/usr/bin/odmdelete -q "uniquetype=adapter/pcmcia/a4001d00" -o PdCn
/usr/bin/odmdelete -q "uniquetype=adapter/pcmcia/a4001d00"  -o PdDv
echo ""
echo "Done deleting all the attributes from the ODM database."
echo "Sleeping for 10 seconds..."
sleep 10
clear
header
echo ""
echo "===================================="
echo " ReGenerate Device Attribute in ODM "
echo "===================================="
echo "Earlier you had selected your MODEM TYPE to be: $MODEMTYPE"
echo "Now Creating an ODM entry for $MODEMTYPE modem."
if [ "$MODEMTYPE" = "ibm" ]
then
	/usr/bin/odmadd /tmp/modem/attr.NEW.IBM
	if [ $? = 0 ]
	then
	 echo "ODM Entry Successful."
         ODMSUCCESSFUL=TRUE
	 sleep 6
	 else
	 echo "Error in Creating Entry in ODM."
	 echo "Critical Error."
	 echo "Aboring script"
	 exit 1
	fi
		
fi
if [ "$MODEMTYPE" = "mhz" ]
then
   /usr/bin/odmadd /tmp/modem/attr.NEW.MHz
   if [ $? = 0 ]
     then
       echo "Entry Successful."
       ODMSUCCESSFUL=TRUE
       sleep 6
     else
	echo "Error in Creating Entry in ODM."
	echo "Critical Error."
	echo "Aboring script"
	exit 1
   fi
fi
echo ""

if [ "$ODMSUCCESSFUL" = "TRUE" ]
then
   echo "Since the ODM entry was successful..the script"
   echo "will now attempt to see if the Operating System Will" 
   echo "recognize the PCMCIA card.."
   /usr/sbin/cfgmgr
	if [ $? = 0 ]
	then
   		CARD=`lscfg|grep -i modem| awk '{print $4,$5,$6,$7,$8}'`
		echo ""
		echo "============================================"
		echo '           Congratulations!!!!              '
		echo ""
		echo "Looks like the confiuration was successful."
		echo ""
		echo "Card: $CARD."
		echo "============================================"
		sleep 5
	else
		echo "AIX, for some odd reason was not able to recognize you PCMCIA Card."
	fi
fi
echo "All done..."
echo "Modem driver has been Installed and Configured."
echo ""
echo "NOTES:"
echo "During the initialization and configuration of your modem,"
echo "some device attributes files were saved to the temporary"
echo "directory. In most cases you will NOT need these files,"
echo "unless you know that you have a specific/known reason to"
echo "save them."
echo "Do you want to DELETE these files? (y/n)\c"
read ANSWER2
if [ "$ANSWER2" = "y" ] || [ "$ANSWER2" = "Y" ]
	then
	echo "Deleting Original Configuration files."
        /usr/bin/rm -f /tmp/attrs.ORIG
	echo "Deleted files."
	echo "ALL DONE."
fi
else
	echo "You selected NOT to run this configuration for the answer..."
	echo "Script Aborting...."
fi
# *********************** END OF SCRIPT ***********************
