diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index 02c33cc..0523c4f 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -292,20 +292,18 @@ function get_remote_fluidd_version() { } function compare_fluidd_versions() { - unset FLUIDD_UPDATE_AVAIL local versions local_ver remote_ver local_ver="$(get_local_fluidd_version)" remote_ver="$(get_remote_fluidd_version)" - if [[ ${local_ver} != "${remote_ver}" ]]; then + if [[ ${local_ver} != "${remote_ver}" && ${local_ver} != "" ]]; then versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - # add fluidd to the update all array for the update all function in the updater - FLUIDD_UPDATE_AVAIL="true" && update_arr+=(update_fluidd) + # add moonraker to application_updates_available in kiauh.ini + add_to_application_updates "fluidd" else versions="${green}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - FLUIDD_UPDATE_AVAIL="false" fi echo "${versions}" diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 6d011dc..1372203 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -553,7 +553,6 @@ function get_remote_klipper_commit() { } function compare_klipper_versions() { - unset KLIPPER_UPDATE_AVAIL local versions local_ver remote_ver local_ver="$(get_local_klipper_commit)" remote_ver="$(get_remote_klipper_commit)" @@ -561,12 +560,11 @@ function compare_klipper_versions() { if [[ ${local_ver} != "${remote_ver}" ]]; then versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - # add klipper to the update all array for the update all function in the updater - KLIPPER_UPDATE_AVAIL="true" && update_arr+=(update_klipper) + # add klipper to application_updates_available in kiauh.ini + add_to_application_updates "klipper" else versions="${green}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - KLIPPER_UPDATE_AVAIL="false" fi echo "${versions}" diff --git a/scripts/klipperscreen.sh b/scripts/klipperscreen.sh index adb5e25..b5587db 100644 --- a/scripts/klipperscreen.sh +++ b/scripts/klipperscreen.sh @@ -180,7 +180,6 @@ function get_remote_klipperscreen_commit() { } function compare_klipperscreen_versions() { - unset KLIPPERSCREEN_UPDATE_AVAIL local versions local_ver remote_ver local_ver="$(get_local_klipperscreen_commit)" remote_ver="$(get_remote_klipperscreen_commit)" @@ -188,12 +187,11 @@ function compare_klipperscreen_versions() { if [[ ${local_ver} != "${remote_ver}" ]]; then versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - # add klipperscreen to the update all array for the update all function in the updater - KLIPPERSCREEN_UPDATE_AVAIL="true" && update_arr+=(update_klipperscreen) + # add moonraker to application_updates_available in kiauh.ini + add_to_application_updates "klipperscreen" else versions="${green}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - KLIPPERSCREEN_UPDATE_AVAIL="false" fi echo "${versions}" diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 9a078d7..7c27715 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -297,20 +297,18 @@ function get_remote_mainsail_version() { } function compare_mainsail_versions() { - unset MAINSAIL_UPDATE_AVAIL local versions local_ver remote_ver local_ver="$(get_local_mainsail_version)" remote_ver="$(get_remote_mainsail_version)" - if [[ ${local_ver} != "${remote_ver}" ]]; then + if [[ ${local_ver} != "${remote_ver}" && ${local_ver} != "" ]]; then versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - # add mainsail to the update all array for the update all function in the updater - MAINSAIL_UPDATE_AVAIL="true" && update_arr+=(update_mainsail) + # add moonraker to application_updates_available in kiauh.ini + add_to_application_updates "mainsail" else versions="${green}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - MAINSAIL_UPDATE_AVAIL="false" fi echo "${versions}" diff --git a/scripts/moonraker-telegram-bot.sh b/scripts/moonraker-telegram-bot.sh index 9943e83..044c334 100644 --- a/scripts/moonraker-telegram-bot.sh +++ b/scripts/moonraker-telegram-bot.sh @@ -436,7 +436,6 @@ function get_remote_telegram_bot_commit() { } function compare_telegram_bot_versions() { - unset MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL local versions local_ver remote_ver local_ver="$(get_local_telegram_bot_commit)" remote_ver="$(get_remote_telegram_bot_commit)" @@ -444,12 +443,11 @@ function compare_telegram_bot_versions() { if [[ ${local_ver} != "${remote_ver}" ]]; then versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - # add moonraker-telegram-bot to the update all array for the update all function in the updater - MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="true" && update_arr+=(update_telegram_bot) + # add moonraker to application_updates_available in kiauh.ini + add_to_application_updates "telegram_bot" else versions="${green}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL="false" fi echo "${versions}" diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index a559bb3..294054c 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -557,7 +557,6 @@ function get_remote_moonraker_commit() { } function compare_moonraker_versions() { - unset MOONRAKER_UPDATE_AVAIL local versions local_ver remote_ver local_ver="$(get_local_moonraker_commit)" remote_ver="$(get_remote_moonraker_commit)" @@ -565,12 +564,11 @@ function compare_moonraker_versions() { if [[ ${local_ver} != "${remote_ver}" ]]; then versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - # add moonraker to the update all array for the update all function in the updater - MOONRAKER_UPDATE_AVAIL="true" && update_arr+=(update_moonraker) + # add moonraker to application_updates_available in kiauh.ini + add_to_application_updates "moonraker" else versions="${green}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - MOONRAKER_UPDATE_AVAIL="false" fi echo "${versions}" diff --git a/scripts/nginx.sh b/scripts/nginx.sh index 9da518d..ebe3b71 100644 --- a/scripts/nginx.sh +++ b/scripts/nginx.sh @@ -260,8 +260,7 @@ function detect_conflicting_packages() { echo -e "###### > Skip" break;; *) - print_unkown_cmd - print_msg && clear_msg;; + error_msg "Invalid command!";; esac done fi diff --git a/scripts/pretty_gcode.sh b/scripts/pretty_gcode.sh index 23822c1..8ab9494 100644 --- a/scripts/pretty_gcode.sh +++ b/scripts/pretty_gcode.sh @@ -109,7 +109,6 @@ function get_remote_prettygcode_commit() { } function compare_prettygcode_versions() { - unset PGC_UPDATE_AVAIL local versions local_ver remote_ver local_ver="$(get_local_prettygcode_commit)" remote_ver="$(get_remote_prettygcode_commit)" @@ -117,12 +116,11 @@ function compare_prettygcode_versions() { if [[ ${local_ver} != "${remote_ver}" ]]; then versions="${yellow}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - # add prettygcode to the update all array for the update all function in the updater - PGC_UPDATE_AVAIL="true" && update_arr+=(update_pgc_for_klipper) + # add moonraker to application_updates_available in kiauh.ini + add_to_application_updates "pgc_for_klipper" else versions="${green}$(printf " %-14s" "${local_ver}")${white}" versions+="|${green}$(printf " %-13s" "${remote_ver}")${white}" - PGC_UPDATE_AVAIL="false" fi echo "${versions}" diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 0df326b..3d6338d 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -37,7 +37,6 @@ function update_ui() { } function update_menu() { - unset update_arr do_action "" "update_ui" local action @@ -74,6 +73,13 @@ function update_menu() { } function update_all() { + read_kiauh_ini "${FUNCNAME[0]}" + + local update_arr + local app_update_state="${application_updates_available}" + + IFS=', ' read -r -a update_arr <<< "${app_update_state}" + while true; do if (( ${#update_arr[@]} == 0 )); then print_confirm "Everything is already up-to-date!" @@ -83,49 +89,47 @@ function update_all() { echo top_border echo -e "| The following installations will be updated: |" - if [[ "${KLIPPER_UPDATE_AVAIL}" = "true" ]]; then - echo -e "| ${cyan}● Klipper${white} |" - fi - if [[ "${MOONRAKER_UPDATE_AVAIL}" = "true" ]]; then - echo -e "| ${cyan}● Moonraker${white} |" - fi - if [[ "${MAINSAIL_UPDATE_AVAIL}" = "true" ]]; then - echo -e "| ${cyan}● Mainsail${white} |" - fi - if [[ "${FLUIDD_UPDATE_AVAIL}" = "true" ]]; then - echo -e "| ${cyan}● Fluidd${white} |" - fi - if [[ "${KLIPPERSCREEN_UPDATE_AVAIL}" = "true" ]]; then - echo -e "| ${cyan}● KlipperScreen${white} |" - fi - if [[ "${PGC_UPDATE_AVAIL}" = "true" ]]; then - echo -e "| ${cyan}● PrettyGCode for Klipper${white} |" - fi - if [[ "${MOONRAKER_TELEGRAM_BOT_UPDATE_AVAIL}" = "true" ]]; then - echo -e "| ${cyan}● MoonrakerTelegramBot${white} |" - fi - if [[ "${SYS_UPDATE_AVAIL}" = "true" ]]; then - echo -e "| ${cyan}● System${white} |" - fi + + [[ "${update_arr[*]}" =~ "klipper" ]] && \ + echo -e "| ${cyan}● Klipper${white} |" + + [[ "${update_arr[*]}" =~ "moonraker" ]] && \ + echo -e "| ${cyan}● Moonraker${white} |" + + [[ "${update_arr[*]}" =~ "mainsail" ]] && \ + echo -e "| ${cyan}● Mainsail${white} |" + + [[ "${update_arr[*]}" =~ "fluidd" ]] && \ + echo -e "| ${cyan}● Fluidd${white} |" + + [[ "${update_arr[*]}" =~ "klipperscreen" ]] && \ + echo -e "| ${cyan}● KlipperScreen${white} |" + + [[ "${update_arr[*]}" =~ "pgc_for_klipper" ]] && \ + echo -e "| ${cyan}● PrettyGCode for Klipper${white} |" + + [[ "${update_arr[*]}" =~ "telegram_bot" ]] && \ + echo -e "| ${cyan}● MoonrakerTelegramBot${white} |" + + [[ "${update_arr[*]}" =~ "system" ]] && \ + echo -e "| ${cyan}● System${white} |" + bottom_border local yn - if (( ${#update_arr[@]} != 0 )); then - read -p "${cyan}###### Do you want to proceed? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - for update in "${update_arr[@]}" - do - #shellcheck disable=SC2250 - $update - done - break;; - N|n|No|no) - break;; - *) - print_unkown_cmd - print_msg && clear_msg;; - esac - fi + read -p "${cyan}###### Do you want to proceed? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + for app in "${update_arr[@]}"; do + local update="update_${app}" + #shellcheck disable=SC2250 + $update + done + break;; + N|n|No|no) + break;; + *) + error_msg "Invalid command!";; + esac done } diff --git a/scripts/utilities.sh b/scripts/utilities.sh index 9d5bc43..b034ae4 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -141,6 +141,12 @@ function init_ini() { } >> "${INI_FILE}" fi + if ! grep -Eq "^application_updates_available=" "${INI_FILE}"; then + echo -e "\napplication_updates_available=\c" >> "${INI_FILE}" + else + sed -i "/application_updates_available=/s/=.*/=/" "${INI_FILE}" + fi + if ! grep -Eq "^backup_before_update=." "${INI_FILE}"; then echo -e "\nbackup_before_update=false\c" >> "${INI_FILE}" fi @@ -370,6 +376,18 @@ function set_custom_klipper_repo() { sed -i '$a'"custom_klipper_repo_branch=${branch}" "${INI_FILE}" } +function add_to_application_updates() { + read_kiauh_ini "${FUNCNAME[0]}" + + local application="${1}" + local app_update_state="${application_updates_available}" + + if ! grep -Eq "${application}" <<< "${app_update_state}"; then + app_update_state="${app_update_state}${application}," + sed -i "/application_updates_available=/s/=.*/=${app_update_state}/" "${INI_FILE}" + fi +} + #================================================# #=============== HANDLE SERVICES ================# #================================================# @@ -474,11 +492,10 @@ function check_system_updates() { updates_avail=$(apt list --upgradeable 2>/dev/null | sed "1d") if [[ -n ${updates_avail} ]]; then - # add system updates to the update all array for the update all function in the updater - SYS_UPDATE_AVAIL="true" && update_arr+=(update_system) info_msg="${yellow}System upgrade available!${white}" + # add system to application_updates_available in kiauh.ini + add_to_application_updates "system" else - SYS_UPDATE_AVAIL="false" info_msg="${green}System up to date! ${white}" fi