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}
8 : ${DVDRIP_UPLOAD=dvdrip-upload}
9 backup
=nil ding
=nil eject
=nil force
=nil retry
=nil verbose
=nil bogus
=nil
13 usage: $prog [-defrv] [-D DEV] [-a ARCH] [-t TMP] TITLE
16 while getopts "hB:D:a:defrt:v" opt
; do
19 B
) params
=${params+$params,}$OPTARG ;;
31 shift $
(( $OPTIND - 1 ))
32 case $# in 1) title
=$1 ;; *) bogus
=t
;; esac
33 case $bogus in t
) usage
>&2; exit 2 ;; esac
34 case $verbose in t
) set -x
;; esac
36 *:*) archhost
=${archive%%:*} archpath
=${archive#*:} ;;
37 *) unset archhost
; archpath
=$archive ;;
42 echo "$(tput bold; tput setaf $colour)$message$(tput sgr0; tput op)"
44 fail
() { notify
1 "!!! $*"; exit 2; }
45 warn
() { notify
5 "??? $*"; }
46 info
() { notify
6 "--- $*"; }
49 set +e
; nice
"$@"; rc
=$?
; set -e
51 run
() { run_setrc
"$@"; case $rc in 0) ;; *) fail
"$1: exit $rc" ;; esac; }
59 qq
="${qq:+$qq }'${a//\'/"'\\''"}'" #" # emacs is confused
61 "$op" ssh "$archhost" "$qq"
68 archrun
() { archdo run
"$@"; }
72 archdo run_setrc
test -f
"$archpath/$title.iso"
74 0,nil
) fail
"output file already exists" ;;
75 0,t
) warn
"output file already exists; will overwrite" ;;
80 discid
=$
(dvd-id
"$dev")
81 if [ -f
"$tmp/$tag/discid" ]; then
82 read oldid
<"$tmp/$tag/discid"
84 t
,"$discid" | nil
,"$discid")
87 fail
"discid mismatch: expected \`$oldid' but drive has \`$discid'"
90 warn
"discid mismatch: expected \`$oldid' but drive has \`$discid'; continuing anway"
94 info
"copying \`$discid'"
95 echo "$discid" >"$tmp/$tag/discid.new"
96 mv "$tmp/$tag/discid.new" "$tmp/$tag/discid"
98 echo "$dev" >"$tmp/$tag/device.new"
99 mv "$tmp/$tag/device.new" "$tmp/$tag/device"
101 accumulate_badblocks
() {
102 if [ -f
"$tmp/$tag/badblocks.new" ]; then
103 if [ ! -f
"$tmp/$tag/badblocks" ]; then
104 { echo "## bad-blocks region map"; echo; } >"$tmp/$tag/badblocks"
106 sed -n
"/^[^#]/p" "$tmp/$tag/badblocks.new" >>"$tmp/$tag/badblocks"
107 rm "$tmp/$tag/badblocks.new"
113 for i
in "$tmp/$tag/dest.new" "$tmp/$tag/dest" "$tmp/$tag/dest.seen"; do
114 if [ -f
"$tmp/$tag/dest.new" ]; then any
=t
; fi
117 nil
) printf "%s\n" "$title.iso" >"$tmp/$tag/dest.new" ;;
120 t
) touch "$tmp/$tag/eject" ;;
121 nil
) rm -f
"$tmp/$tag/eject" ;;
124 t
) touch "$tmp/$tag/ding" ;;
125 nil
) rm -f
"$tmp/$tag/ding" ;;
131 if [ -f
"$tmp/$tag/badblocks.retry" ]; then
133 elif [ -f
"$tmp/$tag/badblocks" ]; then
134 run
mv "$tmp/$tag/badblocks" "$tmp/$tag/badblocks.retry"
136 fail
"no blocks to retry"
138 set -- "$@" -R
"$tmp/$tag/badblocks.retry"
139 if [ -f
"$tmp/$tag/iso" ]; then
140 mv "$tmp/$tag/iso" "$tmp/$tag/iso.new"
144 if [ ! -f
"$tmp/$tag/iso" ]; then
145 run
"$DVD_SECTOR_COPY" -cs
${params+"-B$params"} \
146 -b
"$tmp/$tag/badblocks.new" "$@" "$dev" "$tmp/$tag/iso.new"
147 run
mv "$tmp/$tag/iso.new" "$tmp/$tag/iso"
149 rm -f
"$tmp/$tag/device"
150 case $retry in t
) rm -f
"$tmp/$tag/badblocks.retry" ;; esac
151 if [ -f
"$tmp/$tag/badblocks" ]; then
152 fail
"bad sectors found: check \`$tmp/$tag/iso', run again if ok"
156 rm -f
"$tmp/$tag/device"
157 run
mv "$tmp/$tag/dest.new" "$tmp/$tag/dest"
158 if [ -f
"$tmp/$tag/eject" ]; then eject
=t
; else eject
=nil
; fi
159 if [ -f
"$tmp/$tag/ding" ]; then ding
=t
; else ding
=nil
; fi
161 case $eject in t
) run eject
"$dev" ;; esac
164 if [ -t
1 ]; then exec 3>&1
165 elif [ -t
2 ]; then exec 3>&2