Debian Codegraph @

examples/dump_on_cd_3/dump_disk

raw symbols SCIP
1 #!/bin/bash
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 # exit on errors
42 set -e
43
44 write_output() {
45 # supplied info from "dump -F":
46 # $1 = filename
47 # $2 = sequence number
48 echo "Please insert disk No. $(($2+1))"
49 ANSWER=""
50 while [ "$ANSWER" != "y" ] ; do
51 echo -n "Is the disk ready? (y/n) "
52 read </dev/tty ANSWER
53 if [ "$ANSWER" = "y" ] ; then
54 (${RECORD_BIN}${1}) &
55 return 0
56 elif [ "$ANSWER" = "n" ] ; then
57 EXIT=""
58 echo -n "Do you really want to exit? (y/n) "
59 read </dev/tty EXIT
60 if [ "$EXIT" = "y" ] ; then
61 return 1
62 fi
63 fi
64 done
65 }
66
67 if [ "$#" = "0" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
68 echo >&2 "Usage: $0 <dump options>"
69 echo >&2 "See 'man dump' for dump options"
70 echo >&2 "the dump options -F -f -B are not required and are overridden"
71 exit 1
72 fi
73
74 set -m # We need proper job control
75
76 if [ "$#" = "2" ] && [ -p "$1" ]; then
77 write_output "$@" || (kill $$ >/dev/null 2>&1; exit 1)
78 exit 0
79 else
80 mkfifo $FIFO
81 trap cleanup 0
82 if write_output "$FIFO" "0"; then
83 if $DUMP "$@" -F "$0" -f "$FIFO" -B$BSIZE; then
84 echo "Waiting for background writing process to complete"
85 wait % # Wait for the background writing process
86 else
87 kill % >/dev/null 2>&1 # or kill it
88 exit 1
89 fi
90 exit 0
91 else
92 kill % >/dev/null 2>&1 # Kill the background writing process
93 exit 1
94 fi
95 fi