From c19acb1694e6957b0d4a8e5852c8db134a2bf6bd Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 4 Jun 2023 19:12:53 +0200 Subject: [PATCH 1/8] fix(mainsail/fluidd): fall back to latest stable url if fetching tags fails (#348) --- scripts/fluidd.sh | 33 +++++++++++++++++---------------- scripts/mainsail.sh | 33 +++++++++++++++++---------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 42fda1d..345a1c4 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -341,27 +341,28 @@ function compare_fluidd_versions() { #================================================# function get_fluidd_download_url() { - local fl_tags tags latest_tag latest_url stable_tag stable_url url + local releases_by_tag tags tag unstable_url url - fl_tags="https://api.github.com/repos/fluidd-core/fluidd/tags" - tags=$(curl -s "${fl_tags}" | grep "name" | cut -d'"' -f4) - - ### latest download url including pre-releases (alpha, beta, rc) - latest_tag=$(echo "${tags}" | head -1) - latest_url="https://github.com/fluidd-core/fluidd/releases/download/${latest_tag}/fluidd.zip" - - ### get stable fluidd download url - stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1) - stable_url="https://github.com/fluidd-core/fluidd/releases/download/${stable_tag}/fluidd.zip" + ### latest stable download url + url="https://github.com/fluidd-core/fluidd/releases/latest/download/fluidd.zip" read_kiauh_ini "${FUNCNAME[0]}" if [[ ${fluidd_install_unstable} == "true" ]]; then - url="${latest_url}" - echo "${url}" - else - url="${stable_url}" - echo "${url}" + releases_by_tag="https://api.github.com/repos/fluidd-core/fluidd/tags" + tags=$(curl -s "${releases_by_tag}" | grep "name" | cut -d'"' -f4) + tag=$(echo "${tags}" | head -1) + + ### latest unstable download url including pre-releases (alpha, beta, rc) + unstable_url="https://github.com/fluidd-core/fluidd/releases/download/${tag}/fluidd.zip" + + if [[ ${unstable_url} == *"download//"* ]]; then + warn_msg "Download URL broken! Falling back to URL of latest stable release!" + else + url=${unstable_url} + fi fi + + echo "${url}" } function fluidd_port_check() { diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 0cdedfd..67fef87 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -511,27 +511,28 @@ function ms_theme_delete() { #================================================# function get_mainsail_download_url() { - local ms_tags tags latest_tag latest_url stable_tag stable_url url + local releases_by_tag tags tag unstable_url url - ms_tags="https://api.github.com/repos/mainsail-crew/mainsail/tags" - tags=$(curl -s "${ms_tags}" | grep "name" | cut -d'"' -f4) - - ### latest download url including pre-releases (alpha, beta, rc) - latest_tag=$(echo "${tags}" | head -1) - latest_url="https://github.com/mainsail-crew/mainsail/releases/download/${latest_tag}/mainsail.zip" - - ### get stable mainsail download url - stable_tag=$(echo "${tags}" | grep -E "^v([0-9]+\.?){3}$" | head -1) - stable_url="https://github.com/mainsail-crew/mainsail/releases/download/${stable_tag}/mainsail.zip" + ### latest stable download url + url="https://github.com/mainsail-crew/mainsail/releases/latest/download/mainsail.zip" read_kiauh_ini "${FUNCNAME[0]}" if [[ ${mainsail_install_unstable} == "true" ]]; then - url="${latest_url}" - echo "${url}" - else - url="${stable_url}" - echo "${url}" + releases_by_tag="https://api.github.com/repos/mainsail-crew/mainsail/tags" + tags=$(curl -s "${releases_by_tag}" | grep "name" | cut -d'"' -f4) + tag=$(echo "${tags}" | head -1) + + ### latest unstable download url including pre-releases (alpha, beta, rc) + unstable_url="https://github.com/mainsail-crew/mainsail/releases/download/${tag}/mainsail.zip" + + if [[ ${unstable_url} == *"download//"* ]]; then + warn_msg "Download URL broken! Falling back to URL of latest stable release!" + else + url=${unstable_url} + fi fi + + echo "${url}" } function mainsail_port_check() { From 477f3ca72cd2b05c8b2ffaf085a07f9d66e13f1c Mon Sep 17 00:00:00 2001 From: CODeRUS Date: Sun, 4 Jun 2023 21:23:32 +0200 Subject: [PATCH 2/8] feat: flash DFU device in HID mode (#337) Co-authored-by: th33xitus --- scripts/flash_klipper.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/flash_klipper.sh b/scripts/flash_klipper.sh index 8ea0ab8..c281214 100644 --- a/scripts/flash_klipper.sh +++ b/scripts/flash_klipper.sh @@ -70,6 +70,7 @@ function select_mcu_connection() { echo -e "| How is the controller board connected to the host? |" echo -e "| 1) USB |" echo -e "| 2) UART |" + echo -e "| 3) USB (DFU mode) |" blank_line back_help_footer @@ -85,6 +86,10 @@ function select_mcu_connection() { status_msg "Identifying MCU possibly connected via UART ...\n" get_uart_id || true # continue even after exit code 1 break;; + 3) + status_msg "Identifying MCU connected via USB in DFU mode ...\n" + get_dfu_id || true # continue even after exit code 1 + break;; B|b) advanced_menu break;; @@ -329,6 +334,16 @@ function get_uart_id() { done } +function get_dfu_id() { + unset mcu_list + sleep 1 + mcus=$(lsusb | grep "DFU" | cut -d " " -f 6 2>/dev/null) + + for mcu in ${mcus}; do + mcu_list+=("${mcu}") + done +} + function show_flash_method_help() { top_border echo -e "| ~~~~~~~~ < ? > Help: Flash MCU < ? > ~~~~~~~~ |" @@ -406,4 +421,4 @@ function show_mcu_connection_help() { error_msg "Invalid command!";; esac done -} \ No newline at end of file +} From bcbb185bd79afd8f81971253b2702ab4b703710a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sun, 4 Jun 2023 21:57:56 +0200 Subject: [PATCH 3/8] readme: update README.md also fixes #327 --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d662268..e75d00c 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ distributions based on Debian 11 Bullseye. Read the notes further down below in * **Step 1:** \ To download this script, it is necessary to have git installed. If you don't have git already installed, or if you are unsure, run the following command: ```shell -sudo apt-get install git -y +sudo apt-get update && sudo apt-get install git -y ``` * **Step 2:** \ @@ -178,3 +178,12 @@ prompt and confirm by hitting ENTER. * A big thank you to [lixxbox](https://github.com/lixxbox) for that awesome KIAUH-Logo! * Also, a big thank you to everyone who supported my work with a [Ko-fi](https://ko-fi.com/th33xitus) ! * Last but not least: Thank you to all contributors and members of the Klipper Community who like and share this project! + +
+ +

A special thank you to JetBrains for sponsoring this project with their incredible software!

+

+ + JetBrains Logo (Main) logo. + +

From 0cd058320fcbb9a9eeff7f9cea6a0a038e443fe6 Mon Sep 17 00:00:00 2001 From: marbocub Date: Wed, 7 Jun 2023 04:09:47 +0900 Subject: [PATCH 4/8] feat: allow to install Mainsail/Fluidd without Moonraker (#347) Co-authored-by: th33xitus --- scripts/fluidd.sh | 22 ++++++++++++++++++---- scripts/mainsail.sh | 26 +++++++++++++++++++++----- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 345a1c4..5b3407c 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -16,10 +16,24 @@ set -e #===================================================# function install_fluidd() { - ### exit early if moonraker not found if [[ -z $(moonraker_systemd) ]]; then - local error="Moonraker not installed! Please install Moonraker first!" - print_error "${error}" && return + local error="Moonraker not installed! It's recommended to install Moonraker first!" + print_error "${error}" + while true; do + local yn + read -p "${cyan}###### Proceed to install Fluidd without installing Moonraker? (y/N):${white} " yn + case "${yn}" in + Y|y|Yes|yes) + select_msg "Yes" + break;; + N|n|No|no|"") + select_msg "No" + abort_msg "Exiting Fluidd setup ...\n" + return;; + *) + error_msg "Invalid Input!";; + esac + done fi ### checking dependencies @@ -30,7 +44,7 @@ function install_fluidd() { status_msg "Initializing Fluidd installation ..." ### first, we create a backup of the full klipper_config dir - safety first! - backup_klipper_config_dir + #backup_klipper_config_dir ### check for other enabled web interfaces unset SET_LISTEN_PORT diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 67fef87..da220f7 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -16,10 +16,24 @@ set -e #===================================================# function install_mainsail() { - ### exit early if moonraker not found if [[ -z $(moonraker_systemd) ]]; then - local error="Moonraker not installed! Please install Moonraker first!" - print_error "${error}" && return + local error="Moonraker not installed! It's recommended to install Moonraker first!" + print_error "${error}" + while true; do + local yn + read -p "${cyan}###### Proceed to install Mainsail without installing Moonraker? (y/N):${white} " yn + case "${yn}" in + Y|y|Yes|yes) + select_msg "Yes" + break;; + N|n|No|no|"") + select_msg "No" + abort_msg "Exiting Mainsail setup ...\n" + return;; + *) + error_msg "Invalid Input!";; + esac + done fi ### checking dependencies @@ -157,6 +171,7 @@ function download_mainsail_macros() { } function download_mainsail() { + local services local url url=$(get_mainsail_download_url) @@ -179,8 +194,9 @@ function download_mainsail() { exit 1 fi - ### check for moonraker multi-instance and if multi-instance was found, enable mainsails remoteMode - if [[ $(moonraker_systemd | wc -w) -gt 1 ]]; then + ### check for moonraker multi-instance and if no-instance or multi-instance was found, enable mainsails remoteMode + services=$(moonraker_systemd) + if [[ ( -z "${services}" ) || ( $(echo "${services}" | wc -w) -gt 1 ) ]]; then enable_mainsail_remotemode fi } From 7df3dd489fff51a5ac783ce2a6b570633ccd210a Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 7 Jun 2023 21:48:17 +0200 Subject: [PATCH 5/8] fix(mainsail/fluidd): show correct version number in update menu fixes #350 Signed-off-by: Dominik Willner --- scripts/fluidd.sh | 6 +++--- scripts/mainsail.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 5b3407c..c6f7ecd 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -327,9 +327,9 @@ function get_local_fluidd_version() { function get_remote_fluidd_version() { [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return - local version - version=$(get_fluidd_download_url | rev | cut -d"/" -f2 | rev) - echo "${version}" + local tags + tags=$(curl -s "https://api.github.com/repos/fluidd-core/fluidd/tags" | grep "name" | cut -d'"' -f4) + echo "${tags}" | head -1 } function compare_fluidd_versions() { diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index da220f7..7b052d5 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -334,9 +334,9 @@ function get_local_mainsail_version() { function get_remote_mainsail_version() { [[ ! $(dpkg-query -f'${Status}' --show curl 2>/dev/null) = *\ installed ]] && return - local version - version=$(get_mainsail_download_url | rev | cut -d"/" -f2 | rev) - echo "${version}" + local tags + tags=$(curl -s "https://api.github.com/repos/mainsail-crew/mainsail/tags" | grep "name" | cut -d'"' -f4) + echo "${tags}" | head -1 } function compare_mainsail_versions() { From 5d7debd65ed9cbe2dc1d56ecdba974bf6b29662e Mon Sep 17 00:00:00 2001 From: Kyriel Abad Date: Sun, 11 Jun 2023 05:00:23 +0800 Subject: [PATCH 6/8] readme: fix typos in README.md (#352) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e75d00c..2cabb75 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ that you have a functional Linux system on hand. `Raspberry Pi OS Lite (32bit)` if you are using a Raspberry Pi. The [official Raspberry Pi Imager](https://www.raspberrypi.com/software/) is the simplest way to flash an image like this to an SD card. -* Once you downloaded, installed and launched the Raspberry Pi Imager +* Once you have downloaded, installed and launched the Raspberry Pi Imager, select `Choose OS -> Raspberry Pi OS (other)`: \

KIAUH logo @@ -47,7 +47,7 @@ select `Choose OS -> Raspberry Pi OS (other)`: \ * Back in the Raspberry Pi Imager's main menu, select the corresponding SD card to which you want to flash the image. -* Make sure to go into the Advaced Option (the cog icon in the lower left corner of the main menu) +* Make sure to go into the Advanced Option (the cog icon in the lower left corner of the main menu) and enable SSH and configure Wi-Fi. * If you need more help for using the Raspberry Pi Imager, please visit the [official documentation](https://www.raspberrypi.com/documentation/computers/getting-started.html). @@ -68,14 +68,14 @@ sudo apt-get update && sudo apt-get install git -y ``` * **Step 2:** \ -Once git is installed, use the following command to download KIAUH into your home-directoy: +Once git is installed, use the following command to download KIAUH into your home-directory: ```shell cd ~ && git clone https://github.com/th33xitus/kiauh.git ``` * **Step 3:** \ -Finally start KIAUH by running the next command: +Finally, start KIAUH by running the next command: ```shell ./kiauh/kiauh.sh From 8eb2924832658a970373a906ef67afc3e6a2f07e Mon Sep 17 00:00:00 2001 From: cravl-dev Date: Sat, 17 Jun 2023 12:08:24 -0400 Subject: [PATCH 7/8] refactor: update package lists only when stale (#346) Co-authored-by: th33xitus --- .gitignore | 4 +- scripts/crowsnest.sh | 18 ++---- scripts/klipper.sh | 20 ++----- scripts/moonraker-telegram-bot.sh | 18 ++---- scripts/moonraker.sh | 18 ++---- scripts/octoeverywhere.sh | 18 ++---- scripts/ui/install_menu.sh | 3 +- scripts/ui/update_menu.sh | 5 +- scripts/utilities.sh | 97 ++++++++++++++++++++++++------- 9 files changed, 104 insertions(+), 97 deletions(-) diff --git a/.gitignore b/.gitignore index 7084f49..560b8c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -klipper_repos.txt \ No newline at end of file +.vscode +*.code-workspace +klipper_repos.txt diff --git a/scripts/crowsnest.sh b/scripts/crowsnest.sh index cda3820..fb864ab 100644 --- a/scripts/crowsnest.sh +++ b/scripts/crowsnest.sh @@ -197,7 +197,7 @@ function compare_crowsnest_versions() { } function install_crowsnest_dependencies() { - local packages + local packages log_name="Crowsnest" local install_script="${CROWSNEST_DIR}/tools/install.sh" ### read PKGLIST from official install-script @@ -208,21 +208,11 @@ function install_crowsnest_dependencies() { echo "${cyan}${packages}${white}" | tr '[:space:]' '\n' read -r -a packages <<< "${packages}" - ### Update system package info - status_msg "Updating package lists..." - if ! sudo apt-get update --allow-releaseinfo-change; then - log_error "failure while updating package lists" - error_msg "Updating package lists failed!" - exit 1 - fi + ### Update system package lists if stale + update_system_package_lists ### Install required packages - status_msg "Installing required packages..." - if ! sudo apt-get install --yes "${packages[@]}"; then - log_error "failure while installing required crowsnest packages" - error_msg "Installing required packages failed!" - exit 1 - fi + install_system_packages "${log_name}" "packages[@]" } function update_crowsnest() { diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 66126b4..6ea8c28 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -295,7 +295,7 @@ function create_klipper_virtualenv() { # @param {string}: python_version - klipper-env python version # function install_klipper_packages() { - local packages python_version="${1}" + local packages log_name="Klipper" python_version="${1}" local install_script="${KLIPPER_DIR}/scripts/install-debian.sh" status_msg "Reading dependencies..." @@ -321,21 +321,11 @@ function install_klipper_packages() { echo "${cyan}${packages}${white}" | tr '[:space:]' '\n' read -r -a packages <<< "${packages}" - ### Update system package info - status_msg "Updating package lists..." - if ! sudo apt-get update --allow-releaseinfo-change; then - log_error "failure while updating package lists" - error_msg "Updating package lists failed!" - exit 1 - fi + ### Update system package lists if stale + update_system_package_lists ### Install required packages - status_msg "Installing required packages..." - if ! sudo apt-get install --yes "${packages[@]}"; then - log_error "failure while installing required klipper packages" - error_msg "Installing required packages failed!" - exit 1 - fi + install_system_packages "${log_name}" "packages[@]" } function create_klipper_service() { @@ -634,4 +624,4 @@ function get_klipper_python_ver() { local version version=$("${KLIPPY_ENV}"/bin/python --version 2>&1 | cut -d" " -f2 | cut -d"." -f1) echo "${version}" -} \ No newline at end of file +} diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index 7aab1e9..e88a93f 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -110,7 +110,7 @@ function telegram_bot_setup_dialog() { } function install_telegram_bot_dependencies() { - local packages + local packages log_name="Telegram Bot" local install_script="${TELEGRAM_BOT_DIR}/scripts/install.sh" ### read PKGLIST from official install-script @@ -121,21 +121,11 @@ function install_telegram_bot_dependencies() { echo "${cyan}${packages}${white}" | tr '[:space:]' '\n' read -r -a packages <<< "${packages}" - ### Update system package info - status_msg "Updating package lists..." - if ! sudo apt-get update --allow-releaseinfo-change; then - log_error "failure while updating package lists" - error_msg "Updating package lists failed!" - exit 1 - fi + ### Update system package lists if stale + update_system_package_lists ### Install required packages - status_msg "Installing required packages..." - if ! sudo apt-get install --yes "${packages[@]}"; then - log_error "failure while installing required moonraker-telegram-bot packages" - error_msg "Installing required packages failed!" - exit 1 - fi + install_system_packages "${log_name}" "packages[@]" } function create_telegram_bot_virtualenv() { diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 655e2d6..e971878 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -141,7 +141,7 @@ function moonraker_setup_dialog() { } function install_moonraker_dependencies() { - local packages + local packages log_name="Moonraker" local install_script="${MOONRAKER_DIR}/scripts/install-moonraker.sh" ### read PKGLIST from official install-script @@ -152,21 +152,11 @@ function install_moonraker_dependencies() { echo "${cyan}${packages}${white}" | tr '[:space:]' '\n' read -r -a packages <<< "${packages}" - ### Update system package info - status_msg "Updating package lists..." - if ! sudo apt-get update --allow-releaseinfo-change; then - log_error "failure while updating package lists" - error_msg "Updating package lists failed!" - exit 1 - fi + ### Update system package lists if stale + update_system_package_lists ### Install required packages - status_msg "Installing required packages..." - if ! sudo apt-get install --yes "${packages[@]}"; then - log_error "failure while installing required moonraker packages" - error_msg "Installing required packages failed!" - exit 1 - fi + install_system_packages "${log_name}" "packages[@]" } function create_moonraker_virtualenv() { diff --git a/scripts/octoeverywhere.sh b/scripts/octoeverywhere.sh index ff953ce..635c443 100644 --- a/scripts/octoeverywhere.sh +++ b/scripts/octoeverywhere.sh @@ -307,7 +307,7 @@ function clone_octoeverywhere() { } function install_octoeverywhere_dependencies() { - local packages + local packages log_name="OctoEverywhere" local install_script="${OCTOEVERYWHERE_DIR}/install.sh" ### read PKGLIST from official install-script @@ -318,21 +318,11 @@ function install_octoeverywhere_dependencies() { echo "${cyan}${packages}${white}" | tr '[:space:]' '\n' read -r -a packages <<< "${packages}" - ### Update system package info - status_msg "Updating package lists..." - if ! sudo apt-get update --allow-releaseinfo-change; then - log_error "failure while updating package lists" - error_msg "Updating package lists failed!" - exit 1 - fi + ### Update system package lists if stale + update_system_package_lists ### Install required packages - status_msg "Installing required packages..." - if ! sudo apt-get install --yes "${packages[@]}"; then - log_error "failure while installing required octoeverywhere packages" - error_msg "Installing required packages failed!" - exit 1 - fi + install_system_packages "${log_name}" "packages[@]" } #===================================================# diff --git a/scripts/ui/install_menu.sh b/scripts/ui/install_menu.sh index 2ebcc00..842c367 100755 --- a/scripts/ui/install_menu.sh +++ b/scripts/ui/install_menu.sh @@ -34,7 +34,8 @@ function install_ui() { } function install_menu() { - clear && print_header + clear -x && sudo -v && clear -x # (re)cache sudo credentials so password prompt doesn't bork ui + print_header install_ui ### save all installed webinterface ports to the ini file diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 61e61ee..169d9b3 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -11,7 +11,7 @@ set -e -function update_ui() { +function update_ui() { top_border echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${white} |" hr @@ -40,6 +40,7 @@ function update_ui() { } function update_menu() { + clear -x && sudo -v && clear -x # (re)cache sudo credentials so password prompt doesn't bork ui do_action "" "update_ui" local action @@ -69,7 +70,7 @@ function update_menu() { 10) do_action "update_crowsnest" "update_ui";; 11) - do_action "update_system" "update_ui";; + do_action "upgrade_system_packages" "update_ui";; a) do_action "update_all" "update_ui";; B|b) diff --git a/scripts/utilities.sh b/scripts/utilities.sh index b3293ff..91ab5ce 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -20,6 +20,8 @@ function check_euid() { echo -e "${red}" top_border echo -e "| !!! THIS SCRIPT MUST NOT RUN AS ROOT !!! |" + echo -e "| |" + echo -e "| It will ask for credentials as needed. |" bottom_border echo -e "${white}" exit 1 @@ -285,7 +287,7 @@ function python3_check() { function dependency_check() { local dep=( "${@}" ) - local packages + local packages log_name="dependencies" status_msg "Checking for the following dependencies:" #check if package is installed, if not write its name into array @@ -303,12 +305,12 @@ function dependency_check() { done echo - if sudo apt-get update --allow-releaseinfo-change && sudo apt-get install "${packages[@]}" -y; then - ok_msg "Dependencies installed!" - else - error_msg "Installing dependencies failed!" - return 1 # exit kiauh - fi + # update system package lists if stale + update_system_package_lists + + # install required packages + install_system_packages "${log_name}" "packages[@]" + else ok_msg "Dependencies already met!" return @@ -358,27 +360,78 @@ function create_required_folders() { done } -function check_system_updates() { - local updates_avail info_msg - updates_avail=$(apt list --upgradeable 2>/dev/null | sed "1d") - - if [[ -n ${updates_avail} ]]; then - info_msg="${yellow}System upgrade available!${white}" - # add system to application_updates_available in kiauh.ini - add_to_application_updates "system" +function update_system_package_lists() { + local cache_mtime update_age update_interval silent + + if [[ $1 == '--silent' ]]; then silent="true"; fi + + if [[ -e /var/lib/apt/periodic/update-success-stamp ]]; then + cache_mtime="$(stat -c %Y /var/lib/apt/periodic/update-success-stamp)" + elif [[ -e /var/lib/apt/lists ]]; then + cache_mtime="$(stat -c %Y /var/lib/apt/lists)" else - info_msg="${green}System up to date! ${white}" + log_warning "Failure determining package cache age, forcing update" + cache_mtime=0 fi - echo "${info_msg}" + update_age="$(($(date +'%s') - cache_mtime))" + update_interval=$((48*60*60)) # 48hrs + + # update if cache is greater than update_interval + if (( update_age > update_interval )); then + if [[ ! ${silent} == "true" ]]; then status_msg "Updating package lists..."; fi + if ! sudo apt-get update --allow-releaseinfo-change &>/dev/null; then + log_error "Failure while updating package lists!" + if [[ ! ${silent} == "true" ]]; then error_msg "Updating package lists failed!"; fi + return 1 + else + log_info "Package lists updated successfully" + if [[ ! ${silent} == "true" ]]; then status_msg "Updated package lists."; fi + fi + else + log_info "Package lists updated recently, skipping update..." + fi } -function update_system() { - status_msg "Updating System ..." - if sudo apt-get update --allow-releaseinfo-change && sudo apt-get upgrade -y; then - print_confirm "Update complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been kept back!${green}" +function check_system_updates() { + local updates_avail status + if ! update_system_package_lists --silent; then + status="${red}Update check failed! ${white}" else - print_error "System update failed! Please watch for any errors printed above!" + updates_avail="$(apt list --upgradeable 2>/dev/null | sed "1d")" + + if [[ -n ${updates_avail} ]]; then + status="${yellow}System upgrade available!${white}" + # add system to application_updates_available in kiauh.ini + add_to_application_updates "system" + else + status="${green}System up to date! ${white}" + fi + fi + + echo "${status}" +} + +function upgrade_system_packages() { + status_msg "Upgrading System ..." + update_system_package_lists + if sudo apt-get upgrade -y; then + print_confirm "Upgrade complete! Check the log above!\n ${yellow}KIAUH will not install any dist-upgrades or\n any packages which have been held back!${green}" + else + print_error "System upgrade failed! Please look for any errors printed above!" + fi +} + +function install_system_packages() { + local log_name="$1" + local packages=("${!2}") + status_msg "Installing packages..." + if sudo apt-get install -y "${packages[@]}"; then + ok_msg "${log_name^} packages installed!" + else + log_error "Failure while installing ${log_name,,} packages" + error_msg "Installing ${log_name} packages failed!" + exit 1 # exit kiauh fi } From 345b7b66a34ce4ccb01dc86752624d2c57f5dce0 Mon Sep 17 00:00:00 2001 From: phizev Date: Sat, 17 Jun 2023 18:22:16 +0200 Subject: [PATCH 8/8] refactor: use service specific directories in templates (#355) --- resources/klipper.env | 2 +- resources/klipper.service | 2 +- resources/moonraker-telegram-bot.env | 2 +- resources/moonraker-telegram-bot.service | 2 +- resources/moonraker.env | 2 +- resources/moonraker.service | 2 +- scripts/klipper.sh | 4 ++-- scripts/moonraker-telegram-bot.sh | 4 ++-- scripts/moonraker.sh | 4 ++-- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/resources/klipper.env b/resources/klipper.env index 1f16a6e..6ab13d6 100644 --- a/resources/klipper.env +++ b/resources/klipper.env @@ -1 +1 @@ -KLIPPER_ARGS="/home/%USER%/klipper/klippy/klippy.py %CFG% -I %PRINTER% -l %LOG% -a %UDS%" \ No newline at end of file +KLIPPER_ARGS="%KLIPPER_DIR%/klippy/klippy.py %CFG% -I %PRINTER% -l %LOG% -a %UDS%" \ No newline at end of file diff --git a/resources/klipper.service b/resources/klipper.service index 8c74cd4..b41788f 100644 --- a/resources/klipper.service +++ b/resources/klipper.service @@ -11,7 +11,7 @@ WantedBy=multi-user.target Type=simple User=%USER% RemainAfterExit=yes -WorkingDirectory=/home/%USER%/klipper +WorkingDirectory=%KLIPPER_DIR% EnvironmentFile=%ENV_FILE% ExecStart=%ENV%/bin/python $KLIPPER_ARGS Restart=always diff --git a/resources/moonraker-telegram-bot.env b/resources/moonraker-telegram-bot.env index aaa7547..280f165 100644 --- a/resources/moonraker-telegram-bot.env +++ b/resources/moonraker-telegram-bot.env @@ -1 +1 @@ -TELEGRAM_BOT_ARGS="/home/%USER%/moonraker-telegram-bot/bot/main.py -c %CFG% -l %LOG%" \ No newline at end of file +TELEGRAM_BOT_ARGS="%TELEGRAM_BOT_DIR%/bot/main.py -c %CFG% -l %LOG%" \ No newline at end of file diff --git a/resources/moonraker-telegram-bot.service b/resources/moonraker-telegram-bot.service index 612a6cd..567481d 100644 --- a/resources/moonraker-telegram-bot.service +++ b/resources/moonraker-telegram-bot.service @@ -9,7 +9,7 @@ WantedBy=multi-user.target [Service] Type=simple User=%USER% -WorkingDirectory=/home/%USER%/moonraker-telegram-bot +WorkingDirectory=%TELEGRAM_BOT_DIR% EnvironmentFile=%ENV_FILE% ExecStart=%ENV%/bin/python $TELEGRAM_BOT_ARGS Restart=always diff --git a/resources/moonraker.env b/resources/moonraker.env index 065ca7e..bca6af5 100644 --- a/resources/moonraker.env +++ b/resources/moonraker.env @@ -1 +1 @@ -MOONRAKER_ARGS="/home/%USER%/moonraker/moonraker/moonraker.py -d %PRINTER_DATA%" \ No newline at end of file +MOONRAKER_ARGS="%MOONRAKER_DIR%/moonraker/moonraker.py -d %PRINTER_DATA%" \ No newline at end of file diff --git a/resources/moonraker.service b/resources/moonraker.service index ac8000f..7bfe8e2 100644 --- a/resources/moonraker.service +++ b/resources/moonraker.service @@ -12,7 +12,7 @@ Type=simple User=%USER% SupplementaryGroups=moonraker-admin RemainAfterExit=yes -WorkingDirectory=/home/%USER%/moonraker +WorkingDirectory=%MOONRAKER_DIR% EnvironmentFile=%ENV_FILE% ExecStart=%ENV%/bin/python $MOONRAKER_ARGS Restart=always diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 6ea8c28..e46e02d 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -368,8 +368,8 @@ function create_klipper_service() { sudo cp "${service_template}" "${service}" sudo cp "${env_template}" "${env_file}" - sudo sed -i "s|%USER%|${USER}|g; s|%ENV%|${KLIPPY_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}" - sudo sed -i "s|%USER%|${USER}|; s|%LOG%|${log}|; s|%CFG%|${cfg}|; s|%PRINTER%|${klippy_serial}|; s|%UDS%|${klippy_socket}|" "${env_file}" + sudo sed -i "s|%USER%|${USER}|g; s|%KLIPPER_DIR%|${KLIPPER_DIR}|; s|%ENV%|${KLIPPY_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}" + sudo sed -i "s|%USER%|${USER}|; s|%KLIPPER_DIR%|${KLIPPER_DIR}|; s|%LOG%|${log}|; s|%CFG%|${cfg}|; s|%PRINTER%|${klippy_serial}|; s|%UDS%|${klippy_socket}|" "${env_file}" ok_msg "Klipper service file created!" fi diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index e88a93f..afccef8 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -318,11 +318,11 @@ function write_telegram_bot_service() { else sudo sed -i "s|%INST%|${i}|" "${service}" fi - sudo sed -i "s|%USER%|${USER}|g; s|%ENV%|${TELEGRAM_BOT_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}" + sudo sed -i "s|%USER%|${USER}|g; s|%TELEGRAM_BOT_DIR%|${TELEGRAM_BOT_DIR}|; s|%ENV%|${TELEGRAM_BOT_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}" status_msg "Creating environment file for instance ${i} ..." cp "${env_template}" "${env_file}" - sed -i "s|%USER%|${USER}|; s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${env_file}" + sed -i "s|%USER%|${USER}|; s|%TELEGRAM_BOT_DIR%|${TELEGRAM_BOT_DIR}|; s|%CFG%|${cfg}|; s|%LOG%|${log}|" "${env_file}" fi } diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index e971878..775b0b2 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -360,8 +360,8 @@ function write_moonraker_service() { [[ -z ${i} ]] && sudo sed -i "s| %INST%||" "${service}" [[ -n ${i} ]] && sudo sed -i "s|%INST%|${i}|" "${service}" - sudo sed -i "s|%USER%|${USER}|g; s|%ENV%|${MOONRAKER_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}" - sudo sed -i "s|%USER%|${USER}|; s|%PRINTER_DATA%|${printer_data}|" "${env_file}" + sudo sed -i "s|%USER%|${USER}|g; s|%MOONRAKER_DIR%|${MOONRAKER_DIR}|; s|%ENV%|${MOONRAKER_ENV}|; s|%ENV_FILE%|${env_file}|" "${service}" + sudo sed -i "s|%USER%|${USER}|; s|%MOONRAKER_DIR%|${MOONRAKER_DIR}|; s|%PRINTER_DATA%|${printer_data}|" "${env_file}" fi }