File: dump_disk

package info (click to toggle)
dump 0.4b41-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,416 kB
  • ctags: 1,987
  • sloc: ansic: 17,610; sh: 3,185; makefile: 210; sed: 5
file content (100 lines) | stat: -rwxr-xr-x 2,780 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh

# This script dumps the specified Filesystem via dump on a CD/DVD
# DISK_CAPACITY defines the capacity in MB per disk.
# The script's own name $0 is passed via the -F option of dump
# When using cdrecord/dvdrecord and at least for my DVD-Recorder (a PHILIPS
# DVR-A03) it is necessary to define the tracksize for the next track before
# the DVD is written. This is done via the -tsize option of cdrecord. Since
# tsize takes its arguments in Bytes, the shell cannot compute the value
# correctly anymore (value too high), so I use bc.

# Set this to 4300 for DVD and 650 or 700 for CD
#DISK_CAPACITY=10	# testing
#DISK_CAPACITY=650
DISK_CAPACITY=4300

BSIZE="$(echo "$DISK_CAPACITY*1024" | bc -l )"
TSIZE="$(echo "$DISK_CAPACITY*1024*1024" | bc -l )"

# This is used for testing
#RECORD_BIN="dd of=/dev/null bs=1k if="

# This is for writing to CD with cdrtools, this uses track-at-once mode
# in case cdrtools does not support disk-at-once with your burner
#RECORD_BIN="/usr/bin/cdrecord dev=0,0,0 fs=64M speed=2 -eject -tao -pad -tsize=$TSIZE -data "

# This is for writing to DVD with cdrtools with DVD support, this has to
# use disk-at-once mode.
#RECORD_BIN="/usr/bin/cdrecord dev=0,0,0 fs=64M speed=2 -eject -dao -pad -tsize=$TSIZE -data "

# This is for writing to DVD with growisofs
RECORD_BIN="/usr/bin/growisofs -Z /dev/dvd="

FIFO="/tmp/dump.$$.fifo"
DUMP="/sbin/dump"

cleanup() {
	rm -f $FIFO
}

error_exit() {
	retcode=$?
	echo >&2 "Error $retcode: exiting"
	exit $retcode
}

trap error_exit ERR

write_output() {
	# supplied info from "dump -F":
	# $1 = filename
	# $2 = sequence number
	echo "Please insert disk No. $(($2+1))"
	ANSWER=""
	while [ "$ANSWER" != "y" ] ; do
		echo -n "Is the disk ready? (y/n) "
		read  </dev/tty ANSWER
		if [ "$ANSWER" == "y" ] ; then
			(${RECORD_BIN}${1}) &
			return 0
		elif [ "$ANSWER" == "n" ] ; then
			EXIT=""
			echo -n "Do you really want to exit? (y/n) "
			read </dev/tty EXIT
			if [ "$EXIT" == "y" ] ; then
				return 1
			fi
		fi
	done
}

if [ "$#" = "0" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
	echo >&2 "Usage: $0 <dump options>"
	echo >&2 "See 'man dump' for dump options"
	echo >&2 "the dump options -F -f -B are not required and are overridden"
	exit 1
fi

set -m	# We need proper job control

if [ "$#" = "2" ] && [ -p "$1" ]; then
	write_output "$@" || (kill $$ >/dev/null 2>&1; exit 1)
	exit 0
else
	mkfifo $FIFO
	trap cleanup EXIT
	if write_output "$FIFO" "0"; then
		if $DUMP "$@" -F "$0" -f "$FIFO" -B$BSIZE; then
			echo "Waiting for background writing process to complete"
			wait %			# Wait for the background writing process
		else
			kill % >/dev/null 2>&1	# or kill it
			exit 1
		fi
		exit 0
	else
		kill % >/dev/null 2>&1	# Kill the background writing process
		exit 1
	fi
fi