# @(#)dlk 1.0 SCO Unix 3.2 TCP/IP/NFS source
# set -x
# Globals
#
LKPERM=/etc/perms/inst
PATH=/bin:/usr/bin:/etc:/etc/conf/bin
tmp=/tmp/tcp$$
pkg="TCPRT" # permlist package name
set="SCO TCP Runtime" # appears in prompts
ROOT=
CONF=${ROOT}/usr/sys/conf
DEVDIR=${ROOT}/dev
ETC=${ROOT}/etc
TCP_CONF=${ROOT}/usr/lib/tcprt
TCP_IF=${TCP_CONF}/if.conf
TCPPERM=${ETC}/perms/tcprt # permlist of this product
INET=${ROOT}/usr/sys/inet
# function definitions
#
# usage: safemv file1 file2
# move file1 to file2 without chance of interruption
safemv() {
trap "" 1 2 3 15
mv $1 $2
trap 1 2 3 15
}
# usage: safecopy file1 file2
# copies file1 to file2 without chance of interruption
safecopy() {
trap "" 1 2 3 15
cp $1 $2
trap 1 2 3 15
}
# Prompt for yes or no answer with message passed as argument -
# returns non-zero for no
getyn() {
while echo "\n$* (y/n/q) \c">&2
do read yn rest
case $yn in
[yY]) return 0 ;;
[nN]|[qQ]) return 1 ;;
*) echo "Please answer y,n or q" >&2 ;;
esac
done
}
# print a prompt
#
p() {
set -f
/bin/echo $*
set +f
return $?
}
# Remove temp files and exit with the status passed as argument
cleanup() {
trap '' 1 2 3 15
[ "$tmp" ] && rm -f $tmp*
exit $1
}
# Test to see if link kit is installed
chklinkkit() {
until fixperm -i -d LINK $LKPERM
do case $? in
4) echo "The Link Kit is not installed." >&2 ;;
5) echo "The Link Kit is only partially installed." >&2
echo "Attempting to install/deinstall the driver anyway." >&2
return 0
;;
*) echo "Error testing for Link Kit. Exiting."; cleanup 1 ;;
esac
# Not fully installed. Do so here
while echo "Do you wish to install it now? (y/n) \c"
do read ANSWER
case $ANSWER in
Y|y) custom -o -i LINK
break
;;
N|n) echo "Drivers cannot be installed without the Link Kit."
cleanup 1
;;
*) echo "Please answer 'y' or 'n'. \c"
;;
esac
done
done
}
chktcp() {
PWD=`pwd` ; cd /
fixperm -i -d ${pkg} ${TCPPERM} ; res=$?
if [ $res -lt 5 ]
then
idcheck -p tcp ; res=$?
if [ $res -lt 16 ]
then
echo "Drivers cannot be installed without the TCPRT package."
cleanup 1
fi
else
echo "Drivers cannot be installed without the TCPRT package."
cleanup 1
fi
cd $PWD
}
# Re-link new kernel
relink() {
cd /etc/conf/cf.d
if [ -z "$_NOPROMPT" ] ; then
echo "\nRe-linking the kernel ... \c" >&2
fi
./link_unix 2>&1 | tee -a kmakelog 2>&1 || {
echo "\nError: Kernel link failed.
Check /etc/conf/cf.d/kmakelog for details." >&2
cleanup 1
}
rm -f kmakelog
return 0
}
#
# Edit the sdevice file to remove the driver
edrmvdlk() {
ed -s $1 << TOAST > /dev/null
/^$1/
d
a
dlk0 N 4 5 1 2 300 31f d0000 d1fff
.
w
q
TOAST
}
# D-link driver banner message
dlk_prompt() {
/bin/cat - << EOF
D-Link Network adapter setup
There are four parameters which you will need to supply :
1. The Interrupt Vector Number
2. Base I/O address
3. Base memory address
4. PCMCIA Slot Number
If you wish to go back and reconfigure your board or read the
D-Link adapter documentation answer no to the next question.
EOF
}
addhex() {
echo "$1 $2" | nawk ' {
printf("%x", atoh($1) + atoh($2));
}
function atoh(number) {
i = 0
j = length(number)
result = 0
while ( i < j ) {
result = result + (hexval(substr(number,j - i,1)) * (16 ^ i))
i = i + 1
}
return result
}
function hexval(letter) {
if (letter == "a") return 10 + 0
if (letter == "b") return 11 + 0
if (letter == "c") return 12 + 0
if (letter == "d") return 13 + 0
if (letter == "e") return 14 + 0
if (letter == "f") return 15 + 0
return (letter + 0)
}'
}
# main()
cd /
tput clear
# check to see if the drivers can be installed
#
chklinkkit
#
# check to see if TCP/IP is installed
#
chktcp
# Add drivers via configure
#
while echo "Do you wish to install or delete the dlk driver (i/d/q) \c"
do read ANSWER
case $ANSWER in
I|i)
break
;;
D|d)
cd /etc/conf/pack.d
idinstall -d -e dlk0
cd /etc/conf/sdevice.d
edrmvdlk dlk0
cd /
grep -v dlk /etc/tcp > /tmp/tcp && cp /tmp/tcp /etc/tcp
grep -v dlk /etc/strcf > /tmp/strcf && cp /tmp/strcf /etc/strcf
rm -f /tmp/tcp /tmp/strcf
# Relink the kernel with the new driver information
if [ -z "$_NOPROMPT" ] ; then
if getyn "\nDo you wish to relink the kernel now?"
then
relink
else
echo "\nChanges will not take effect until the kernel is relinked." >&2
fi
else
relink
fi
cleanup 0
;;
Q|q)
cleanup 0
;;
*) echo "Please answer 'i', 'd' or 'q'."
;;
esac
done
echo " "
#
# Deal with the D-Link driver
#
dlk_prompt
getyn "Do you want to continue?"
if [ $? = "1" ]
then
p "You can rerun mkdev at a later time"
exit 0
fi
echo " "
vect=9
ioaddr=300
ioend=31f
maddr=d0000
mend=d3fff
slot=0
while p "Interrupt vector number [5]: \c "
do read vect
case "$vect" in
"")
vect=5;
break;
;;
2)
vect=9;
break;
;;
[0-9]*)
break;
;;
*)
p "Vector number must be decimal digits"
;;
esac
done
echo " "
while p "IO base address (in hexadecimal) [300] : \c"
do read ioaddr
case "$ioaddr" in
"")
ioaddr=300
break;
;;
[0-3][0-9ABCDEFabcdef]?)
case "$ioaddr" in
3f[!0])
p "Address must be 3 hexadecimal digits"
;;
*)
break;
;;
esac
;;
*) p "Address must be 3 hexadecimal digits"
;;
esac
done
echo " "
while p "Memory base address (in hexadecimal) [d0000]: \c"
do read maddr
case "$maddr" in
"")
maddr=d0000
break;
;;
[0-9,a-f,A-F]*)
break;
;;
*) p "Address must be hexadecimal digits"
;;
esac
done
echo " "
while p "PCMCIA slot number [0]: \c"
do read slot
case "$slot" in
"")
slot=0
break;
;;
[0-9]*)
break;
;;
*) p "Slot number must be decimal "
;;
esac
done
echo " "
mend=`addhex $maddr 3fff`
ioend=`addhex $ioaddr 1f`
cd /tmp
if [ ! -d dlk ] ; then
mkdir dlk
fi
cd dlk
# system
echo "dlk0 Y 4 5 1 $vect $ioaddr $ioend $maddr $mend" > ./System
# node
echo "clone dlk0 c dlk0" > ./Node
# master
echo "dlk0 I iScH dlk 0 0 1 4 -1" > ./Master
# space.c
echo "unsigned long DLKbase = 0x$maddr;" > ./Space.c
echo "unsigned long DLKport = 0x$ioaddr;" >> ./Space.c
echo "unsigned char DLKirq = $vect;" >> ./Space.c
echo "unsigned char DLKslot = 0x$slot;" >> ./Space.c
echo "int Protocol = 0;" >> ./Space.c
# Driver.o
cp /usr/lib/tcprt/dlk/de650.o ./Driver.o
if [ -d /etc/conf/pack.d/dlk0 ] ; then
idinstall -u -m -s -n -o -p -e dlk0
else
idinstall -a -e dlk0
/etc/conf/bin/idmknod dlk0
fi
cd .. ; rm -rf dlk
echo ""
cd /
# Relink the kernel with the new driver information
if [ -z "$_NOPROMPT" ] ; then
if getyn "\nDo you wish to relink the kernel now?"
then
relink
else
echo "\n$set will not work until the kernel is relinked." >&2
cleanup 0
fi
else
relink
fi
# install if requested
#
echo ""
echo "To complete installation run mkdev tcp" >&2
echo "and reboot the system via init 6\n" >&2