#! /bin/sh -e . $(dirname $0)/common.sh setenv status "scanning" log "Scanning for DVD title" title=$(dvdbackup -I | awk -F \" '/DVD with title/ {print $2}') setenv title "$title" # How big is this DVD? totalSize=$(dvdbackup -I | awk '/[MK]iB$/ { b += $2 } END { print b }') dvdbackup -p -F -n DVD \ | tr '\r' '\n' \ | awk -F '[ /:]+' ' function update() { print "% " pct; fflush(); } /Found [0-9]+ VTS/ { numTitles = $3; title = 1; pct = 0; print "# I found " numTitles " titles" update() } /Copying menu:/ { # Not sure how to know in advance how many of these there will be. print "# We are reading the menu: " $0 update(); } /Copying Title,/ { # Copying Title, part 1/5: 23% done (239/1024 MiB) part = $4 parts = $5 done = $6 print "# Title " part " of " parts " pct " done titleDone = (part * 100 - 100 + done) / parts; if (titleDone < titleLast) { title += 1; } titleLast = titleDone; pct = (title * 100 - 100 + pctDone) / numTitles; update(); } { print "## " $0; update(); } ' \ | while read t val; do case "$t" in "%") setenv complete "$val" echo "Complete: $val" ;; *) echo "$t $val" ;; esac done