@@ -106,6 +106,44 @@ find_dev() {
106106 echo " $l_iso_dev "
107107}
108108
109+ extract_image () {
110+ image_path=" $1 "
111+ 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
137+
138+ # Wait for dialog to finish reading remaining input and exit
139+ wait " $DIALOG_PID " 2> /dev/null || true
140+
141+ # Cleanup and return the pipeline's exit code
142+ trap - EXIT
143+ _cleanup
144+ return " $RC "
145+ }
146+
109147main () {
110148
111149 iso_dev=" $( find_dev) "
@@ -115,9 +153,19 @@ main() {
115153
116154 mount_iso " ${iso_dev} " " ${mount_point} "
117155
156+ # Lower kernel console loglevel temporarily, so dialogs are not destroyed.
157+ echo 1 > /proc/sys/kernel/printk
158+
118159 # Loop-mount the embedded image (read-only by default)
119- if [ ! -e " $mount_point$image " ]; then
120- raise " WARN: $mount_point$image not found"
160+ # Support either uncompressed image or a gzipped image on the ISO
161+ if [ -e " $mount_point$image " ]; then
162+ image_path=" $mount_point$image "
163+ elif [ -e " $mount_point ${image} .zst" ]; then
164+ image_path=" $mount_point ${image} .zst"
165+ elif [ -e " $mount_point ${image} .gz" ]; then
166+ image_path=" $mount_point ${image} .gz"
167+ else
168+ raise " WARN: $mount_point$image or ${image} .zst/gz not found"
121169 fi
122170
123171 echo " Running custom installer..."
@@ -127,6 +175,10 @@ main() {
127175 while read -r name type ro size model; do
128176 [ " $type " = " disk" ] || continue
129177 [ " $ro " = " 0" ] || continue
178+ # Filter out iso_dev
179+ if [ " /dev/$name " = " $iso_dev " ]; then
180+ continue
181+ fi
130182 safe_model=$( echo " $model " | tr ' ' ' _' )
131183 label=" ${size} _${safe_model} "
132184 DISKS=" $DISKS $name $label off"
@@ -141,18 +193,22 @@ INNEREOF
141193 if [ " $COUNT " -eq 0 ]; then
142194 raise " No writable disks found"
143195 fi
196+ if [ " $COUNT " -eq 1 ]; then
197+ # select it automatically, it replace off by on
198+ DISKS=$( echo " $DISKS " | sed ' s/ off$/ on/' )
199+ fi
144200
145- # if [ "$COUNT" -eq 1 ]; then
146- # target=$(echo "$DISKS" | awk '{print $1}')
147- # else
201+ if [ " $COUNT " -eq 1 ] && [ -f " $mount_point /installer_auto_overwrite_disk.txt " ]; then
202+ target=$( echo " $DISKS " | awk ' {print $1}' )
203+ else
148204 # shellcheck disable=SC2086
149205 target=$( dialog --clear --backtitle " Installer" \
150206 --title " Select Target Disk. The disk will be OVERWRITTEN." \
151207 --no-cancel \
152208 --radiolist " \nUse up/down keys, select with space key and hit enter:\n " 15 70 5 \
153209 $DISKS 3>&1 1>&2 2>&3 )
154210 clear
155- # fi
211+ fi
156212
157213 if [ -z " $target " ]; then
158214 raise " No disk selected"
@@ -161,13 +217,14 @@ INNEREOF
161217 echo " $target "
162218
163219
164- echo " Writing $image to /dev/$target ... (this may take a while)"
165- if ! dd if= " $mount_point$image " of= " /dev/ $target " bs=4M iflag=fullblock ; then
220+ echo " Writing $( basename " $image_path " ) to /dev/$target ... (this may take a while)"
221+ if ! extract_image " $image_path " " $target " ; then
166222 raise " Failed writing image to disk"
167223 fi
168224
169225 sync
170- echo " Done."
226+ dialog --backtitle " Installer" --title " Image sucessfully written to disk" --infobox " \nThe system will reboot now.\n\nEnsure to boot from the selected disk." 10 70
227+ sleep 1
171228 # sh
172229 reboot -f
173230}
0 commit comments