Skip to content

Commit 5afd7d5

Browse files
committed
Use redi_url instead of direct image
1 parent 8d99e40 commit 5afd7d5

File tree

6 files changed

+80
-80
lines changed

6 files changed

+80
-80
lines changed

tools/include/images/FLASH1.png

20.2 KB
Loading

tools/include/markdown/FLASH1-footer.md

Whitespace-only changes.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
This module provides a simple way to download and flash any Armbian OS image from our servers. It lets you prepare a bootable SD card or, when running from live media, flash a fresh OS directly onto the device’s internal storage. All flashed images are automatically verified to ensure data integrity and reliable installation.
1+
What can this tool do?
2+
3+
- Install Armbian onto internal **eMMC, SSD, or other storage**
4+
- Create **bootable SD cards or USB drives** for any supported board
5+
- Recover a system by **re-flashing a clean image**
6+
- Switch between different **OS variants, kernel branches, or preinstalled applications**
7+
- Accelerate development with **fast, repeatable deployments** for testing and automation
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
This section provides an option to transfer the live running Armbian system from an SD card to internal storage devices such as eMMC, SATA, NVMe, or USB drives. It prepares the target storage, copies the active system, adjusts bootloader settings, and ensures the system can boot independently without requiring reinstallation.
1+
- Clones your current live OS installation
2+
- Keeps your settings, configuration, installed packages, and user data
3+
- Essentially “transfer my existing system to internal/external storage”
4+
5+
Use this option to **transfer your current live Armbian system** to another storage device (eMMC, SSD, USB, etc.). This copies your existing installation exactly as it is — including settings, installed packages, and user data.

tools/json/config.system.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"sub": [
9292
{
9393
"id": "STO001",
94-
"description": "Copy live OS to internal media",
94+
"description": "Copy the running Armbian system to another device",
9595
"short": "Install",
9696
"module": "module_generic",
9797
"command": [
@@ -103,7 +103,7 @@
103103
},
104104
{
105105
"id": "FLASH1",
106-
"description": "Download and flash to internal media",
106+
"description": "Download a fresh, official Armbian OS image and write it to a device",
107107
"short": "Download and flash",
108108
"module": "module_images",
109109
"command": [

tools/modules/software/module_images.sh

Lines changed: 66 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module_options+=(
88
["module_images,example"]="install remove purge status help"
99
["module_images,desc"]="Download and flash Armbian OS images for selected hardware"
1010
["module_images,status"]="Active"
11-
["module_images,doc_link"]="https://docs.armbian.com/User-Guide_Recovery/"
11+
["module_images,doc_link"]=""
1212
["module_images,group"]="Management"
1313
["module_images,arch"]="x86-64 arm64 armhf"
1414
)
@@ -775,62 +775,47 @@ function module_images () {
775775
}
776776

777777
# Helper: download image file
778-
# We only have .img.xz: download and decompress on the fly to .img
778+
# Download is always done using file_url (full path)
779+
# redi_url is only shown to the user as a clean short link
779780
download_image_file() {
780-
local file_url file_ext image_url filename dirname base real_image_ext
781+
local file_url redi_url file_ext image_url filename dirname raw_filename
781782

783+
# Always download using file_url
782784
file_url=$(jq -r '.file_url' <<< "$IMAGE_JSON")
785+
redi_url=$(jq -r '.redi_url // ""' <<< "$IMAGE_JSON")
783786
file_ext=$(jq -r '.file_extension // ""' <<< "$IMAGE_JSON")
784787

785-
# Derive real image extension and URL
786-
if [[ -n "$file_ext" && "$file_ext" == img.xz ]]; then
787-
# JSON already tells us it's img.xz
788-
image_url="$file_url"
789-
else
790-
# Fallback: strip known non-image tails from URL if needed
791-
case "$file_url" in
792-
*.img.xz)
793-
image_url="$file_url"
794-
;;
795-
*.asc|*.torrent|*.sha*)
796-
image_url="${file_url%.*}"
797-
;;
798-
*)
799-
image_url="$file_url"
800-
;;
801-
esac
802-
fi
788+
# Determine real downloadable URL (must be file_url)
789+
case "$file_url" in
790+
*.img.xz) image_url="$file_url" ;;
791+
*.asc|*.torrent|*.sha*) image_url="${file_url%.*}" ;;
792+
*) image_url="$file_url" ;;
793+
esac
803794

804-
filename=$(basename "$image_url") # e.g. Armbian_xxx_Board.img.xz
805-
dirname=${image_url%/*}
795+
filename=$(basename "$image_url")
796+
raw_filename="${filename%.xz}"
806797

807-
# We want a local UNCOMPRESSED .img
808-
local raw_filename="${filename%.xz}" # strip .xz → .img
809798
LOCAL_IMAGE_PATH="${IMAGES_BASE}/${raw_filename}"
810799

811-
# If already present, optionally reuse
800+
# If already present, ask reuse
812801
if [[ -f "$LOCAL_IMAGE_PATH" ]]; then
813802
if [[ -n "$DIALOG" ]]; then
814-
if $DIALOG --title "Image already available" --yesno \
815-
"Uncompressed image already exists:\n\n$LOCAL_IMAGE_PATH\n\nReuse this file?" 12 70; then
816-
return 0
817-
fi
803+
$DIALOG --title "Note" --yesno \
804+
"\nUncompressed image already exists in ${IMAGES_BASE}/:\n\n${raw_filename}\n\nReuse this file?" \
805+
12 70 && return 0
818806
else
819807
read -rp "Image $LOCAL_IMAGE_PATH exists. Reuse? [y/N]: " reuse
820-
if [[ "$reuse" =~ ^[Yy]$ ]]; then
821-
return 0
822-
fi
808+
[[ "$reuse" =~ ^[Yy]$ ]] && return 0
823809
fi
824-
# If user does not want to reuse, remove the old file
825810
rm -f "$LOCAL_IMAGE_PATH"
826811
fi
827812

828-
# Size of the COMPRESSED file (for pv/gauge)
813+
# File size for pv gauge
829814
local content_length
830815
content_length=$(jq -r '(.file_size // "0")' <<< "$IMAGE_JSON")
831816
[[ -z "$content_length" ]] && content_length=0
832817

833-
# Ensure xz exists
818+
# Must have xz
834819
if ! command -v xz >/dev/null 2>&1; then
835820
echo "xz is required to decompress the image."
836821
return 1
@@ -839,54 +824,56 @@ function module_images () {
839824
# -------------------------
840825
# Download + decompress
841826
# -------------------------
827+
local display_url="$redi_url"
828+
[[ -z "$display_url" ]] && display_url="$image_url"
829+
842830
local rc=0
843831

844-
if command -v pv >/dev/null 2>&1 && [[ -n "$DIALOG" ]] && [[ "$content_length" =~ ^[0-9]+$ ]] && (( content_length > 0 )); then
845-
# Use whiptail gauge driven by pv (on COMPRESSED size)
846-
local gauge_fifo
847-
gauge_fifo=$(mktemp -u)
848-
mkfifo "$gauge_fifo"
832+
if command -v pv >/dev/null 2>&1 && [[ -n "$DIALOG" ]] && (( content_length > 0 )); then
833+
local gauge_dir
834+
gauge_dir=$(mktemp -d) || { echo "Failed to create temp dir"; return 1; }
835+
local gauge_fifo="${gauge_dir}/fifo"
836+
mkfifo "$gauge_fifo" || { rm -rf "$gauge_dir"; return 1; }
849837

850-
"$DIALOG" --title "Armbian imager" \
851-
--gauge "Downloading and decompressing Armbian image...\n\n$image_url" 10 70 0 \
852-
< "$gauge_fifo" &
838+
$DIALOG --title "Armbian imager" \
839+
--gauge "\nDownloading and decompressing Armbian image...\n\n$display_url" \
840+
10 70 0 < "$gauge_fifo" &
853841
local gauge_pid=$!
854842

855-
# curl (compressed) → pv (0..100 based on compressed size) → xz -dc → .img
856-
if ! curl -fSL "$image_url" 2>/dev/null \
857-
| pv -n -s "$content_length" 2> "$gauge_fifo" \
858-
| xz -T0 -dc \
859-
> "$LOCAL_IMAGE_PATH"; then
860-
rc=$?
861-
else
862-
rc=0
863-
fi
843+
{
844+
curl -fSL "$image_url" 2>/dev/null \
845+
| pv -n -s "$content_length" 2> "$gauge_fifo" \
846+
| xz -T0 -dc \
847+
> "$LOCAL_IMAGE_PATH"
848+
} || rc=$?
864849

865-
# Close FIFO & wait gauge
866-
exec 3>&-
867850
rm -f "$gauge_fifo"
851+
rmdir "$gauge_dir" 2>/dev/null || true
868852
wait "$gauge_pid" 2>/dev/null || true
869853

870-
if [[ $rc -ne 0 ]]; then
854+
(( rc != 0 )) && {
871855
echo "Failed to download or decompress image: $image_url"
872856
rm -f "$LOCAL_IMAGE_PATH"
873857
return 1
874-
fi
858+
}
859+
875860
else
876-
# Fallback: no pv or no DIALOG or no size → plain stream
861+
# Fallback simple mode
877862
if [[ -n "$DIALOG" ]]; then
878-
"$DIALOG" --infobox "Downloading and decompressing Armbian image...\n\n$image_url" 8 70
863+
$DIALOG --infobox \
864+
"\nDownloading and decompressing Armbian image...\n\n$display_url" \
865+
8 70
879866
else
880-
echo "Downloading and decompressing image from $image_url ..."
867+
echo "Downloading and decompressing: $display_url"
881868
fi
882869

883-
if ! curl -fSL "$image_url" \
870+
curl -fSL "$image_url" \
884871
| xz -T0 -dc \
885-
> "$LOCAL_IMAGE_PATH"; then
886-
echo "Failed to download or decompress image: $image_url"
887-
rm -f "$LOCAL_IMAGE_PATH"
888-
return 1
889-
fi
872+
> "$LOCAL_IMAGE_PATH" || {
873+
echo "Failed to download or decompress: $image_url"
874+
rm -f "$LOCAL_IMAGE_PATH"
875+
return 1
876+
}
890877
fi
891878

892879
return 0
@@ -922,9 +909,10 @@ function module_images () {
922909
# FLASH PHASE (with gauge if pv + $DIALOG available)
923910
# ------------------------------------------------------------
924911
if command -v pv >/dev/null 2>&1 && [[ -n "$DIALOG" ]]; then
925-
local gauge_fifo
926-
gauge_fifo=$(mktemp -u)
927-
mkfifo "$gauge_fifo"
912+
local gauge_dir
913+
gauge_dir=$(mktemp -d) || { echo "Failed to create temp dir"; return 1; }
914+
local gauge_fifo="${gauge_dir}/fifo"
915+
mkfifo "$gauge_fifo" || { rm -rf "$gauge_dir"; return 1; }
928916

929917
# Reader: takes percentages from FIFO and feeds whiptail
930918
{
@@ -943,6 +931,7 @@ function module_images () {
943931

944932
# Close FIFO and wait for whiptail to exit
945933
rm -f "$gauge_fifo"
934+
rmdir "$gauge_dir" 2>/dev/null || true
946935
wait "$gauge_pid" 2>/dev/null || true
947936
else
948937
# Fallback: console progress
@@ -974,14 +963,14 @@ function module_images () {
974963

975964
if command -v pv >/dev/null 2>&1 && [[ -n "$DIALOG" ]]; then
976965
# Gauge for verification
977-
local v_fifo
978-
v_fifo=$(mktemp -u)
979-
mkfifo "$v_fifo"
980-
966+
local gauge_dir
967+
gauge_dir=$(mktemp -d) || { echo "Failed to create temp dir"; return 1; }
968+
local gauge_fifo="${gauge_dir}/fifo"
969+
mkfifo "$gauge_fifo" || { rm -rf "$gauge_dir"; return 1; }
981970
{
982971
while read -r line; do
983972
echo "$line"
984-
done < "$v_fifo"
973+
done < "$gauge_fifo"
985974
} | "$DIALOG" --title "Armbian imager" \
986975
--gauge "\nVerifying written image on $dev...\n\nPlease wait." 10 70 0 &
987976
local v_pid=$!
@@ -990,11 +979,12 @@ function module_images () {
990979
verify_result=1
991980
{
992981
dd if="$dev" bs=$block_size count=$blocks status=none \
993-
| pv -n -s "$img_size_bytes" 2> "$v_fifo" \
982+
| pv -n -s "$img_size_bytes" 2> "$gauge_fifo" \
994983
| cmp -n "$img_size_bytes" "$img" - >/dev/null
995984
} || verify_result=0
996985

997-
rm -f "$v_fifo"
986+
rm -f "$gauge_fifo"
987+
rmdir "$gauge_dir" 2>/dev/null || true
998988
wait "$v_pid" 2>/dev/null || true
999989
else
1000990
# No gauge, but still verify

0 commit comments

Comments
 (0)