| 1 | #!/bin/bashscip-shell filesystem . . `/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="$(echoscip-shell system . . echo. "$DISK_CAPACITY*1024" | bc -l )" |
| 18 | TSIZE="$(echoscip-shell system . . 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=scip-shell filesystem . . `/usr/bin/growisofs -Z /dev/dvd=`." |
| 33 | |
| 34 | FIFO="/tmp/dump.$$.fifo" |
| 35 | DUMP="/sbin/dumpscip-shell filesystem . . `/sbin/dump`." |
| 36 | |
| 37 | cleanupscip-shell shell shell-project 0.0.0 cleanup().() { |
| 38 | rmscip-shell system . . rm. -f $FIFO |
| 39 | } |
| 40 | |
| 41 | # exit on errors |
| 42 | set -e |
| 43 | |
| 44 | write_outputscip-shell shell shell-project 0.0.0 write_output().() { |
| 45 | # supplied info from "dump -F": |
| 46 | # $1 = filename |
| 47 | # $2 = sequence number |
| 48 | echoscip-shell system . . echo. "Please insert disk No. $(($2+1))" |
| 49 | ANSWER="" |
| 50 | while [scip-shell system . . `[`. "$ANSWER" != "y" ] ; do |
| 51 | echoscip-shell system . . echo. -n "Is the disk ready? (y/n) " |
| 52 | read </dev/ttyscip-shell filesystem . . `/dev/tty`. ANSWER |
| 53 | if [scip-shell system . . `[`. "$ANSWER" = "y" ] ; then |
| 54 | (${RECORD_BIN}${1}) & |
| 55 | return 0 |
| 56 | elif [scip-shell system . . `[`. "$ANSWER" = "n" ] ; then |
| 57 | EXIT="" |
| 58 | echoscip-shell system . . echo. -n "Do you really want to exit? (y/n) " |
| 59 | read </dev/ttyscip-shell filesystem . . `/dev/tty`. EXIT |
| 60 | if [scip-shell system . . `[`. "$EXIT" = "y" ] ; then |
| 61 | return 1 |
| 62 | fi |
| 63 | fi |
| 64 | done |
| 65 | } |
| 66 | |
| 67 | if [scip-shell system . . `[`. "$#" = "0" ] || [scip-shell system . . `[`. "$1" = "-h" ] || [scip-shell system . . `[`. "$1" = "--help" ]; then |
| 68 | echoscip-shell system . . echo. >&2 "Usage: $0 <dump options>" |
| 69 | echoscip-shell system . . echo. >&2 "See 'man dump' for dump options" |
| 70 | echoscip-shell system . . 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 [scip-shell system . . `[`. "$#" = "2" ] && [scip-shell system . . `[`. -p "$1" ]; then |
| 77 | write_outputscip-shell shell shell-project 0.0.0 write_output(). "$@" || (killscip-shell system . . kill. $$ >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1; exit 1) |
| 78 | exit 0 |
| 79 | else |
| 80 | mkfifoscip-shell system . . mkfifo. $FIFO |
| 81 | trap cleanup 0 |
| 82 | if write_outputscip-shell shell shell-project 0.0.0 write_output(). "$FIFO" "0"; then |
| 83 | if $DUMP "$@" -F "$0" -f "$FIFO" -B$BSIZE; then |
| 84 | echoscip-shell system . . echo. "Waiting for background writing process to complete" |
| 85 | wait % # Wait for the background writing process |
| 86 | else |
| 87 | killscip-shell system . . kill. % >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 # or kill it |
| 88 | exit 1 |
| 89 | fi |
| 90 | exit 0 |
| 91 | else |
| 92 | killscip-shell system . . kill. % >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 # Kill the background writing process |
| 93 | exit 1 |
| 94 | fi |
| 95 | fi |