From 387ddc76781b025445d50968a720cd82c85359c7 Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Thu, 26 Sep 2024 21:49:02 +0200 Subject: [PATCH] Bugfix: firmware switch function was not working correctly --- lib/armbian-configng/config.ng.functions.sh | 33 ++++++++++++++------- lib/armbian-configng/config.ng.system.sh | 5 +++- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/armbian-configng/config.ng.functions.sh b/lib/armbian-configng/config.ng.functions.sh index 4b82589d..b083e3b8 100644 --- a/lib/armbian-configng/config.ng.functions.sh +++ b/lib/armbian-configng/config.ng.functions.sh @@ -257,15 +257,16 @@ armbian_fw_manipulate() { [[ -n $version ]] && local version="=${version}" # fallback to $BRANCH - [[ -z $branch ]] && branch="${BRANCH}" + [[ -z "${branch}" ]] && branch="${BRANCH}" + [[ -z "${branch}" ]] && branch="current" # fallback in case we switch to very old BSP that have no such info # packages to install local armbian_packages=( "linux-u-boot-${BOARD}-${branch}" "linux-image-${branch}-${LINUXFAMILY}" "linux-dtb-${branch}-${LINUXFAMILY}" - "armbian-config" "armbian-zsh" + "armbian-bsp-cli-${BOARD}-${branch}" ) # reinstall headers only if they were previously installed @@ -276,26 +277,36 @@ armbian_fw_manipulate() { local packages="" for pkg in "${armbian_packages[@]}"; do if [[ "${function}" == reinstall ]]; then - apt search "$pkg" 2> /dev/null | grep "^$pkg" > /dev/null - if [[ $? -eq 0 ]]; then packages+="$pkg${version} "; fi + local pkg_search=$(apt search "$pkg" 2> /dev/null | grep "^$pkg") + if [[ $? -eq 0 && -n "${pkg_search}" ]]; then + if [[ "${pkg_search}" == *$version* ]] ; then + packages+="$pkg${version} "; + else + packages+="$pkg "; + fi + fi else if check_if_installed $pkg; then packages+="$pkg${version} " fi fi done - for pkg in "${packages[@]}"; do - local pkg_uninstall=${pkg/=*/} # removing numbers case $function in unhold) apt-mark unhold ${pkg} | show_infobox ;; hold) apt-mark hold ${pkg} | show_infobox ;; reinstall) - apt_install_wrapper apt-get -y --download-only --allow-change-held-packages --allow-downgrades install "${pkg}" - apt_install_wrapper apt-get -y purge "${pkg_uninstall/${branch}/*}" # remove all branches - apt_install_wrapper apt-get -y --allow-change-held-packages --allow-downgrades install "${pkg}" - apt_install_wrapper apt-get -y autoremove - apt_install_wrapper apt-get -y clean + apt_install_wrapper apt-get -y --simulate --download-only --allow-change-held-packages --allow-downgrades install ${pkg} + if [[ $? == 0 ]]; then + apt_install_wrapper apt-get -y purge "linux-u-boot-*" "linux-image-*" "linux-dtb-*" "linux-headers-*" "armbian-zsh-*" "armbian-bsp-cli-*" # remove all branches + apt_install_wrapper apt-get -y --allow-change-held-packages install ${pkg} + apt_install_wrapper apt-get -y autoremove + apt_install_wrapper apt-get -y clean + else + exit 1 + fi + + ;; *) return ;; esac diff --git a/lib/armbian-configng/config.ng.system.sh b/lib/armbian-configng/config.ng.system.sh index 4fffcc4f..66be03a1 100644 --- a/lib/armbian-configng/config.ng.system.sh +++ b/lib/armbian-configng/config.ng.system.sh @@ -12,11 +12,12 @@ module_options+=( # @description Use TUI / GUI for apt install if exists # function apt_install_wrapper() { + if [ -t 0 ]; then debconf-apt-progress -- "$@" else # Terminal not defined - proceed without TUI - "$@" + DEBIAN_FRONTEND=noninteractive "$@" fi } @@ -145,6 +146,7 @@ function set_stable() { if ! grep -q 'apt.armbian.com' /etc/apt/sources.list.d/armbian.list; then sed -i "s/http:\/\/[^ ]*/http:\/\/apt.armbian.com/" /etc/apt/sources.list.d/armbian.list + apt_install_wrapper apt-get update armbian_fw_manipulate "reinstall" fi } @@ -164,6 +166,7 @@ function set_rolling() { if ! grep -q 'beta.armbian.com' /etc/apt/sources.list.d/armbian.list; then sed -i "s/http:\/\/[^ ]*/http:\/\/beta.armbian.com/" /etc/apt/sources.list.d/armbian.list + apt_install_wrapper apt-get update armbian_fw_manipulate "reinstall" fi }