From b83338e0e1f3d2c151ae0938c5a3d238a4b1f28a Mon Sep 17 00:00:00 2001 From: Igor Date: Thu, 5 Sep 2024 15:22:01 +0200 Subject: [PATCH] Change set_safe_boot with improved function armbian_fw_manipulate (#57) * Change set_safe_boot with improved function armbian_fw_manipulate It extends functionality to reload packages too * fix: shift to accomidate option arguments 2nd option to --api * fixed extra if stament. * Improve reloading armbian packages --------- Co-authored-by: Tearran --- README.md | 6 +- bin/armbian-configng | 9 ++- lib/armbian-configng/config.ng.functions.sh | 72 ++++++++++++++------- lib/armbian-configng/config.ng.jobs.json | 9 ++- lib/armbian-configng/config.ng.system.sh | 2 + 5 files changed, 66 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index de0b4cc7c..c6c2c4ef0 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ Enable Armbian kernel upgrades Jobs: ~~~ -set_safe_boot unhold +armbian_fw_manipulate unhold ~~~ ### S02 @@ -169,7 +169,7 @@ Disable Armbian kernel upgrades Jobs: ~~~ -set_safe_boot freeze +armbian_fw_manipulate freeze ~~~ ### S03 @@ -510,7 +510,7 @@ These helper functions facilitate various operations related to job management, | Display a message box | show_message <<< 'hello world' | Joey Turner | Migrated procedures from Armbian config. | connect_bt_interface | Igor Pecovnik | Show or generate QR code for Google OTP | qr_code generate | Igor Pecovnik -| Freeze/unhold Migrated procedures from Armbian config. | set_safe_boot unhold or set_safe_boot freeze | Igor Pecovnik +| Freeze/unhold Migrated procedures from Armbian config. | armbian_fw_manipulate unhold or armbian_fw_manipulate freeze or armbian_fw_manipulate reinstall | Igor Pecovnik | Check if kernel headers are installed | are_headers_installed | Gunjan Gupta | Check when apt list was last updated | see_current_apt | Joey Turner | Migrated procedures from Armbian config. | check_if_installed nano | Igor Pecovnik diff --git a/bin/armbian-configng b/bin/armbian-configng index e2a442cfe..e291bc7a0 100755 --- a/bin/armbian-configng +++ b/bin/armbian-configng @@ -87,8 +87,15 @@ case "$1" in exit 1 fi shift + if [[ -z "$1" ]]; then + echo "Error: Missing option for --api." + exit 1 + fi + option="$1" + shift args=$(sanitize_input "$@") - "$args" + # echo -e "\"$option\" \"$args\"" + "$option" "$args" exit 0 ;; "main=help" | "main=Help") diff --git a/lib/armbian-configng/config.ng.functions.sh b/lib/armbian-configng/config.ng.functions.sh index 67ec9498b..330290bc5 100644 --- a/lib/armbian-configng/config.ng.functions.sh +++ b/lib/armbian-configng/config.ng.functions.sh @@ -248,35 +248,61 @@ function set_runtime_variables(){ module_options+=( -["set_safe_boot,author"]="Igor Pecovnik" -["set_safe_boot,ref_link"]="" -["set_safe_boot,feature"]="set_safe_boot" -["set_safe_boot,desc"]="Freeze/unhold Migrated procedures from Armbian config." -["set_safe_boot,example"]="set_safe_boot unhold or set_safe_boot freeze" -["set_safe_boot,status"]="Active" +["armbian_fw_manipulate,author"]="Igor Pecovnik" +["armbian_fw_manipulate,ref_link"]="" +["armbian_fw_manipulate,feature"]="armbian_fw_manipulate" +["armbian_fw_manipulate,desc"]="freeze/unhold/reinstall armbian related packages." +["armbian_fw_manipulate,example"]="armbian_fw_manipulate unhold|freeze|reinstall" +["armbian_fw_manipulate,status"]="Active" ) # -# freeze/unhold packages +# freeze/unhold/reinstall armbian firmware packages # -set_safe_boot() { +armbian_fw_manipulate() { - check_if_installed linux-u-boot-${BOARD}-${BRANCH} && PACKAGE_LIST+=" linux-u-boot-${BOARD}-${BRANCH}" - check_if_installed linux-image-${BRANCH}-${LINUXFAMILY} && PACKAGE_LIST+=" linux-image-${BRANCH}-${LINUXFAMILY}" - check_if_installed linux-dtb-${BRANCH}-${LINUXFAMILY} && PACKAGE_LIST+=" linux-dtb-${BRANCH}-${LINUXFAMILY}" - check_if_installed linux-headers-${BRANCH}-${LINUXFAMILY} && PACKAGE_LIST+=" linux-headers-${BRANCH}-${LINUXFAMILY}" + function=$1 - # new BSP - check_if_installed armbian-${LINUXFAMILY} && PACKAGE_LIST+=" armbian-${LINUXFAMILY}" - check_if_installed armbian-${BOARD} && PACKAGE_LIST+=" armbian-${BOARD}" - check_if_installed armbian-${DISTROID} && PACKAGE_LIST+=" armbian-${DISTROID}" - check_if_installed armbian-bsp-cli-${BOARD} && PACKAGE_LIST+=" armbian-bsp-cli-${BOARD}" - check_if_installed armbian-${DISTROID}-desktop-xfce && PACKAGE_LIST+=" armbian-${DISTROID}-desktop-xfce" - check_if_installed armbian-firmware && PACKAGE_LIST+=" armbian-firmware" - check_if_installed armbian-firmware-full && PACKAGE_LIST+=" armbian-firmware-full" - IFS=" " - [[ "$1" == "unhold" ]] && local command="apt-mark unhold" && for word in $PACKAGE_LIST; do $command $word; done | show_infobox + # fallback to current + [[ -z $BRANCH ]] && BRANCH="current" - [[ "$1" == "freeze" ]] && local command="apt-mark hold" && for word in $PACKAGE_LIST; do $command $word; done | show_infobox + ARMBIAN_PACKAGES=( + "linux-u-boot-${BOARD}-${BRANCH}" + "linux-image-${BRANCH}-${LINUXFAMILY}" + "linux-dtb-${BRANCH}-${LINUXFAMILY}" + "linux-headers-${BRANCH}-${LINUXFAMILY}" + "armbian-config" + "armbian-zsh" + "armbian-bsp-cli-${BOARD}-${BRANCH}" + ) + + if [[ "${function}" == reinstall ]]; then + debconf-apt-progress -- apt-get update + fi + + PACKAGES="" + for PACKAGE in "${ARMBIAN_PACKAGES[@]}" + do + if [[ "${function}" == reinstall ]]; then + apt search $PACKAGE 2>/dev/null | grep "^$PACKAGE" >/dev/null + if [[ $? -eq 0 ]]; then PACKAGES+="$PACKAGE "; fi + else + if check_if_installed $PACKAGE; then + PACKAGES+="$PACKAGE " + fi + fi + done + + case $function in + unhold) apt-mark unhold ${PACKAGES} | show_infobox ;; + hold) apt-mark hold ${PACKAGES} | show_infobox ;; + reinstall) + debconf-apt-progress -- apt-get -y --download-only install ${PACKAGES} + debconf-apt-progress -- apt-get -y purge ${PACKAGES} + debconf-apt-progress -- apt-get -y install ${PACKAGES} + debconf-apt-progress -- apt-get -y autoremove + ;; + *) return ;; + esac } diff --git a/lib/armbian-configng/config.ng.jobs.json b/lib/armbian-configng/config.ng.jobs.json index 251dab077..dbf083a35 100644 --- a/lib/armbian-configng/config.ng.jobs.json +++ b/lib/armbian-configng/config.ng.jobs.json @@ -8,7 +8,7 @@ "id": "S01", "description": "Enable Armbian kernel upgrades", "command": [ - "set_safe_boot unhold" + "armbian_fw_manipulate unhold" ], "status": "Active", "doc_link": "", @@ -20,7 +20,7 @@ "id": "S02", "description": "Disable Armbian kernel upgrades", "command": [ - "set_safe_boot freeze" + "armbian_fw_manipulate hold" ], "status": "Active", "doc_link": "", @@ -215,7 +215,6 @@ } ] }, - { "id": "S08", "description": "Change shell system wide to BASH", @@ -261,7 +260,7 @@ "doc_link": "", "src_reference": "https://github.com/armbian/config/blob/master/debian-config-jobs#L1446", "author": "Igor Pecovnik", - "condition": "grep -q 'apt.armbian.com' /etc/apt/sources.list.d/armbian.list" + "condition": "grep -q 'apt.armbian.com' /etc/apt/sources.list.d/armbian.list && [[ -z \"$(apt-mark showhold)\" ]]" }, { "id": "S11", @@ -274,7 +273,7 @@ "doc_link": "", "src_reference": "https://github.com/armbian/config/blob/master/debian-config-jobs#L1446", "author": "Igor Pecovnik", - "condition": "grep -q 'beta.armbian.com' /etc/apt/sources.list.d/armbian.list" + "condition": "grep -q 'beta.armbian.com' /etc/apt/sources.list.d/armbian.list && [[ -z \"$(apt-mark showhold)\" ]]" } ] diff --git a/lib/armbian-configng/config.ng.system.sh b/lib/armbian-configng/config.ng.system.sh index f5c0e2591..f24a8e17c 100644 --- a/lib/armbian-configng/config.ng.system.sh +++ b/lib/armbian-configng/config.ng.system.sh @@ -69,6 +69,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 + armbian_fw_manipulate "reinstall" fi } @@ -87,5 +88,6 @@ 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 + armbian_fw_manipulate "reinstall" fi } \ No newline at end of file