|
1 | 1 | #!/bin/sh
|
2 | 2 |
|
3 |
| -set -ex |
| 3 | +# Color support from portable-color <https://mattiebee.dev/portable-color> |
| 4 | + |
| 5 | +_try_color() { |
| 6 | + [ -n "${NO_COLOR}" ] && return 1 |
| 7 | + [ -n "${CLICOLOR_FORCE}" ] && return 0 |
| 8 | + test -t 1 || return 1 |
| 9 | + [ -n "${CLICOLOR}" ] && return 0 |
| 10 | + return 0 |
| 11 | +} |
| 12 | +setup_color() { |
| 13 | + TPUT=$(which tput 2>/dev/null) && _try_color || TPUT=true |
| 14 | +} |
| 15 | +_qtput() { |
| 16 | + [ -z "${TPUT}" ] && return 0 # if not set up, don't do anything |
| 17 | + "${TPUT}" "$@" 2>/dev/null || true |
| 18 | +} |
| 19 | +_twrap() { |
| 20 | + output="$1" |
| 21 | + shift |
| 22 | + _qtput "$@" |
| 23 | + printf %s "$output" |
| 24 | + _qtput sgr0 |
| 25 | +} |
| 26 | +bold() { _twrap "$1" bold; } |
| 27 | +green() { _twrap "$1" setaf 2; } |
| 28 | +blue() { _twrap "$1" setaf 4; } |
| 29 | + |
| 30 | +print_task() { echo "$(green "==>") $(bold "$@")"; } |
| 31 | +print_subtask() { echo "$(blue "==>") $(bold "$@")"; } |
| 32 | + |
| 33 | +set -e |
| 34 | +setup_color |
4 | 35 |
|
5 | 36 | esd="${1}"
|
6 | 37 | tmpdir=$(mktemp -d)
|
7 | 38 |
|
8 | 39 | __cleanup() {
|
9 |
| - set -e |
| 40 | + print_task "Cleaning up $(green "${tmpdir}")" |
10 | 41 | rm -rf "${tmpdir}"
|
11 | 42 | }
|
12 | 43 | trap __cleanup EXIT
|
13 | 44 |
|
| 45 | +print_task "Exporting images from $(green "${esd}")" |
| 46 | + |
14 | 47 | image_count=$(wiminfo "${esd}" --header | grep '^Image Count' | cut -d= -f 2 )
|
| 48 | +echo "Found ${image_count} images." |
15 | 49 |
|
| 50 | +print_subtask "Exporting image 1" |
16 | 51 | wimapply "${esd}" 1 "${tmpdir}"
|
17 |
| -wimexport "${esd}" 2 "${tmpdir}/sources/boot.wim" --compress=LZX --chunk-size 32K |
18 |
| -wimexport "${esd}" 3 "${tmpdir}/sources/boot.wim" --compress=LZX --chunk-size 32K --boot |
19 | 52 |
|
20 |
| -for index in $(seq 4 ${image_count}) |
| 53 | +print_subtask "Exporting image 2" |
| 54 | +wimexport "${esd}" 2 "${tmpdir}/sources/boot.wim" --compress=LZX --chunk-size=32K |
| 55 | + |
| 56 | +print_subtask "Exporting image 3" |
| 57 | +wimexport "${esd}" 3 "${tmpdir}/sources/boot.wim" --compress=LZX --chunk-size=32K --boot |
| 58 | + |
| 59 | +for index in $(seq 4 "${image_count}") |
21 | 60 | do
|
22 |
| - wimexport "${esd}" "${index}" "${tmpdir}/sources/install.esd" --compress=LZMS --chunk-size 128K |
| 61 | + print_subtask "Exporting image ${index}" |
| 62 | + wimexport "${esd}" "${index}" "${tmpdir}/sources/install.esd" --compress=LZMS --chunk-size 128K --recompress |
23 | 63 | done
|
24 | 64 |
|
25 | 65 | basename="$(basename "${esd}" .esd)"
|
26 | 66 | iso="${basename}.iso"
|
27 | 67 |
|
28 | 68 | rm -f "${iso}"
|
| 69 | +print_task "Creating ${iso}" |
29 | 70 | hdiutil makehybrid -o "${iso}" -iso -udf -hard-disk-boot -eltorito-boot "${tmpdir}/efi/microsoft/boot/efisys.bin" -iso-volume-name ESD_ISO -udf-volume-name ESD-ISO "${tmpdir}"
|
30 |
| - |
|
0 commit comments