116802Spc#!/bin/sh
2*32049Spc#	dumpdev.sh	1.5	08/11/87
316802Spc#	shell script to dump a single device
416802Spc#	the script is called with a single
516802Spc#	parameter - which is the device to be dumped
616802Spc#
719227Spc#	A second parameter (if set) sets the debug switch which will
819227Spc#	simply print the parameters to dump and not alter any state
916804SpcPATH=:/etc:/bin:/usr/bin:
1016804Spc#
1116804Spcdumpdata=/etc/dumpdata
1216802Spcdumpcycle=${dumpdata}/dumpcycle
1316804Spcdump=/etc/dump
1416802Spclabelchk="t"
1516802Spc#
1616802Spcdev=$1
1716802Spcif [ "$1" = "" ]
1816802Spcthen
19*32049Spc	echo	'Usage: dumpdev device-name'
2016802Spc	exit 1
2116802Spcfi
2219227Spcchkflg=no
2319227Spcif [ "$2" != "" ]
2419227Spcthen
2519227Spc	chkflg=yes
2619227Spcfi
2716802Spc#	device can be /dev/<name>
2816802Spc#	so we'll look for that and split it off
2916802Spcdev=`echo $dev|sed -e 's/\/dev\///'`
3016802Spc#	Now lets see if the device exists in the dumpcycle file
3116802Spcgstr=`grep "^$dev" $dumpcycle` 2> /dev/null
3216802Spcif [ "$gstr" = "" ]
3316802Spcthen
3416802Spc#	it might be a raw device
3516802Spc	altdev=`expr $dev : 'r\(.*\)'`
3616802Spc	if [ "$altdev" = "" ]
3716802Spc	then
3816802Spc		echo Sorry, cannot find device $1 in $dumpcycle
3916802Spc		exit 1
4016802Spc	fi
4116802Spc	dev=$altdev
4216802Spc	gstr=`grep "^$dev" $dumpcycle` 2> /dev/null
4316802Spc	if [ "$gstr" = "" ]
4416802Spc	then
4516802Spc		echo Sorry, cannot find device $1 in $dumpcycle
4616802Spc		exit 1
4716802Spc	fi
4816802Spcfi
4916802Spc#	Now we look for existing dump state
5016802Spc#	stored in a file called devicename.state on /etc/dumpdata
5116802Spcstatefile=${dumpdata}/${dev}.state
5216802Spcif [ ! -s $statefile ]
5316802Spcthen
5416802Spc#	we ain't got one
5516802Spc	STATE="0"
5616802Spcelse
5716802Spc	STATE=`cat $statefile`
5816802Spcfi
5916802Spc#
6016802Spc#	Get the next state from the cycle file
6116802Spc#
6216802Spcawkprog="/^$dev/ { if ($STATE == \$2) print \$3	}"
6316802SpcNEXTSTATE=`awk "$awkprog" < $dumpcycle`
6416802Spcif [ "$NEXTSTATE" = "" ]
6516802Spcthen
6616802Spc	echo "Dump state problem"
6716802Spc	echo "State file $statefile contents giving current state = $STATE"
6816802Spc	echo "cannot be found in $dumpcycle"
6916802Spc	exit 1
7016802Spcfi
7116802Spc#
7216802Spc#	Now we need the dump information from the cycle file
7316802Spc#
74*32049Spcawkprog="/^$dev/ { if ($NEXTSTATE == \$2) print \$4,\$5,\$6	}"
7516802Spcdecodethis=`awk "$awkprog" < $dumpcycle`
7616802Spcif [ "$decodethis" = "" ]
7716802Spcthen
7816802Spc	echo "Dump state problem"
7916802Spc	echo "Cannot find state $NEXTSTATE in $dumpcycle"
8016802Spc	exit 1
8116802Spcfi
8216802Spc#
8316802Spc#	This is really nasty - but
8416802Spc#	now finally set the dump level and the tape range
85*32049Spcecho $decodethis | (
86*32049Spc	read LEVEL TAPESTEM TAPECYCLE
87*32049Spc	if [ "$chkflg" = yes ]
88*32049Spc	then
89*32049Spc		echo "DUMP of /dev/$dev at level ${LEVEL} to tapes $TAPESTEM $TAPECYCLE"
90*32049Spc		exit 1
91*32049Spc	fi
92*32049Spc	if [ "$TAPECYCLE" = "" ]
93*32049Spc	then
94*32049Spc		$dump oul${labelchk}${LEVEL} $TAPESTEM /dev/$dev
95*32049Spc		retval=$?
96*32049Spc	else
97*32049Spc		$dump oulm${labelchk}${LEVEL} $TAPESTEM $TAPECYCLE /dev/$dev
98*32049Spc		retval=$?
99*32049Spc	fi
10016802Spc#
101*32049Spc#	dump returns 0 on a successful dump
10216802Spc#
103*32049Spc	if [ $retval = 0 ]
104*32049Spc	then
105*32049Spc		echo $NEXTSTATE > $statefile
106*32049Spc	fi
107*32049Spc)
10816802Spcexit 0
109