Updated buggy example.
[dump.git] / examples / dump_on_cd_3 / dump_disk
1 #!/bin/sh
2
3 # This script dumps the specified Filesystem via dump on a CD/DVD
4 # DISK_CAPACITY defines the capacity in MB per disk.
5 # The script's own name $0 is passed via the -F option of dump
6 # When using cdrecord/dvdrecord and at least for my DVD-Recorder (a PHILIPS
7 # DVR-A03) it is necessary to define the tracksize for the next track before
8 # the DVD is written. This is done via the -tsize option of cdrecord. Since
9 # tsize takes its arguments in Bytes, the shell cannot compute the value
10 # correctly anymore (value too high), so I use bc.
11
12 # Set this to 4300 for DVD and 650 or 700 for CD
13 #DISK_CAPACITY=10 # testing
14 #DISK_CAPACITY=650
15 DISK_CAPACITY=4300
16
17 BSIZE="$(echo "$DISK_CAPACITY*1024" | bc -l )"
18 TSIZE="$(echo "$DISK_CAPACITY*1024*1024" | bc -l )"
19
20 # This is used for testing
21 #RECORD_BIN="dd of=/dev/null bs=1k if="
22
23 # This is for writing to CD with cdrtools, this uses track-at-once mode
24 # in case cdrtools does not support disk-at-once with your burner
25 #RECORD_BIN="/usr/bin/cdrecord dev=0,0,0 fs=64M speed=2 -eject -tao -pad -tsize=$TSIZE -data "
26
27 # This is for writing to DVD with cdrtools with DVD support, this has to
28 # use disk-at-once mode.
29 #RECORD_BIN="/usr/bin/cdrecord dev=0,0,0 fs=64M speed=2 -eject -dao -pad -tsize=$TSIZE -data "
30
31 # This is for writing to DVD with growisofs
32 RECORD_BIN="/usr/bin/growisofs -Z /dev/dvd="
33
34 FIFO="/tmp/dump.$$.fifo"
35 DUMP="/sbin/dump"
36
37 cleanup() {
38 rm -f $FIFO
39 }
40
41 error_exit() {
42 retcode=$?
43 echo >&2 "Error $retcode: exiting"
44 exit $retcode
45 }
46
47 trap error_exit ERR
48
49 write_output() {
50 # supplied info from "dump -F":
51 # $1 = filename
52 # $2 = sequence number
53 echo "Please insert disk No. $(($2+1))"
54 ANSWER=""
55 while [ "$ANSWER" != "y" ] ; do
56 echo -n "Is the disk ready? (y/n) "
57 read </dev/tty ANSWER
58 if [ "$ANSWER" == "y" ] ; then
59 (${RECORD_BIN}${1}) &
60 return 0
61 elif [ "$ANSWER" == "n" ] ; then
62 EXIT=""
63 echo -n "Do you really want to exit? (y/n) "
64 read </dev/tty EXIT
65 if [ "$EXIT" == "y" ] ; then
66 return 1
67 fi
68 fi
69 done
70 }
71
72 if [ "$#" = "0" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
73 echo >&2 "Usage: $0 <dump options>"
74 echo >&2 "See 'man dump' for dump options"
75 echo >&2 "the dump options -F -f -B are not required and are overridden"
76 exit 1
77 fi
78
79 set -m # We need proper job control
80
81 if [ "$#" = "2" ] && [ -p "$1" ]; then
82 write_output "$@" || (kill $$ >/dev/null 2>&1; exit 1)
83 exit 0
84 else
85 mkfifo $FIFO
86 trap cleanup EXIT
87 if write_output "$FIFO" "0"; then
88 if $DUMP "$@" -F "$0" -f "$FIFO" -B$BSIZE; then
89 echo "Waiting for background writing process to complete"
90 wait % # Wait for the background writing process
91 else
92 kill % >/dev/null 2>&1 # or kill it
93 exit 1
94 fi
95 exit 0
96 else
97 kill % >/dev/null 2>&1 # Kill the background writing process
98 exit 1
99 fi
100 fi