#       Copyright (c) 1987 AT&T
#	  All Rights Reserved

#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.

#ident  "@(#)ldsysdump.sh	1.2"

# load a system memory image dump from tape or floppy to a file

# shell variables used:
#
#       DEV     "f" = floppy; "t" = tape
#
#       IF      input device file used by dd
#       BS      block size used by dd, in 512 byte units
#       COUNT   number of blocks per disk/tape
#
#       NB      number of BS size blocks on tape/disk
#       N       number of BS size blocks of memory to copy


if [ $# -ne 1 ]
then
	echo 'usage: /etc/ldsysdump file'
	exit
fi

while :
do
	echo 'Is the dump on:'
	echo '  d - double density diskettes (dev/rdsk/f0d9dt)'
	echo '  q - quad density diskettes (dev/rdsk/f0q15dt)'
	echo '  t - tape (/dev/rmt0)'
	echo '  n - no, QUIT'
	echo '> \c'
	read ans
	case $ans in
	  d )   IF=/dev/rdsk/f0d9dt  BS=18 NB=40     DEV=f ; break ;;
	  q )   IF=/dev/rdsk/f0q15dt BS=30 NB=80     DEV=f ; break ;;
	  t )   IF=/dev/rmt0         BS=32 NB=10000  DEV=t ; break ;;
	  n )   exit ;;
	esac
	echo '???'
done

while :
do
	echo 'How many megabytes of memory image do you want to load?'
	echo 'Enter decimal integer or "q" to quit. > \c'
	read ans
	case $ans in
	  q )   exit ;;
	esac
	N=`expr \( $ans \* 2048 + $BS - 1 \) / $BS`
	case $? in
	  0 )   break;;
	esac
	echo '???'
done

SKIP=0
COUNT=$NB

{   while [ $N -gt 0 ]
    do
	if [ $COUNT -gt $N ]
	then
		COUNT=$N
	fi
	echo 'Insert \c' >&2
	case $DEV in
	  f )   echo 'diskette \c' >&2 ;;
	  t )   echo 'tape cartridge \c' >&2 ;;
	esac
	echo 'and press return to load it, or enter q to quit. > \c' >&2
	read ans
	case $ans in
	  q )   exit ;;
	esac
	echo 'Wait.' >&2
	echo dd if=$IF bs=${BS}b count=$COUNT >&2
	dd if=$IF bs=${BS}b count=$COUNT
	N=`expr $N - $COUNT`
	SKIP=`expr $SKIP + $COUNT`
    done
} > $1

echo "System dump copied into $1.  Use crash(1M) to analyze the dump."
