8ff1d98a2581448c0e48c63cfd545bcb1bd0e13d
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 echo "$dev" >"$tmp/$tag/device.new"
100 mv "$tmp/$tag/device.new" "$tmp/$tag/device"
102 accumulate_badblocks
() {
103 if [ -f
"$tmp/$tag/badblocks.new" ]; then
104 if [ ! -f
"$tmp/$tag/badblocks" ]; then
105 { echo "## bad-blocks region map"; echo; } >"$tmp/$tag/badblocks"
107 sed -n
"/^[^#]/p" "$tmp/$tag/badblocks.new" >>"$tmp/$tag/badblocks"
108 rm "$tmp/$tag/badblocks.new"
114 for i
in "$tmp/$tag/dest.new" "$tmp/$tag/dest" "$tmp/$tag/dest.seen"; do
115 if [ -f
"$tmp/$tag/dest.new" ]; then any
=t
; fi
118 nil
) printf "%s\n" "$title.iso" >"$tmp/$tag/dest.new" ;;
121 t
) touch "$tmp/$tag/eject" ;;
122 nil
) rm -f
"$tmp/$tag/eject" ;;
125 t
) touch "$tmp/$tag/ding" ;;
126 nil
) rm -f
"$tmp/$tag/ding" ;;
132 if [ -f
"$tmp/$tag/badblocks.retry" ]; then
134 elif [ -f
"$tmp/$tag/badblocks" ]; then
135 run
mv "$tmp/$tag/badblocks" "$tmp/$tag/badblocks.retry"
137 fail
"no blocks to retry"
139 set -- "$@" -R
"$tmp/$tag/badblocks.retry"
140 if [ -f
"$tmp/$tag/iso" ]; then
141 mv "$tmp/$tag/iso" "$tmp/$tag/iso.new"
145 if [ ! -f
"$tmp/$tag/iso" ]; then
146 run
"$DVD_SECTOR_COPY" -cs
${params+"-B$params"} \
147 -b
"$tmp/$tag/badblocks.new" "$@" "$dev" "$tmp/$tag/iso.new"
148 run
mv "$tmp/$tag/iso.new" "$tmp/$tag/iso"
150 rm -f
"$tmp/$tag/device"
151 case $retry in t
) rm -f
"$tmp/$tag/badblocks.retry" ;; esac
152 if [ -f
"$tmp/$tag/badblocks" ]; then
153 fail
"bad sectors found: check \`$tmp/$tag/iso', run again if ok"
157 rm -f
"$tmp/$tag/device"
158 run
mv "$tmp/$tag/dest.new" "$tmp/$tag/dest"
159 if [ -f
"$tmp/$tag/eject" ]; then eject
=t
; else eject
=nil
; fi
160 if [ -f
"$tmp/$tag/ding" ]; then ding
=t
; else ding
=nil
; fi
162 case $eject in t
) run eject
"$dev" ;; esac
165 if [ -t
1 ]; then exec 3>&1
166 elif [ -t
2 ]; then exec 3>&2