#
echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '
echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '
echo ' '; echo ' '; echo ' '; echo ' '
echo '         Everex Streaming Tape XENIX Driver  (Version 1.02)'
echo '        Installation Script for Non-Preconfigured Driver et'
echo '              (C) Copyright Everex Systems, Inc. 1987'
#
set cwd  = `pwd`
set dir  = "/usr/sys/tape"
set dev  = "/ser"
set max  = "30"
set PORT = 300
set IRQ  = 3
set DMA  = 1
set auto = "n"
#
if ($#argv != 3) goto step1
set PORT = $argv[1]
set IRQ  = $argv[2]
set DMA  = $argv[3]
set auto = "y" 
echo ' '
echo "STEP  1: PORT=$PORT   IRQ=$IRQ   DMA=$DMA"
echo ' '
echo 'STEP  2: Auto install mode'
goto step3
#
step1:
echo ' '
echo "STEP  1: Get tape controller settings:  PORT=$PORT   IRQ=$IRQ   DMA=$DMA"

loop1:
./getkey 'Enter y to continue, r to re-enter, x to exit: '; set key=`./getkey`
if ($key == "s") goto step2
if ($key == "y") goto step2
if ($key == "x") exit
if ($key != "r") goto loop1

echo ' '
./getkey 'Enter port address (in hexadecimal) -----: '; set PORT = `./getkey`
./getkey 'Enter interrupt request line (IRQ) ------: '; set IRQ  = `./getkey`
./getkey 'Enter DMA channel number ----------------: '; set DMA  = `./getkey`
goto step1
#
step2:
echo ' '
echo 'STEP  2: Would you like to stop before every installation step?'

loop2:
./getkey 'Enter y for step-by-step, a for auto, x to exit: '
set key = `./getkey`
if ($key == "s") goto step3
if ($key == "y") goto step3
if ($key == "x") exit
if ($key != "a") goto loop2

set auto = "y"
#
step3:
echo ' '
echo 'STEP  3: Copy tape software from diskette drive A: doscp a:* .'
if ($auto == "y") goto exec3

loop3:
./getkey 'Enter y to continue, x to exit: '; set key = `./getkey`
if ($key == "s") goto step4
if ($key == "x") exit
if ($key != "y") goto loop3

exec3:
doscp -r a:tape		.
doscp -r a:tape.com	.
doscp -r a:et.o		.
doscp    a:eterase      .
doscp    a:etrewind     .
doscp    a:etretens     .
doscp    a:etbackup	.
chmod +x tape eterase etrewind etretens etbackup
#
step4:
echo ' '
echo "STEP  4: Copy files from ../conf to $cwd"': cp ../conf/* .'
if ($auto == "y") goto exec4

loop4:
./getkey 'Enter y to continue, x to exit: '; set key = `./getkey`
if ($key == "s") goto step5
if ($key == "x") exit
if ($key != "y") goto loop4

exec4:
cp ../conf/*   .
cp ../conf/*.c .
cp ../conf/*.o .
#
step5:
echo ' '
echo 'STEP  5: Record tape controller settings in /etc/rc.'
if ($auto == "y") goto exec5

loop5:
./getkey 'Enter y to continue, x to exit: '; set key = `./getkey`
if ($key == "s") goto step6
if ($key == "x") exit
if ($key != "y") goto loop5

exec5:
if (! -e /etc/rc.old) cp /etc/rc /etc/rc.old
if (-e rc.ed) rm rc.ed
set key = "$cwd/tape /dev/et0 -l $cwd/tape.com -c 1 $PORT $IRQ $DMA"
echo 'g/tape./d'	 >rc.ed
echo '$'		>>rc.ed
echo 'a'		>>rc.ed
echo $key		>>rc.ed
echo '.'		>>rc.ed
echo 'w'		>>rc.ed
echo 'q'		>>rc.ed
ed /etc/rc	 	<rc.ed >/dev/null
#
step6:
echo ' '
echo "STEP  6: Get next major device number from $cwd/master"
if ($auto == "y") goto exec6

loop6:
./getkey 'Enter y to continue, x to exit: '; set key = `./getkey`
if ($key == "s") goto step7
if ($key == "x") exit
if ($key != "y") goto loop6

exec6:
set lst = `sed -n -e '/  [0-9][0-9][0-9][0-9] [0-9]/p' master`
set num = $#lst; set max = 0; set cnt = 8; set ptr = 8
while ($ptr < $num)
   set dev = $lst[$ptr]
   if ($dev > $max) then
      set max = $dev 
      set cnt = $ptr
   endif
   @ ptr = $ptr + 14
end
@   cnt -= 7
set dev = $lst[$cnt]
@   max++
#
step7:
echo ' '
echo "STEP  7: Create device files: /dev/et* (major=$max)"
if ($auto == "y") goto exec7

loop7:
./getkey 'Enter y to continue, x to exit: '; set key = `./getkey`
if ($key == "s") goto step8
if ($key == "x") exit
if ($key != "y") goto loop7

exec7:
if (-e /dev/et0)  rm /dev/et0
if (-e /dev/et11) rm /dev/et11
mknod /dev/et0  c $max 0  ; chmod 600 /dev/et0
mknod /dev/et11 c $max 11 ; chmod 666 /dev/et11
#
step8:
echo ' '
echo "STEP  8: Add et to $cwd/master"
if ($auto == "y") goto exec8

loop8:
./getkey 'Enter y to continue, x to exit: '; set key = `./getkey`
if ($key == "s") goto step9
if ($key == "x") exit
if ($key != "y") goto loop8

exec8:
if (-e master.ed) rm master.ed
set _c = " 0  0137 104     et  0   0  $max    1   0    0     0     0   0" 
echo "/$dev"		 >master.ed
echo "a"		>>master.ed
echo "et	$_c"	>>master.ed
echo "."		>>master.ed
echo "w"		>>master.ed
echo "q"		>>master.ed
ed master		 <master.ed >/dev/null
#
step9:
echo ' '
echo "STEP  9: Add et to $cwd/xenixconf"
if ($auto == "y") goto exec9

loop9:
./getkey 'Enter y to continue, x to exit: '; set key = `./getkey`
if ($key == "s") goto step10
if ($key == "x") exit
if ($key != "y") goto loop9

exec9:
if (-e xenixconf.ed) rm xenixconf.ed
echo "/ser"		 >xenixconf.ed
echo "a"		>>xenixconf.ed
echo "et	1"	>>xenixconf.ed
echo "."		>>xenixconf.ed
echo "w"		>>xenixconf.ed
echo "q"		>>xenixconf.ed
ed xenixconf		 <xenixconf.ed >/dev/null
#
step10:
echo ' '
echo "STEP 10: Add et.o to $cwd/link_xenix"
if ($auto == "y") goto exec10

loop10:
./getkey 'Enter y to continue, x to exit: '; set key = `./getkey`
if ($key == "s") goto step11
if ($key == "x") exit
if ($key != "y") goto loop10

exec10:
if (-e link_xenix.ed) rm link_xenix.ed
echo '/ld'		 >link_xenix.ed
echo 'a'		>>link_xenix.ed
echo '	et.o '\\	>>link_xenix.ed
echo '.'		>>link_xenix.ed
echo 'w'		>>link_xenix.ed
echo 'q'		>>link_xenix.ed
ed link_xenix		 <link_xenix.ed >/dev/null
#
step11:
echo ' '
echo "STEP 11: Add et.o to $cwd/makefile"
if ($auto == "y") goto exec11

loop11:
./getkey 'Enter y to continue, x to exit: '; set key = `./getkey`
if ($key == "s") goto step12
if ($key == "x") exit
if ($key != "y") goto loop11

exec11:
if (-e makefile.ed) rm makefile.ed
echo "/CONF"		 >makefile.ed
echo 's/$/ et.o/'	>>makefile.ed
echo "w"		>>makefile.ed
echo "q"		>>makefile.ed
ed makefile		 <makefile.ed >/dev/null
#
step12:
echo ' '
echo "STEP 12: Ready to re-make kernel: $cwd/xenix"
if ($auto == "y") goto exec12

loop12:
./getkey 'Enter y to continue, x to exit: '; set key = `./getkey`
if ($key == "s") goto step13
if ($key == "x") exit
if ($key != "y") goto loop12

exec12:
make
#
step13:
echo ' '
echo "STEP 13: Reboot kernel from $cwd/xenix"
echo ' '
echo '      -- The following commands will be executed to reboot the system:'
echo '         sync; haltsys'
echo ' '
echo '      -- Hit a key to reboot after you see the following message:'
echo '         ** Hit Any Key to Reboot **'
echo ' '
echo "      -- Enter $cwd/xenix after you see the Boot prompt:"
echo '         Boot'
echo '         : '"$cwd/xenix"
echo ' '
echo '      -- Run the "etbackup" script after log into the new system:'
echo "         $cwd/etbackup"
echo ' '
echo '      -- Replace the kernel permanently if everything is OK:'
echo '         mv /xenix /xenix.old'
echo "         mv $cwd/xenix /xenix"
echo ' '
echo 'Now you can remove the tape software diskette from drive A:'

loop13:
./getkey 'Enter y to REBOOT, x to exit: '; set key = `./getkey`
if ($key == "s") exit
if ($key == "x") exit
if ($key != "y") goto loop13

exec13:
sync; haltsys
