#!/bin/sh # Boilerplate _root="$(dirname "${0}")"; . "${_root}/lib/env.sh" # Load needed modules want ansi log progress printf "${a_normal}" src="${1:-root.iso}" out="${2:-root.img}" rm -f "${out}" [ -r "${src}" ] || err "${src}: no such file or directory" [ ! -f "${out}" ] || err "${out}: file exists" command="/usr/bin/mkuzip -s 65536 -v -o '${out}' '${src}' 2>&1 | tee '${_root}/sample.txt'" time_start="$(date +%s)" eval ${command} | sed -l -e '/^compressed /s/^.*$/$finished=yes/' -e '/^cluster /s/^cluster #\([0-9]*\), in \([0-9]*\) bytes, out \([0-9]*\) bytes$/$clust=\1 in=\2 out=\3/' -e '/^data /s/^.* number of clusters \([0-9]*\), .*$/$count=\1/' -e '/^[^$]/d; s/^\$//' | while read line do # initialization clust="${clust:-0}" count="${count:-0}" all_in="${all_in:-0}" all_out="${all_out:-0}" in=0 out=0 # Read in values eval ${line} # Compute aggregates iter="$(( ${iter:-0} + 1 ))" all_in="$(( ${all_in} + ${in} ))" all_out="$(( ${all_out} + ${out} ))" if [ -n "${finished}" -o "$(( ${iter} % ${limit_break:-16} ))" -eq 0 ] && \ [ -n "${finished}" -o "$(date +%s)" != "${time_last}" ] then time="$(date +%s)" clust_diff="$(( ${clust:-0} - ${clust_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} + ( ( ${clust_diff} / ${time_diff} ) / 2 ) ) / 2 ))" clust_last="${clust:-0}" time_last="${time}" [ -n "${finished}" ] && clust="${count}" # Compute current ratio ratio="$(printf "%u / %u\n" "${all_out:-0}" "${all_in:-0}" | bc -l 2>/dev/null)" printf "\r %s %0.4f \033[K" "$(progress "${clust}" "${count}")" "${ratio:-0}" [ -n "${finished}" ] && printf "\n" fi done