Skip to content

Commit 774613e

Browse files
committed
error-check getting image count
1 parent 399432a commit 774613e

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
1. Replaced status messages with nicer, easier-to-read messages in color.
66

77
2. Added error checking for presence of wimlib tools and ESD image before starting.
8+
9+
3. Added error checking to image count check.
10+

windows-esd-to-iso

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ set -e
3535
setup_color
3636

3737
if [ -z "$1" ] || [ "$1" = "-h" ]; then
38-
echo "$(red "Usage:") $(basename "$0") ESD"
39-
exit 0
38+
echo "$(red "Usage:") $(basename "$0") ESD"
39+
exit 0
4040
fi
4141

4242
check_tool() {
43-
if ! which "$1" >/dev/null; then
44-
echo "$(red "Error:") wimlib tools not found"
43+
if ! which "$1" >/dev/null; then
44+
echo "$(red "Error:") wimlib tools not found"
4545
exit 1
4646
fi
4747
}
@@ -52,21 +52,25 @@ check_tool wimexport
5252
esd="$1"
5353

5454
if [ ! -f "${esd}" ]; then
55-
echo "$(red "Error:") ${esd} not found"
56-
exit 2
55+
echo "$(red "Error:") ${esd} not found"
56+
exit 2
5757
fi
5858

5959
tmpdir=$(mktemp -d)
6060

6161
__cleanup() {
62-
print_task "Cleaning up $(green "${tmpdir}")"
63-
rm -rf "${tmpdir}"
62+
print_task "Cleaning up $(green "${tmpdir}")"
63+
rm -rf "${tmpdir}"
6464
}
6565
trap __cleanup EXIT
6666

6767
print_task "Exporting images from $(green "${esd}")"
6868

69-
image_count=$(wiminfo "${esd}" --header | grep '^Image Count' | cut -d= -f 2 )
69+
image_count=$(wiminfo "${esd}" --header | grep '^Image Count' | cut -d= -f 2)
70+
if ! [ "${image_count}" -gt 0 ] 2>/dev/null; then
71+
echo "$(red "Error:") could not get ${esd} image count"
72+
exit 3
73+
fi
7074
echo "Found ${image_count} images."
7175

7276
print_subtask "Exporting image 1"
@@ -80,7 +84,7 @@ wimexport "${esd}" 3 "${tmpdir}/sources/boot.wim" --compress=LZX --chunk-size=32
8084

8185
for index in $(seq 4 "${image_count}")
8286
do
83-
print_subtask "Exporting image ${index}"
87+
print_subtask "Exporting image ${index}"
8488
wimexport "${esd}" "${index}" "${tmpdir}/sources/install.esd" --compress=LZMS --chunk-size 128K --recompress
8589
done
8690

0 commit comments

Comments
 (0)