#!/bin/sh # Boilerplate _root="$(dirname "${0}")"; . "${_root}/lib/env.sh" # Load needed modules want ansi log progress printf "${a_normal}" pebkac() { echo "Insert help here" } # Parse command line options while getopts "n:h" opt do case "${opt}" in n) name="${OPTARG}" ;; h) pebkac ;; [?]) pebkac "Unrecognized option ${opt}" ;; esac done shift $(( $OPTIND - 1 )) src="${1}" out="${2}" [ -r "${src}" ] || err "${src}: no such file or directory" [ ! -f "${out}" ] || err "${out}: file exists" # mkisofs switch meanings # -v Verbose # -gui GUI-suitable status messages # -D No deep directory relocation (and no RR_MOVED) # -R Include rock-ridge extensions # -no-pad Don't pad to 150 sectors # -iso-level 4 iso8859:1999 standard # -p CyberLeo Set preparer string # -V Set volume label # -o splat output filename command="/usr/local/bin/mkisofs -v -gui -D -R -no-pad -iso-level 4 -p CyberLeo -V '${name}' -o '${out}' '${src}' 2>&1" time_start="$(date +%s)" eval ${command} | sed -l -e '/^Writing: *The File(s).*$/s/^.*$/started=1 total=10000/; s/^\([ 0-9.%]*\) done.*$/count=\1/; /^[0-9]* extents written/s/^.*$/finished=1/; /=/!d; /^count=/s/[ .%]//g' | while read line do # initialization count="${count:-0}" # Read in values eval ${line} # Compute aggregates iter="$(( ${iter:-0} + 1 ))" if [ -n "${finished}" -o "$(( ${iter} % ${limit_break:-16} ))" -eq 0 ] && \ [ -n "${finished}" -o "$(date +%s)" != "${time_last}" ] then time="$(date +%s)" iter_diff="$(( ${iter:-0} - ${iter_last:-0} ))" time_diff="$(( ${time} - ${time_last:-0} ))" # Adjust last iteration length as a rolling average of half the last per-second cluster count [ -z "${finished}" ] && limit_break="$(( ( ${limit_break:-16} + ( ( ${iter_diff} / ${time_diff} ) / 2 ) ) / 2 ))" [ "${limit_break}" -eq 0 ] && limit_break=1 # Avoid divide-by-zero errors iter_last="${iter:-0}" time_last="${time}" [ -n "${finished}" ] && count="${total}" printf "\r %s\033[K" "$(progress "${count}" "${total}")" [ -n "${finished}" ] && printf "\n" fi done