From 668331e7eaa7a8f3c954ad28bba1563f83a40247 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Thu, 17 Sep 2020 21:23:26 +0200 Subject: [PATCH] add: update all function --- scripts/status.sh | 31 ++++++++++++++++++++++++-- scripts/ui/update_menu.sh | 14 ++++++++---- scripts/update.sh | 46 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 83 insertions(+), 8 deletions(-) diff --git a/scripts/status.sh b/scripts/status.sh index 8c0879a..8f79f4b 100755 --- a/scripts/status.sh +++ b/scripts/status.sh @@ -168,6 +168,7 @@ read_remote_klipper_commit(){ } compare_klipper_versions(){ + unset KLIPPER_UPDATE_AVAIL read_local_klipper_commit read_remote_klipper_commit #echo "Local: $LOCAL_COMMIT" @@ -175,9 +176,12 @@ compare_klipper_versions(){ if [ "$LOCAL_COMMIT" != "$REMOTE_COMMIT" ]; then LOCAL_COMMIT="${yellow}$LOCAL_COMMIT${default}" REMOTE_COMMIT="${green}$REMOTE_COMMIT${default}" + KLIPPER_UPDATE_AVAIL="true" + update_arr+=(update_klipper) else LOCAL_COMMIT="${green}$LOCAL_COMMIT${default}" REMOTE_COMMIT="${green}$REMOTE_COMMIT${default}" + KLIPPER_UPDATE_AVAIL="false" fi } @@ -197,23 +201,30 @@ read_dwc2fk_versions(){ } compare_dwc2fk_versions(){ + unset DWC2FK_UPDATE_AVAIL read_dwc2fk_versions #echo "Local: $LOCAL_DWC2FK_COMMIT" #echo "Remote: $REMOTE_DWC2FK_COMMIT" if [ "$LOCAL_DWC2FK_COMMIT" != "$REMOTE_DWC2FK_COMMIT" ]; then LOCAL_DWC2FK_COMMIT="${yellow}$LOCAL_DWC2FK_COMMIT${default}" REMOTE_DWC2FK_COMMIT="${green}$REMOTE_DWC2FK_COMMIT${default}" + DWC2FK_UPDATE_AVAIL="true" + update_arr+=(update_dwc2fk) else LOCAL_DWC2FK_COMMIT="${green}$LOCAL_DWC2FK_COMMIT${default}" REMOTE_DWC2FK_COMMIT="${green}$REMOTE_DWC2FK_COMMIT${default}" + DWC2FK_UPDATE_AVAIL="false" fi } read_local_dwc2_version(){ + unset DWC2_IS_INSTALLED if [ -e $DWC2_DIR/version ]; then DWC2_LOCAL_VER=$(head -n 1 $DWC2_DIR/version) + DWC2_IS_INSTALLED="true" else DWC2_LOCAL_VER="${red}-----${default}" + DWC2_IS_INSTALLED="false" fi } @@ -227,16 +238,20 @@ read_remote_dwc2_version(){ } compare_dwc2_versions(){ + unset DWC2_UPDATE_AVAIL read_local_dwc2_version read_remote_dwc2_version #echo "Local: $DWC2_LOCAL_VER" #echo "Remote: $DWC2_REMOTE_VER" - if [ "$DWC2_LOCAL_VER" != "$DWC2_REMOTE_VER" ]; then + if [ "$DWC2_LOCAL_VER" != "$DWC2_REMOTE_VER" ] && [ "$DWC2_IS_INSTALLED" = "true" ]; then DWC2_LOCAL_VER="${yellow}$DWC2_LOCAL_VER${default}" DWC2_REMOTE_VER="${green}$DWC2_REMOTE_VER${default}" + DWC2_UPDATE_AVAIL="true" + update_arr+=(update_dwc2) else DWC2_LOCAL_VER="${green}$DWC2_LOCAL_VER${default}" DWC2_REMOTE_VER="${green}$DWC2_REMOTE_VER${default}" + DWC2_UPDATE_AVAIL="false" fi } @@ -244,10 +259,13 @@ compare_dwc2_versions(){ ############################################################# read_local_mainsail_version(){ + unset MAINSAIL_IS_INSTALLED if [ -e $MAINSAIL_DIR/version ]; then MAINSAIL_LOCAL_VER=$(head -n 1 $MAINSAIL_DIR/version) + MAINSAIL_IS_INSTALLED="true" else MAINSAIL_LOCAL_VER="${red}-----${default}" + MAINSAIL_IS_INSTALLED="false" fi } @@ -262,16 +280,20 @@ read_remote_mainsail_version(){ } compare_mainsail_versions(){ + unset MAINSAIL_UPDATE_AVAIL read_local_mainsail_version read_remote_mainsail_version #echo "Local: $MAINSAIL_LOCAL_VER" #echo "Remote: $MAINSAIL_REMOTE_VER" - if [ "$MAINSAIL_LOCAL_VER" != "$MAINSAIL_REMOTE_VER" ]; then + if [ "$MAINSAIL_LOCAL_VER" != "$MAINSAIL_REMOTE_VER" ] && [ "$MAINSAIL_IS_INSTALLED" = "true" ]; then MAINSAIL_LOCAL_VER="${yellow}$MAINSAIL_LOCAL_VER${default}" MAINSAIL_REMOTE_VER="${green}$MAINSAIL_REMOTE_VER${default}" + MAINSAIL_UPDATE_AVAIL="true" + update_arr+=(update_mainsail) else MAINSAIL_LOCAL_VER="${green}$MAINSAIL_LOCAL_VER${default}" MAINSAIL_REMOTE_VER="${green}$MAINSAIL_REMOTE_VER${default}" + MAINSAIL_UPDATE_AVAIL="false" fi } @@ -288,19 +310,24 @@ read_moonraker_versions(){ } compare_moonraker_versions(){ + unset MOONRAKER_UPDATE_AVAIL read_moonraker_versions #echo "Local: $LOCAL_MOONRAKER_COMMIT" #echo "Remote: $REMOTE_MOONRAKER_COMMIT" if [ "$LOCAL_MOONRAKER_COMMIT" != "$REMOTE_MOONRAKER_COMMIT" ]; then LOCAL_MOONRAKER_COMMIT="${yellow}$LOCAL_MOONRAKER_COMMIT${default}" REMOTE_MOONRAKER_COMMIT="${green}$REMOTE_MOONRAKER_COMMIT${default}" + MOONRAKER_UPDATE_AVAIL="true" + update_arr+=(update_moonraker) else LOCAL_MOONRAKER_COMMIT="${green}$LOCAL_MOONRAKER_COMMIT${default}" REMOTE_MOONRAKER_COMMIT="${green}$REMOTE_MOONRAKER_COMMIT${default}" + MOONRAKER_UPDATE_AVAIL="false" fi } ui_print_versions(){ + unset update_arr compare_klipper_versions compare_dwc2fk_versions compare_dwc2_versions diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 928311e..9834a3b 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -2,16 +2,16 @@ update_ui(){ top_border echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${default} | " hr - echo -e "| It is a good idea to check the following website | " - echo -e "| for important software changes to the config file | " - echo -e "| >> BEFORE << updating your klipper installation: | " + echo -e "| Check the following website for important software | " + echo -e "| changes to the config file before updating Klipper: | " echo -e "| | " echo -e "| ${yellow}https://www.klipper3d.org/Config_Changes.html${default} | " bottom_border top_border echo -e "| 0) $BB4U_STATUS| " hr - echo -e "| | Local Vers: | Remote Vers: | " + echo -e "| a) [Update all] | Local Vers: | Remote Vers: | " + echo -e "| | | | " echo -e "| Firmware: | | | " echo -e "| 1) [Klipper] | $(echo "$LOCAL_COMMIT") | $(echo "$REMOTE_COMMIT") | " echo -e "| | | | " @@ -72,6 +72,12 @@ update_menu(){ update_mainsail && ui_print_versions print_msg && clear_msg update_ui;; + a) + clear + print_header + update_all && ui_print_versions + print_msg && clear_msg + update_ui;; Q|q) clear; main_menu; break;; *) diff --git a/scripts/update.sh b/scripts/update.sh index 8e7cd8c..c85e80f 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -7,6 +7,50 @@ update_kiauh(){ fi } +update_all(){ + while true; do + if [ "${#update_arr[@]}" = "0" ]; then + CONFIRM_MSG="Everything is already up to date!" + echo; break + fi + echo + top_border + echo -e "| The following installations will be updated: |" + if [ "$KLIPPER_UPDATE_AVAIL" = "true" ]; then + echo -e "| ${cyan}● Klipper${default} |" + fi + if [ "$DWC2FK_UPDATE_AVAIL" = "true" ]; then + echo -e "| ${cyan}● DWC2-for-Klipper-Socket${default} |" + fi + if [ "$DWC2_UPDATE_AVAIL" = "true" ]; then + echo -e "| ${cyan}● Duet Web Control${default} |" + fi + if [ "$MOONRAKER_UPDATE_AVAIL" = "true" ]; then + echo -e "| ${cyan}● Moonraker${default} |" + fi + if [ "$MAINSAIL_UPDATE_AVAIL" = "true" ]; then + echo -e "| ${cyan}● Mainsail${default} |" + fi + bottom_border + if [ "${#update_arr[@]}" != "0" ]; then + read -p "${cyan}###### Do you want to proceed? (Y/n):${default} " yn + case "$yn" in + Y|y|Yes|yes|"") + for update in ${update_arr[@]} + do + $update + done + break;; + N|n|No|no) + break;; + *) + print_unkown_cmd + print_msg && clear_msg;; + esac + fi + done +} + update_klipper(){ stop_klipper if [ ! -d $KLIPPER_DIR ]; then @@ -49,11 +93,9 @@ update_dwc2(){ } update_mainsail(){ - stop_klipper bb4u "mainsail" status_msg "Updating Mainsail ..." mainsail_setup - start_klipper } update_moonraker(){