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 eject
=nil force
=nil verbose
=nil bogus
=nil
; unset dir sub n label
12 usage: $prog [-befv] [-D DEV] [-a ARCH] [-d DIR]
13 [-l LABEL] [-n N] [-s SUB] [-t TMP] TITLE
16 while getopts "hD:a:bd:efl:n:s:t:v" opt
; do
33 shift $
(( $OPTIND - 1 ))
38 case $bogus in t
) usage
>&2; exit 2 ;; esac
39 case $verbose in t
) set -x
;; esac
41 *:*) archhost
=${archive%%:*} archpath
=${archive#*:} ;;
42 *) unset archhost
; archpath
=$archive ;;
47 echo "$(tput bold; tput setaf $colour)$message$(tput sgr0; tput op)"
49 fail
() { notify
1 "!!! $*"; exit 2; }
50 warn
() { notify
5 "??? $*"; }
51 info
() { notify
6 "--- $*"; }
54 set +e
; nice
"$@"; rc
=$?
; set -e
56 run
() { run_setrc
"$@"; case $rc in 0) ;; *) fail
"$1: exit $rc" ;; esac; }
64 qq
="${qq:+$qq }'${a//\'/"'\\''"}'" #" # emacs is confused
66 "$op" ssh "$archhost" "$qq"
73 archrun
() { archdo run
"$@"; }
75 case ${dir+t},${n+t} in
77 n
=$
(printf "%02d" "$n")
80 echo >&2 "$prog: must specify both directory and disc number, or neither"
86 tr "[:lower:]" "[:upper:]" |
87 tr -Cs
"[:alnum:]_\n" "[-*]" |
93 case ${label+t},${dir+t} in
95 ,) label
=$
(printf "%s" "$title" | hack_label
) ;;
96 ,t
) label
=$
(printf "%s_%s" "$dir" "$n" | hack_label
) ;;
98 len
=$
(printf "%s" "$label" |
wc -c
)
99 if [ $len -gt
32 ]; then echo >&2 "$prog: label too long"; exit 2; fi
103 t
) echo >&2 "$prog: label only meaningful to \`dvdbackup'"; exit 2 ;;
109 t
) tag
="${dir}_${n}_${title}" out
="$dir/$n. $title" ;;
110 *) tag
=$title out
=$title ;;
114 archdo run_setrc
test -f
"$archpath${sub+/$sub}/$out.iso"
116 0,nil
) fail
"output file already exists" ;;
117 0,t
) warn
"output file already exists; will overwrite" ;;
123 if [ ! -d
"$tmp/$tag/rip" ]; then
124 rm -rf
"$tmp/$tag/rip.new"
125 run dvdbackup
-Mp
-i
"$dev" -o
"$tmp/$tag" -n
"rip.new"
126 run
mv "$tmp/$tag/rip.new" "$tmp/$tag/rip"
128 if [ ! -f
"$tmp/$tag/iso" ]; then
129 run genisoimage
-quiet
-dvd-video
-udf
-V
"$label" \
130 -o
"$tmp/$tag/iso.new" "$tmp/$tag/rip"
131 run
mv "$tmp/$tag/iso.new" "$tmp/$tag/iso"
135 if [ ! -f
"$tmp/$tag/iso" ]; then
136 run_setrc
"$DVD_SECTOR_COPY" -c
-b
"$tmp/$tag/badblocks" \
137 "$dev" "$tmp/$tag/iso.new"
140 run
mv "$tmp/$tag/iso.new" "$tmp/$tag/iso"
143 run
mv "$tmp/$tag/iso.new" "$tmp/$tag/iso"
144 fail
"bad sectors found: check \`$tmp/$tag/iso', run again if ok"
147 fail
"$DVD_SECTOR_COPY: exit $rc"
153 printf "%s\n" "${sub+$sub/}$out.iso" >"$tmp/$tag/dest.new"
154 mv "$tmp/$tag/dest.new" "$tmp/$tag/dest"
156 case $eject in t
) run eject
"$dev" ;; esac