]> CyberLeo.Net >> Repos - CDN/Mosi.git/blob - script/geniso
Move mkisofs parameter docs into script/geniso where they belong
[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 # mkisofs switch meanings
32 # -v            Verbose
33 # -gui          GUI-suitable status messages
34 # -D            No deep directory relocation (and no RR_MOVED)
35 # -R            Include rock-ridge extensions
36 # -no-pad       Don't pad to 150 sectors
37 # -iso-level 4  iso8859:1999 standard
38 # -p CyberLeo   Set preparer string
39 # -V <volname>  Set volume label
40 # -o splat      output filename
41 command="/usr/local/bin/mkisofs -v -gui -D -R -no-pad -iso-level 4 -p CyberLeo -V '${name}' -o '${out}' '${src}' 2>&1"
42
43 time_start="$(date +%s)"
44
45 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
46 do
47   # initialization
48   count="${count:-0}"
49
50   # Read in values
51   eval ${line}
52
53   # Compute aggregates
54   iter="$(( ${iter:-0} + 1 ))"
55   
56   if [ -n "${finished}" -o "$(( ${iter} % ${limit_break:-16} ))" -eq 0 ] && \
57     [ -n "${finished}" -o "$(date +%s)" != "${time_last}" ]
58   then
59     time="$(date +%s)"
60     
61     iter_diff="$(( ${iter:-0} - ${iter_last:-0} ))"
62     time_diff="$(( ${time} - ${time_last:-0} ))"
63     
64     # Adjust last iteration length as a rolling average of half the last per-second cluster count
65     [ -z "${finished}" ] && limit_break="$(( ( ${limit_break:-16} + ( ( ${iter_diff} / ${time_diff} ) / 2 ) ) / 2 ))"
66     [ "${limit_break}" -eq 0 ] && limit_break=1 # Avoid divide-by-zero errors
67
68     iter_last="${iter:-0}"
69     time_last="${time}"
70
71     [ -n "${finished}" ] && count="${total}"
72
73     printf "\r %s\033[K" "$(progress "${count}" "${total}")"
74
75     [ -n "${finished}" ] && printf "\n"
76   fi
77 done