4 dev
=${DVDRIP_DEVICE-/dev/dvd}
5 tmp
=${DVDRIP_TMPDIR-${HOME?}/tmp
/dvdrip
}
6 archive
=${DVDRIP_ARCHIVE-jem.distorted.org.uk:/mnt/dvd/archive}
7 : ${DVD_SECTOR_COPY=dvd-sector-copy}
9 : ${DVDRIP_UPLOAD=dvdrip-upload}
10 backup
=nil ding
=nil eject
=nil force
=nil retry
=nil verbose
=nil bogus
=nil
14 usage: $prog [-defrv] [-D DEV] [-a ARCH] [-t TMP] TITLE
17 while getopts "hB:D:a:defrt:v" opt
; do
20 B
) params
=${params+$params,}$OPTARG ;;
32 shift $
(( $OPTIND - 1 ))
33 case $# in 1) title
=$1 ;; *) bogus
=t
;; esac
34 case $bogus in t
) usage
>&2; exit 2 ;; esac
35 case $verbose in t
) set -x
;; esac
37 *:*) archhost
=${archive%%:*} archpath
=${archive#*:} ;;
38 *) unset archhost
; archpath
=$archive ;;
43 echo "$(tput bold; tput setaf $colour)$message$(tput sgr0; tput op)"
45 fail
() { notify
1 "!!! $*"; exit 2; }
46 warn
() { notify
5 "??? $*"; }
47 info
() { notify
6 "--- $*"; }
50 set +e
; nice
"$@"; rc
=$?
; set -e
52 run
() { run_setrc
"$@"; case $rc in 0) ;; *) fail
"$1: exit $rc" ;; esac; }
60 qq
="${qq:+$qq }'${a//\'/"'\\''"}'" #" # emacs is confused
62 "$op" ssh "$archhost" "$qq"
69 archrun
() { archdo run
"$@"; }
73 archdo run_setrc
test -f
"$archpath/$title.iso"
75 0,nil
) fail
"output file already exists" ;;
76 0,t
) warn
"output file already exists; will overwrite" ;;
81 discid
=$
("$DVD_ID" -I
"$dev")
82 if [ -f
"$tmp/$tag/discid" ]; then
83 read oldid
<"$tmp/$tag/discid"
85 t
,"$discid" | nil
,"$discid")
88 fail
"discid mismatch: expected \`$oldid' but drive has \`$discid'"
91 warn
"discid mismatch: expected \`$oldid' but drive has \`$discid'; continuing anway"
95 info
"copying \`$discid'"
96 echo "$discid" >"$tmp/$tag/discid.new"
97 mv "$tmp/$tag/discid.new" "$tmp/$tag/discid"
99 if [ -b
"$dev" ]; then msz
=$
(blockdev
--getsize64
"$dev")
102 echo "$dev" >"$tmp/$tag/device.new"
103 mv "$tmp/$tag/device.new" "$tmp/$tag/device"
105 accumulate_badblocks
() {
106 if [ -f
"$tmp/$tag/badblocks.new" ]; then
107 if [ ! -f
"$tmp/$tag/badblocks" ]; then
108 { echo "## bad-blocks region map"; echo; } >"$tmp/$tag/badblocks"
110 sed -n
"/^[^#]/p" "$tmp/$tag/badblocks.new" >>"$tmp/$tag/badblocks"
111 rm "$tmp/$tag/badblocks.new"
117 for i
in "$tmp/$tag/dest.new" "$tmp/$tag/dest" "$tmp/$tag/dest.seen"; do
118 if [ -f
"$tmp/$tag/dest.new" ]; then any
=t
; fi
121 nil
) printf "%s\n" "$title.iso" >"$tmp/$tag/dest.new" ;;
124 t
) touch "$tmp/$tag/eject" ;;
125 nil
) rm -f
"$tmp/$tag/eject" ;;
128 t
) touch "$tmp/$tag/ding" ;;
129 nil
) rm -f
"$tmp/$tag/ding" ;;
135 if [ -f
"$tmp/$tag/badblocks.retry" ]; then
137 elif [ -f
"$tmp/$tag/badblocks" ]; then
138 run
mv "$tmp/$tag/badblocks" "$tmp/$tag/badblocks.retry"
140 fail
"no blocks to retry"
142 set -- "$@" -R
"$tmp/$tag/badblocks.retry"
143 if [ -f
"$tmp/$tag/iso" ]; then
144 mv "$tmp/$tag/iso" "$tmp/$tag/iso.new"
148 if [ ! -f
"$tmp/$tag/iso" ]; then
149 run
"$DVD_SECTOR_COPY" -cs
${params+"-B$params"} \
150 -b
"$tmp/$tag/badblocks.new" "$@" "$dev" "$tmp/$tag/iso.new"
151 run
mv "$tmp/$tag/iso.new" "$tmp/$tag/iso"
153 rm -f
"$tmp/$tag/device"
154 case $retry in t
) rm -f
"$tmp/$tag/badblocks.retry" ;; esac
155 if [ -f
"$tmp/$tag/badblocks" ]; then
156 fail
"bad sectors found: check \`$tmp/$tag/iso', run again if ok"
161 newmsz
=$
(blockdev
--getsize64
"$dev")
164 *) fail
"medium size changed ($msz -> $newmsz): try again" ;;
170 rm -f
"$tmp/$tag/device"
171 run
mv "$tmp/$tag/dest.new" "$tmp/$tag/dest"
172 if [ -f
"$tmp/$tag/eject" ]; then eject
=t
; else eject
=nil
; fi
173 if [ -f
"$tmp/$tag/ding" ]; then ding
=t
; else ding
=nil
; fi
175 case $eject in t
) run eject
"$dev" ;; esac
178 if [ -t
1 ]; then exec 3>&1
179 elif [ -t
2 ]; then exec 3>&2