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 accumulate_badblocks () {
99 if [ -f "$tmp/$tag/badblocks.new" ]; then
100 if [ ! -f "$tmp/$tag/badblocks" ]; then
101 { echo "## bad-blocks region map"; echo; } >"$tmp/$tag/badblocks"
103 sed -n "/^[^#]/p" "$tmp/$tag/badblocks.new" >>"$tmp/$tag/badblocks"
104 rm "$tmp/$tag/badblocks.new"
110 for i in "$tmp/$tag/dest.new" "$tmp/$tag/dest" "$tmp/$tag/dest.seen"; do
111 if [ -f "$tmp/$tag/dest.new" ]; then any=t; fi
114 nil) printf "%s\n" "$title.iso" >"$tmp/$tag/dest.new" ;;
117 t) touch "$tmp/$tag/eject" ;;
118 nil) rm -f "$tmp/$tag/eject" ;;
121 t) touch "$tmp/$tag/ding" ;;
122 nil) rm -f "$tmp/$tag/ding" ;;
128 if [ -f "$tmp/$tag/badblocks.retry" ]; then
130 elif [ -f "$tmp/$tag/badblocks" ]; then
131 run mv "$tmp/$tag/badblocks" "$tmp/$tag/badblocks.retry"
133 fail "no blocks to retry"
135 set -- "$@" -R"$tmp/$tag/badblocks.retry"
136 if [ -f "$tmp/$tag/iso" ]; then
137 mv "$tmp/$tag/iso" "$tmp/$tag/iso.new"
141 if [ ! -f "$tmp/$tag/iso" ]; then
142 run "$DVD_SECTOR_COPY" -cs ${params+"-B$params"} \
143 -b"$tmp/$tag/badblocks.new" "$@" "$dev" "$tmp/$tag/iso.new"
144 run mv "$tmp/$tag/iso.new" "$tmp/$tag/iso"
146 case $retry in t) rm -f "$tmp/$tag/badblocks.retry" ;; esac
147 if [ -f "$tmp/$tag/badblocks" ]; then
148 fail "bad sectors found: check \`$tmp/$tag/iso', run again if ok"
152 run mv "$tmp/$tag/dest.new" "$tmp/$tag/dest"
153 if [ -f "$tmp/$tag/eject" ]; then eject=t; else eject=nil; fi
154 if [ -f "$tmp/$tag/ding" ]; then ding=t; else ding=nil; fi
156 case $eject in t) run eject "$dev" ;; esac
159 if [ -t 1 ]; then exec 3>&1
160 elif [ -t 2 ]; then exec 3>&2