#!/bin/sh
#
#	/*name and version number:@(#)ltinst	1.3*/
#	/*date of get: 		  05/10/00 11:23:50*/
#	/*date of delta:	  12/28/99 12:10:46*/
#===========================================================================
#       File Name :     ltinst
#===========================================================================
#     Actions are:
# /dev/ttyLT0  made
# Standard symbolic link made  /dev/modem /dev/ttyLT0
# Symbolic link /dev/ttyS14 --> /dev/ttyLT0 made for backward compatibility
#  and to support dialup utilities such as wvdial
# ltmodem.o copied into modules PATH
# Dependencies redone with    depmod -a
# Demand loading of ltmodem.o enabled with:
#  /etc/modules.conf: alias char-major-62 ltmodem
echo
echo "  This $0 command should be executed only by Root."
echo "  Your login name is: "`whoami`.
echo "  Please stop any current PPP session."
echo "  Abort if necessary with:    Ctrl-C "
echo
sleep 5
      
###  Making nodes
group="uucp"
mode="666"


device="/dev/ttyLT0"
olddevice="/dev/ttyS14"

./ltuninst > /dev/null 2>/dev/null

rm -f $device

mknod $device c 62 64

rm -f /dev/modem

ln -s $device /dev/modem
ln -s $device $olddevice

chgrp $group $device
chmod $mode $device
echo "	"
echo "	"Made $device and two symbolic links:
ls -l $device
ls -l /dev/modem
ls -l $olddevice
echo "	to support dialup configuration utilities."
echo
sleep 5

echo "   Copying ltmodem.o into the modules tree now."
KV=`uname -r | cut -c 1-3`
SYS=`uname -r`
echo "	The current kernel version is:  $SYS"
if [ "$KV" = "2.4" ] ; then
cp ltmodem.o /lib/modules/$SYS/kernel/drivers/char/
else
cp ltmodem.o /lib/modules/$SYS/misc/
fi
echo "	Within the modules path: /lib/modules/$SYS/ ,ltmodem.o should now be displayed::"
ls -lR  /lib/modules/$SYS/ | grep ltmodem.o 
echo
sleep 5


## configure auto loading of module
if [ -f /etc/modutils/aliases ]; then
MCFILE=/etc/modutils/aliases

else
MCFILE=/etc/conf.modules
if [ -f /etc/modules.conf ]; then
MCFILE=/etc/modules.conf
fi

fi

if ! grep "alias char-major-62" $MCFILE >/dev/null 2>&1 ; then
echo "alias char-major-62 ltmodem" >> $MCFILE
fi
# To drive autoloading of isa-pnp.o dependent of ltmodem.o under 2.4.nn      
if [ "$KV" = "2.4" -a -f /lib/modules/$SYS/kernel/drivers/pnp/isa-pnp.o ] ;then
echo "  Modular isa-pnp.o found."
if ! grep "ltmodem isa-pnp" $MCFILE >/dev/null 2>&1 ; then
echo "below ltmodem isa-pnp" >> $MCFILE
fi
fi

# To avoid non-relevant complaint noise that would be generated during
#    depmod -a   within update-modules
# under 2.4.nn kernels due to the symbolic Link
#   /lib/modules/2.4.nn/build --> /usr/src/linux
#  if kernel-source "make clean" is run betweem build_module & ltinst
# the Link is moved to  /tmp and after "update-modules" is  restored.
if [ -f /etc/modutils/aliases ]; then
if [ -L /lib/modules/$SYS/build ]; then
mv /lib/modules/$SYS/build /tmp
update-modules
mv /tmp/build /lib/modules/$SYS/
else
update-modules
fi
else
depmod -a
fi

echo "  Modules dependencies have been updated."
echo "  Demand loading is enabled by:"
grep modem /etc/modules.conf
echo "  within /etc/modules.conf"
echo
sleep 5

## Testing insertion
echo "  Preparing for ltmodem.o insertion test"
echo "  Removing any currently inserted module:   ltmodem"
# poff
# sleep 2
rmmod ltmodem
echo
echo "  The ltmodem with any dependent modules should now be displayed by the test:   "
echo "  modprobe ltmodem"
modprobe ltmodem
lsmod | grep ltmodem
echo
sleep 5

## Reserve
echo "  A reserve  ltmodem.o backup is being copied out:"
cp ltmodem.o ../ltmodem.o_$SYS
echo "  Current reserve copies are:"
ls ../ltmodem.o_*
echo
sleep 5

## Advice
echo "	Installation of ltmodem support is now completed."
echo "	But to enable dialout, Editing /dev/ttyLT0 into a dialout script"
echo "	may be necessary. For ppp initated by pon, it would be among:"
grep -is "/dev/" /etc/ppp/peers/*
echo
sleep 5 

## Clean up
# echo "  Compile intermediates will by removed with: make clean"
# echo "  unless Aborted with Ctrl-C"
# echo
# sleep 5
# make clean

echo "   =====================  End $0, ENJOY =============================="
