From 4930c5dc704df36a223b64915466f7b585f2aead Mon Sep 17 00:00:00 2001 From: thetechprepper Date: Wed, 20 Aug 2025 20:02:39 -0700 Subject: [PATCH 1/3] Post R5 Build 4 fixes - Added support for retry asset downloader --- overlay/opt/emcomm-tools/bin/et-common | 69 +++++++++++++++++++++++++- scripts/install-et-api.sh | 15 ++++-- 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/overlay/opt/emcomm-tools/bin/et-common b/overlay/opt/emcomm-tools/bin/et-common index bf45cf8..bc781dd 100755 --- a/overlay/opt/emcomm-tools/bin/et-common +++ b/overlay/opt/emcomm-tools/bin/et-common @@ -1,7 +1,7 @@ #!/bin/bash # Author : Gaston Gonzalez # Date : 1 February 2025 -# Updated : 7 June 2025 +# Updated : 20 August 2025 # Purpose : Common environment variables and functions # Standardized device paths for supported hardware @@ -74,3 +74,70 @@ start_and_wait_for_service() { exit_on_service_failure ${systemd_unit_name} } + +# download_with_retries downloads a file from a URL with retry and checksum support. +# +# This function attempts to download a file up to a maximum number of retries. +# If a checksum is provided, the downloaded file will be verified against it. +# On checksum mismatch, the file is deleted and the download retried. +# +# Args: +# url: The URL of the file to download. (required) +# filename: The local filename to save the file as. (required) +# checksum: Optional sha256 checksum string to validate the downloaded file. +# max_retries: Optional max number of retries (default: 3). +# wait_seconds: Optional wait time in seconds between retries (default: 2). +# +# Returns: +# 0 if the file was successfully downloaded (and checksum verified if given). +# 1 if arguments are missing, download fails after all retries, +# or checksum verification fails. +# +# Example: +# download_with_retries "https://example.com/file.tar.gz" "file.tar.gz" +# download_with_retries "https://example.com/file.tar.gz" "file.tar.gz" "abc123..." 5 3 +download_with_retries() { + local url="$1" + local filename="$2" + local checksum="$3" # expected checksum (sha256) + local max_retries="${4:-3}" # default = 3 retries + local wait_seconds="${5:-2}" # default = 2s wait between retries + + # Require at least URL and filename + if [[ -z "$url" || -z "$filename" ]]; then + echo "Usage: download_with_retries [checksum] [max_retries] [wait_seconds]" + return 1 + fi + + for ((i=1; i<=max_retries; i++)); do + echo "Attempt $i of $max_retries to download $url..." + + if curl -L -f -o "$filename" "$url"; then + echo "Download successful: $filename" + + if [[ -n "$checksum" ]]; then + echo "Verifying checksum..." + local file_checksum + file_checksum=$(sha256sum "$filename" | awk '{print $1}') + + if [[ "$file_checksum" == "$checksum" ]]; then + echo "Checksum OK" + return 0 + else + echo "Checksum mismatch (expected $checksum, got $file_checksum)" + rm -f "$filename" + fi + else + # no checksum provided, just succeed + return 0 + fi + else + echo "Download failed (attempt $i)." + fi + + sleep "$wait_seconds" + done + + echo "Download failed after $max_retries attempts." + return 1 +} diff --git a/scripts/install-et-api.sh b/scripts/install-et-api.sh index 29d517d..5ea12fb 100755 --- a/scripts/install-et-api.sh +++ b/scripts/install-et-api.sh @@ -7,6 +7,7 @@ trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG trap 'et-log "\"${last_command}\" command failed with exit code $?."' ERR . ./env.sh +. ../overlay/opt/emcomm-tools/bin/et-common APP=et-api VERSION=1.0.0 @@ -24,17 +25,23 @@ mkdir -v -p "${BIN_DIR}" "${DATA_DIR}" "${INDEX_DIR}" # Download and install et-api uber JAR URL="${BASE_URL}/${ET_API_JAR}" -et-log "Downloading ${APP}: ${URL}" -curl -s -L -o "${BIN_DIR}/${APP}" --fail ${URL} +download_with_retries ${URL} ${APP} +mv ${APP} ${BIN_DIR} chmod 755 "${BIN_DIR}/${APP}" # Download pre-built data sets -FILES=("faa.csv" "license.csv" "zip2geo.csv" "zip2geo-elevation.csv") +FILES=( + "faa.csv" + "license.csv" + "zip2geo.csv" + "zip2geo-elevation.csv" +) for file in "${FILES[@]}"; do URL="${BASE_URL}/${file}" et-log "Downloading data set: ${URL}" - curl -s -L -o "${DATA_DIR}/${file}" --fail ${URL} + download_with_retries ${URL} ${file} + mv ${file} ${DATA_DIR} done et-log "Applying permissions..." From e3edc70be0303bbd4ed415442a34e430b1d5a4b1 Mon Sep 17 00:00:00 2001 From: thetechprepper Date: Wed, 20 Aug 2025 20:09:53 -0700 Subject: [PATCH 2/3] Post R5 Build 4 fixes - Added download retry to et-aircraft-app --- scripts/install-et-aircraft.sh | 6 +++--- scripts/install-et-api.sh | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/install-et-aircraft.sh b/scripts/install-et-aircraft.sh index 806bd1b..7b7531d 100755 --- a/scripts/install-et-aircraft.sh +++ b/scripts/install-et-aircraft.sh @@ -1,12 +1,14 @@ #!/bin/bash # Author : Gaston Gonzalez # Date : 9 July 2025 +# Updated : 20 August 2025 # Purpose : Install et-aircraft-app set -e trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG trap 'et-log "\"${last_command}\" command failed with exit code $?."' ERR . ./env.sh +. ../overlay/opt/emcomm-tools/bin/et-common APP=et-aircraft-app VERSION=1.0.0 @@ -18,9 +20,7 @@ if [[ ! -e ${ET_DIST_DIR}/${DOWNLOAD_FILE} ]]; then URL="https://github.com/thetechprepper/et-aircraft-app/releases/download/${VERSION}/${DOWNLOAD_FILE}" - et-log "Downloading ${APP}: ${URL}" - curl -s -L -o ${DOWNLOAD_FILE} --fail ${URL} - + download_with_retries ${URL} ${DOWNLOAD_FILE} mv ${DOWNLOAD_FILE} ${ET_DIST_DIR} fi diff --git a/scripts/install-et-api.sh b/scripts/install-et-api.sh index 5ea12fb..4829230 100755 --- a/scripts/install-et-api.sh +++ b/scripts/install-et-api.sh @@ -1,6 +1,7 @@ #!/bin/bash # Author : Gaston Gonzalez # Date : 13 August 2025 +# Updated : 20 August 2025 # Purpose : Install EmComm Tools API set -e trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG From b7a57f408ab158a62a91a3a2b528a78869e006f3 Mon Sep 17 00:00:00 2001 From: thetechprepper Date: Wed, 20 Aug 2025 20:29:09 -0700 Subject: [PATCH 3/3] Post R5 Build 4 fixes - Added a more robust test case for the et-api installation as an experiment. --- tests/test-et-api.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tests/test-et-api.sh b/tests/test-et-api.sh index 919264a..b6d9bee 100755 --- a/tests/test-et-api.sh +++ b/tests/test-et-api.sh @@ -1,7 +1,23 @@ #!/bin/bash -# Author : Gaston Gonzalez -# Date : 13 August 2025 -# Purpose : Test et-api installation +# Author : Gaston Gonzalez +# Date : 13 August 2025 +# Updated : 20 August 2025 +# Purpose : Test et-api installation + +FILES=( + "faa.csv" + "license.csv" + "zip2geo.csv" + "zip2geo-elevation.csv" +) + +for file in "${FILES[@]}"; do + OUT=$(ls /opt/emcomm-tools-api/data/${file} 2>/dev/null) + if [[ $? -ne 0 ]]; then + echo -e "\t* Required file '$file' does not exist." + exit 1 + fi +done OUT=$(ls /opt/emcomm-tools-api/bin/et-api 2>/dev/null) exit $?