#!/bin/ksh
#            tape2sm.scr

# Copy achived tape file to hard disk

    PATH=/bin:/usr/bin:/etc:/usr/ucb:$HOME/bin:/usr/bin/X11:.:/usr/local/bin:/usr/abin
    export PATH

 #  set -nv
    HOST=`hostname`
       
#   Set block size to an even multiple of archive file record length
#   RAMARCOLD = 38x38+50=1494 (*10)=14940
#   CBRAMARC = 42x46+50=1982 (*10)=19820 
#   NERAMARC = 78x74+50=1982 (*10)=58220 
    echo; echo "Enter RAMS Archive (cb or ne )"
    read atyp
    if [ $atyp = cb ];then 
      BLOCK=19820
    else
      BLOCK=58220
    fi
    mdl=RAMS

#-->choose tape drive
#   read cdev?"(1) 4 mm or (2) 8 mm?"
    if [ $HOST = 'gus' ];then
       dev=rmt0
    else
       dev=rmt1
    fi

#-->files to skip
    read sk?"Enter number of files to skip: "
 
       FILE=${dir}/${mdl}
       echo
       echo "     ...............  ${FILE}  ................................."
          
#----->load tape
       echo; echo "Insert tape; press 'c' to continue"
       read cont
       if [ $cont = "c" ]; then
          echo
       else
          echo Termination: $0 $1
          exit
       fi

#----->rewind 
       echo; echo "Rewind the tape first? (y/n)"
       read rwnd
       if [ $rwnd = "y" ]; then
          tctl -f /dev/$dev rewind
       fi

#-------->skip files 
       if [ $sk -gt 0 ]; then
           echo Skipping $sk files
           tctl -f /dev/$dev.1 fsf $sk
       fi

#-------->copy 
       echo "Transferring data:  /dev/$dev.1 (bs=$BLOCK)"
       if dd  if=/dev/$dev.1 of=SMFILE bs=$BLOCK conv=sync; then
          echo "Successful copy: $FILE "
       else
          echo "Error in copying $FILE"
          exit
       fi

#-------->rewind 
       echo; echo "Rewind the tape now? (y/n)"
       read rwnd
       if [ $rwnd = "y" ]; then
          tctl -f /dev/$dev rewind
       fi

#-------->inventory
       echo; echo "Inventory the tape now? (y/n)"
       read invn
       if [ $invn = "y" ]; then
          echo "$cdev\n" | smtapeinv.scr
          qprt -Bnn -v8 -p12 filedump
       fi

