From 7da500a945c42927b7cde3118e4254068aa444f5 Mon Sep 17 00:00:00 2001 From: th33xitus Date: Sat, 23 Apr 2022 12:51:51 +0200 Subject: [PATCH] refactor: backup_before_updates functions Signed-off-by: Dominik Willner th33xitus@gmail.com --- scripts/backup.sh | 31 ++++--------------------------- scripts/fluidd.sh | 2 +- scripts/klipper.sh | 2 +- scripts/mainsail.sh | 2 +- scripts/moonraker.sh | 2 +- scripts/ui/settings_menu.sh | 16 ++++++++++++++++ scripts/ui/update_menu.sh | 3 --- scripts/utilities.sh | 10 ++++++++++ 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 98cb05d..4288a54 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -23,34 +23,11 @@ function check_for_backup_dir(){ fi } -function toggle_backups(){ +function backup_before_update(){ read_kiauh_ini - if [ "${backup_before_update}" = "true" ]; then - sed -i '/backup_before_update=/s/true/false/' "${INI_FILE}" - BB4U_STATUS="${green}[Enable]${white} backups before updating " - CONFIRM_MSG=" Backups before updates are now >>> DISABLED <<< !" - fi - if [ "${backup_before_update}" = "false" ]; then - sed -i '/backup_before_update=/s/false/true/' "${INI_FILE}" - BB4U_STATUS="${red}[Disable]${white} backups before updating " - CONFIRM_MSG=" Backups before updates are now >>> ENABLED <<< !" - fi -} - -function bb4u(){ - read_kiauh_ini - if [ "${backup_before_update}" = "true" ]; then - backup_"${1}" - fi -} - -function read_bb4u_stat(){ - read_kiauh_ini - if [ ! "${backup_before_update}" = "true" ]; then - BB4U_STATUS="${green}[Enable]${white} backups before updating " - else - BB4U_STATUS="${red}[Disable]${white} backups before updating " - fi + local state="${backup_before_update}" + [ "${state}" = "false" ] && return + backup_"${1}" } function backup_printer_cfg(){ diff --git a/scripts/fluidd.sh b/scripts/fluidd.sh index bff2219..00025db 100644 --- a/scripts/fluidd.sh +++ b/scripts/fluidd.sh @@ -233,7 +233,7 @@ function remove_fluidd(){ #===================================================# function update_fluidd(){ - bb4u "fluidd" + backup_before_update "fluidd" status_msg "Updating Fluidd ..." fluidd_setup match_nginx_configs diff --git a/scripts/klipper.sh b/scripts/klipper.sh index 499a427..34bfdb7 100644 --- a/scripts/klipper.sh +++ b/scripts/klipper.sh @@ -341,7 +341,7 @@ function update_klipper(){ if [ ! -d "${KLIPPER_DIR}" ]; then cd "${HOME}" && git clone "${KLIPPER_REPO}" else - bb4u "klipper" + backup_before_update "klipper" status_msg "Updating Klipper ..." cd "${KLIPPER_DIR}" && git pull ### read PKGLIST and install possible new dependencies diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 323311b..1b3f60b 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -238,7 +238,7 @@ function remove_mainsail(){ #===================================================# function update_mainsail(){ - bb4u "mainsail" + backup_before_update "mainsail" status_msg "Updating Mainsail ..." mainsail_setup match_nginx_configs diff --git a/scripts/moonraker.sh b/scripts/moonraker.sh index 2da795d..75fb5ea 100644 --- a/scripts/moonraker.sh +++ b/scripts/moonraker.sh @@ -395,7 +395,7 @@ function update_moonraker(){ if [ ! -d "${MOONRAKER_DIR}" ]; then cd "${HOME}" && git clone "${MOONRAKER_REPO}" else - bb4u "moonraker" + backup_before_update "moonraker" status_msg "Updating Moonraker ..." cd "${MOONRAKER_DIR}" && git pull ### read PKGLIST and install possible new dependencies diff --git a/scripts/ui/settings_menu.sh b/scripts/ui/settings_menu.sh index 40370f7..d58fdca 100755 --- a/scripts/ui/settings_menu.sh +++ b/scripts/ui/settings_menu.sh @@ -18,6 +18,7 @@ function settings_ui() { local custom_branch="${custom_klipper_repo_branch}" local ms_pre_rls="${mainsail_install_unstable}" local fl_pre_rls="${fluidd_install_unstable}" + local bbu="${backup_before_update}" ### config location if [ -z "${custom_cfg_loc}" ]; then @@ -49,6 +50,12 @@ function settings_ui() { else fl_pre_rls="${green}● ${fl_pre_rls}${white}" fi + ### backup before update toggle + if [ "${bbu}" == "false" ]; then + bbu="${red}● ${bbu}${white}" + else + bbu="${green}● ${bbu}${white}" + fi top_border echo -e "| $(title_msg "~~~~~~~~~~~~ [ KIAUH Settings ] ~~~~~~~~~~~~~") |" @@ -63,6 +70,8 @@ function settings_ui() { printf "| Mainsail: %-55s|\n" "${ms_pre_rls}" printf "| Fluidd: %-55s|\n" "${fl_pre_rls}" hr + printf "| Backup before updating: %-42s|\n" "${bbu}" + hr echo -e "| 1) Change Klipper config folder location |" echo -e "| 2) Set custom Klipper repository |" if [ "${mainsail_install_unstable}" == "false" ]; then @@ -75,6 +84,11 @@ function settings_ui() { else echo -e "| 4) ${red}Disallow${white} unstable Fluidd releases |" fi + if [ "${backup_before_update}" == "false" ]; then + echo -e "| 5) ${green}Enable${white} automatic backups before updates |" + else + echo -e "| 5) ${red}Disable${white} automatic backups before updates |" + fi back_help_footer } @@ -133,6 +147,8 @@ function settings_menu(){ switch_mainsail_releasetype && settings_menu;; 4) switch_fluidd_releasetype && settings_menu;; + 5) + toggle_backup_before_update && settings_menu;; B|b) clear main_menu diff --git a/scripts/ui/update_menu.sh b/scripts/ui/update_menu.sh index 94d885f..31ccd99 100755 --- a/scripts/ui/update_menu.sh +++ b/scripts/ui/update_menu.sh @@ -15,8 +15,6 @@ function update_ui(){ top_border echo -e "| ${green}~~~~~~~~~~~~~~ [ Update Menu ] ~~~~~~~~~~~~~~${white} | " hr - echo -e "| 0) ${BB4U_STATUS}| " - hr echo -e "| a) [Update all] | | | " echo -e "| | Installed: | Latest: | " echo -e "| Klipper & API: |---------------|--------------| " @@ -40,7 +38,6 @@ function update_ui(){ function update_menu(){ unset update_arr - read_bb4u_stat do_action "" "update_ui" while true; do read -p "${cyan}####### Perform action:${white} " action diff --git a/scripts/utilities.sh b/scripts/utilities.sh index f6ebc94..0a1bb5b 100644 --- a/scripts/utilities.sh +++ b/scripts/utilities.sh @@ -310,6 +310,16 @@ function switch_fluidd_releasetype() { fi } +function toggle_backup_before_update(){ + read_kiauh_ini + local state="${backup_before_update}" + if [ "${state}" = "false" ]; then + sed -i '/backup_before_update=/s/false/true/' "${INI_FILE}" + else + sed -i '/backup_before_update=/s/true/false/' "${INI_FILE}" + fi +} + function set_custom_klipper_repo() { read_kiauh_ini local repo_url=${1} branch=${2}