]> CyberLeo.Net >> Repos - CDN/Mosi.git/blob - script/geniso
boot/zfs symlink so that zpool.cache persists
[CDN/Mosi.git] / script / geniso
1 #!/bin/sh
2
3 # Boilerplate
4 _root="$(dirname "${0}")"; . "${_root}/lib/env.sh"
5
6 # Load needed modules
7 want ansi log progress
8 printf "${a_normal}"
9
10 pebkac() {
11   echo "Insert help here"
12 }
13
14 # Parse command line options
15 while getopts "n:h" opt
16 do
17   case "${opt}" in
18     n) name="${OPTARG}" ;;
19     h) pebkac ;;
20     [?]) pebkac "Unrecognized option ${opt}" ;;
21   esac
22 done
23 shift $(( $OPTIND - 1 ))
24
25 src="${1}"
26 out="${2}"
27
28 [ -r "${src}" ] || err "${src}: no such file or directory"
29 [ ! -f "${out}" ] || err "${out}: file exists"
30
31 command="/usr/local/bin/mkisofs -v -gui -D -R -no-pad -iso-level 4 -p CyberLeo -V '${name}' -o '${out}' '${src}' 2>&1"
32
33 time_start="$(date +%s)"
34
35 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
36 do
37   # initialization
38   count="${count:-0}"
39
40   # Read in values
41   eval ${line}
42
43   # Compute aggregates
44   iter="$(( ${iter:-0} + 1 ))"
45   
46   if [ -n "${finished}" -o "$(( ${iter} % ${limit_break:-16} ))" -eq 0 ] && \
47     [ -n "${finished}" -o "$(date +%s)" != "${time_last}" ]
48   then
49     time="$(date +%s)"
50     
51     iter_diff="$(( ${iter:-0} - ${iter_last:-0} ))"
52     time_diff="$(( ${time} - ${time_last:-0} ))"
53     
54     # Adjust last iteration length as a rolling average of half the last per-second cluster count
55     [ -z "${finished}" ] && limit_break="$(( ( ${limit_break:-16} + ( ( ${iter_diff} / ${time_diff} ) / 2 ) ) / 2 ))"
56     [ "${limit_break}" -eq 0 ] && limit_break=1 # Avoid divide-by-zero errors
57
58     iter_last="${iter:-0}"
59     time_last="${time}"
60
61     [ -n "${finished}" ] && count="${total}"
62
63     printf "\r %s\033[K" "$(progress "${count}" "${total}")"
64
65     [ -n "${finished}" ] && printf "\n"
66   fi
67 done