@@ -109,39 +109,28 @@ find_dev() {
109109extract_image () {
110110 image_path=" $1 "
111111 target=" $2 "
112- # Use a named pipe so dialog reads progress separately from the decompression pipeline.
113- PROG_FIFO=" /tmp/imgprog.$$ "
114- mkfifo " $PROG_FIFO " || return 1
115- # ensure fifo is removed on function exit
116- _cleanup () {
117- rm -f " $PROG_FIFO " 2> /dev/null || true
118- }
119- trap _cleanup EXIT
120-
121- # Start dialog reading progress from the fifo in the background
122- dialog --gauge " Preparing to extract image, please wait..." 10 70 0 < " $PROG_FIFO " &
123- DIALOG_PID=$!
124-
125- # Run the actual decompression/writing pipeline; pv will write numeric progress to stderr,
126- # which we redirect into the fifo so dialog displays it. Capture the pipeline exit code.
127- if echo " $image_path " | grep -qE ' \.zst$' ; then
128- pv -n " $image_path " 2> " $PROG_FIFO " | zstd -d -c | dd of=" /dev/$target " bs=4M conv=notrunc,noerror
129- RC=$?
130- elif echo " $image_path " | grep -qE ' \.gz$' ; then
131- pv -n " $image_path " 2> " $PROG_FIFO " | gunzip -c | dd of=" /dev/$target " bs=4M conv=notrunc,noerror
132- RC=$?
133- else
134- pv -n " $image_path " 2> " $PROG_FIFO " | dd of=" /dev/$target " bs=4M conv=notrunc,noerror
135- RC=$?
136- fi
137112
138- # Wait for dialog to finish reading remaining input and exit
139- wait " $DIALOG_PID " 2> /dev/null || true
113+ (
114+ if echo " $image_path " | grep -qE ' \.zst$' ; then
115+ if ! pv -n " $image_path " | zstd -d -c | dd of=" /dev/$target " bs=4M conv=notrunc,noerror; then
116+ touch /tmp/extract_image_failed
117+ fi
118+ elif echo " $image_path " | grep -qE ' \.gz$' ; then
119+ if ! pv -n " $image_path " | gzip -d -c | dd of=" /dev/$target " bs=4M conv=notrunc,noerror; then
120+ touch /tmp/extract_image_failed
121+ fi
122+ else
123+ if ! pv -n " $image_path " | dd of=" /dev/$target " bs=4M conv=notrunc,noerror; then
124+ touch /tmp/extract_image_failed
125+ fi
126+ fi
127+ ) 2>&1 | dialog --gauge " Extract the image, please wait..." 10 70 0
140128
141- # Cleanup and return the pipeline's exit code
142- trap - EXIT
143- _cleanup
144- return " $RC "
129+ if [ -f /tmp/extract_image_failed ]; then
130+ rm -f /tmp/extract_image_failed
131+ return 1
132+ fi
133+ return 0
145134}
146135
147136main () {
0 commit comments