recovery-initramfs: improve initramfs retry implementation

This commit improves and simplifies the retry
implementation.

Signed-off-by: Mike Engel <Mike.Engel@digi.com>
This commit is contained in:
Mike Engel 2026-01-23 10:07:58 +01:00
parent 190df56f4e
commit 0bb84fec8b
1 changed files with 10 additions and 16 deletions

View File

@ -3,7 +3,7 @@
#
# recovery-initramfs-init
#
# Copyright (C) 2016, 2017 by Digi International Inc.
# Copyright (C) 2016, 2026 by Digi International Inc.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
@ -364,29 +364,23 @@ swu_package_path() {
# Check whether the package is local and get the absolute path.
if echo "${1}" | grep -qs '^file://'; then
local pkg_name="$(basename ${1})"
local success=false
local retries=1
local max_retries=10
local MAX_RETRIES="10"
while [ $success = false ] && [ $retries -le $max_retries ]; do
for _ in $(seq ${MAX_RETRIES}); do
for i in ${UPDATE_MOUNT_DIR} $(echo ${USB_MOUNT_DIR}/*); do
echo $i | grep -qs "${USB_MOUNT_DIR}/\*" && continue
if [ -f "${i}/${pkg_name}" ]; then
swu_abspath="${i}/${pkg_name}"
break
break 2
fi
done
if [ -n "${swu_abspath}" ]; then
echo "${swu_abspath}"
success=true
else
sleep 1
retries=$(( retries + 1 ))
fi
sleep 1
done
if [ -z "${swu_abspath}" ]; then
quit_with_error "Unable to find update package '${pkg_name}' after ${max_retries} retries"
if [ -n "${swu_abspath}" ]; then
echo "${swu_abspath}"
else
quit_with_error "Unable to find update package '${pkg_name}' after ${MAX_RETRIES} retries"
fi
else
echo "${1}"