refactor: backup_before_updates functions

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-04-23 12:51:51 +02:00
parent 1915453b7e
commit 7da500a945
8 changed files with 34 additions and 34 deletions

View File

@@ -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(){

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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}