refactor(backup.sh): fix some shellcheck warnings
Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
1
kiauh.sh
1
kiauh.sh
@@ -35,7 +35,6 @@ MAINSAIL_DIR=${HOME}/mainsail
|
|||||||
FLUIDD_DIR=${HOME}/fluidd
|
FLUIDD_DIR=${HOME}/fluidd
|
||||||
#misc
|
#misc
|
||||||
INI_FILE=${HOME}/.kiauh.ini
|
INI_FILE=${HOME}/.kiauh.ini
|
||||||
BACKUP_DIR=${HOME}/kiauh-backups
|
|
||||||
|
|
||||||
### set github repos
|
### set github repos
|
||||||
DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git
|
DMBUTYUGIN_REPO=https://github.com/dmbutyugin/klipper.git
|
||||||
|
|||||||
@@ -1,37 +1,53 @@
|
|||||||
check_for_backup_dir(){
|
#!/bin/bash
|
||||||
if [ ! -d $BACKUP_DIR ]; then
|
|
||||||
|
#=======================================================================#
|
||||||
|
# Copyright (C) 2020 - 2022 Dominik Willner <th33xitus@gmail.com> #
|
||||||
|
# #
|
||||||
|
# This file is part of KIAUH - Klipper Installation And Update Helper #
|
||||||
|
# https://github.com/th33xitus/kiauh #
|
||||||
|
# #
|
||||||
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
|
#=======================================================================#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
### global variables
|
||||||
|
BACKUP_DIR="${HOME}/kiauh-backups"
|
||||||
|
|
||||||
|
function check_for_backup_dir(){
|
||||||
|
if [ ! -d "${BACKUP_DIR}" ]; then
|
||||||
status_msg "Create KIAUH backup directory ..."
|
status_msg "Create KIAUH backup directory ..."
|
||||||
mkdir -p $BACKUP_DIR && ok_msg "Directory created!"
|
mkdir -p "${BACKUP_DIR}" && ok_msg "Directory created!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle_backups(){
|
function toggle_backups(){
|
||||||
source_kiauh_ini
|
source_kiauh_ini
|
||||||
if [ "$backup_before_update" = "true" ]; then
|
if [ "${backup_before_update}" = "true" ]; then
|
||||||
sed -i '/backup_before_update=/s/true/false/' $INI_FILE
|
sed -i '/backup_before_update=/s/true/false/' "${INI_FILE}"
|
||||||
BB4U_STATUS="${green}[Enable]${default} backups before updating "
|
BB4U_STATUS="${green}[Enable]${white} backups before updating "
|
||||||
CONFIRM_MSG=" Backups before updates are now >>> DISABLED <<< !"
|
CONFIRM_MSG=" Backups before updates are now >>> DISABLED <<< !"
|
||||||
fi
|
fi
|
||||||
if [ "$backup_before_update" = "false" ]; then
|
if [ "${backup_before_update}" = "false" ]; then
|
||||||
sed -i '/backup_before_update=/s/false/true/' $INI_FILE
|
sed -i '/backup_before_update=/s/false/true/' "${INI_FILE}"
|
||||||
BB4U_STATUS="${red}[Disable]${default} backups before updating "
|
BB4U_STATUS="${red}[Disable]${white} backups before updating "
|
||||||
CONFIRM_MSG=" Backups before updates are now >>> ENABLED <<< !"
|
CONFIRM_MSG=" Backups before updates are now >>> ENABLED <<< !"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
bb4u(){
|
function bb4u(){
|
||||||
source_kiauh_ini
|
source_kiauh_ini
|
||||||
if [ "$backup_before_update" = "true" ]; then
|
if [ "${backup_before_update}" = "true" ]; then
|
||||||
backup_$1
|
backup_"${1}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
read_bb4u_stat(){
|
function read_bb4u_stat(){
|
||||||
source_kiauh_ini
|
source_kiauh_ini
|
||||||
if [ ! "$backup_before_update" = "true" ]; then
|
if [ ! "${backup_before_update}" = "true" ]; then
|
||||||
BB4U_STATUS="${green}[Enable]${default} backups before updating "
|
BB4U_STATUS="${green}[Enable]${white} backups before updating "
|
||||||
else
|
else
|
||||||
BB4U_STATUS="${red}[Disable]${default} backups before updating "
|
BB4U_STATUS="${red}[Disable]${white} backups before updating "
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,28 +55,28 @@ read_bb4u_stat(){
|
|||||||
#******************************************************************************#
|
#******************************************************************************#
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
backup_printer_cfg(){
|
function backup_printer_cfg(){
|
||||||
check_for_backup_dir
|
check_for_backup_dir
|
||||||
if [ -f $PRINTER_CFG ]; then
|
if [ -f "${PRINTER_CFG}" ]; then
|
||||||
get_date
|
get_date
|
||||||
status_msg "Timestamp: $current_date"
|
status_msg "Timestamp: ${current_date}"
|
||||||
status_msg "Create backup of printer.cfg ..."
|
status_msg "Create backup of printer.cfg ..."
|
||||||
cp $PRINTER_CFG $BACKUP_DIR/printer.cfg."$current_date".backup && ok_msg "Backup complete!"
|
cp "${PRINTER_CFG}" "${BACKUP_DIR}/printer.cfg.${current_date}.backup" && ok_msg "Backup complete!"
|
||||||
else
|
else
|
||||||
ok_msg "No printer.cfg found! Skipping backup ..."
|
ok_msg "No printer.cfg found! Skipping backup ..."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_klipper_config_dir(){
|
function backup_klipper_config_dir(){
|
||||||
source_kiauh_ini
|
source_kiauh_ini
|
||||||
check_for_backup_dir
|
check_for_backup_dir
|
||||||
if [ -d "$klipper_cfg_loc" ]; then
|
if [ -d "${klipper_cfg_loc}" ]; then
|
||||||
get_date
|
get_date
|
||||||
status_msg "Timestamp: $current_date"
|
status_msg "Timestamp: ${current_date}"
|
||||||
status_msg "Create backup of the Klipper config directory ..."
|
status_msg "Create backup of the Klipper config directory ..."
|
||||||
config_folder_name="$(echo "$klipper_cfg_loc" | rev | cut -d"/" -f1 | rev)"
|
config_folder_name="$(echo "${klipper_cfg_loc}" | rev | cut -d"/" -f1 | rev)"
|
||||||
mkdir -p $BACKUP_DIR/$config_folder_name/$current_date
|
mkdir -p "${BACKUP_DIR}/${config_folder_name}/${current_date}"
|
||||||
cp -r "$klipper_cfg_loc" "$_" && ok_msg "Backup complete!"
|
cp -r "${klipper_cfg_loc}" "${_}" && ok_msg "Backup complete!"
|
||||||
echo
|
echo
|
||||||
else
|
else
|
||||||
ok_msg "No config directory found! Skipping backup ..."
|
ok_msg "No config directory found! Skipping backup ..."
|
||||||
@@ -68,16 +84,16 @@ backup_klipper_config_dir(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_moonraker_database(){
|
function backup_moonraker_database(){
|
||||||
check_for_backup_dir
|
check_for_backup_dir
|
||||||
if ls -d ${HOME}/.moonraker_database* 2>/dev/null 1>&2; then
|
if ls -d ${HOME}/.moonraker_database* 2>/dev/null 1>&2; then
|
||||||
get_date
|
get_date
|
||||||
status_msg "Timestamp: $current_date"
|
status_msg "Timestamp: ${current_date}"
|
||||||
mkdir -p "$BACKUP_DIR/mr_db_backup/$current_date"
|
mkdir -p "${BACKUP_DIR}/mr_db_backup/${current_date}"
|
||||||
for database in $(ls -d ${HOME}/.moonraker_database*)
|
for database in $(ls -d ${HOME}/.moonraker_database*)
|
||||||
do
|
do
|
||||||
status_msg "Create backup of $database ..."
|
status_msg "Create backup of ${database} ..."
|
||||||
cp -r $database "$BACKUP_DIR/mr_db_backup/$current_date"
|
cp -r "${database}" "${BACKUP_DIR}/mr_db_backup/${current_date}"
|
||||||
ok_msg "Done!"
|
ok_msg "Done!"
|
||||||
done
|
done
|
||||||
ok_msg "Backup complete!\n"
|
ok_msg "Backup complete!\n"
|
||||||
@@ -86,110 +102,110 @@ backup_moonraker_database(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_klipper(){
|
function backup_klipper(){
|
||||||
if [ -d $KLIPPER_DIR ] && [ -d $KLIPPY_ENV ]; then
|
if [ -d "${KLIPPER_DIR}" ] && [ -d "${KLIPPY_ENV}" ]; then
|
||||||
status_msg "Creating Klipper backup ..."
|
status_msg "Creating Klipper backup ..."
|
||||||
check_for_backup_dir
|
check_for_backup_dir
|
||||||
get_date
|
get_date
|
||||||
status_msg "Timestamp: $current_date"
|
status_msg "Timestamp: ${current_date}"
|
||||||
mkdir -p $BACKUP_DIR/klipper-backups/"$current_date"
|
mkdir -p "${BACKUP_DIR}/klipper-backups/${current_date}"
|
||||||
cp -r $KLIPPER_DIR $_ && cp -r $KLIPPY_ENV $_ && ok_msg "Backup complete!"
|
cp -r "${KLIPPER_DIR}" "${_}" && cp -r "${KLIPPY_ENV}" "${_}" && ok_msg "Backup complete!"
|
||||||
else
|
else
|
||||||
ERROR_MSG=" Can't backup klipper and/or klipper-env directory! Not found!"
|
print_error "Can't backup klipper and/or klipper-env directory! Not found!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_dwc2(){
|
function backup_dwc2(){
|
||||||
if [ -d $DWC2FK_DIR ] && [ -d $DWC_ENV_DIR ] && [ -d $DWC2_DIR ]; then
|
if [ -d "${DWC2FK_DIR}" ] && [ -d "${DWC_ENV_DIR}" ] && [ -d "${DWC2_DIR}" ]; then
|
||||||
status_msg "Creating DWC2 Web UI backup ..."
|
status_msg "Creating DWC2 Web UI backup ..."
|
||||||
check_for_backup_dir
|
check_for_backup_dir
|
||||||
get_date
|
get_date
|
||||||
status_msg "Timestamp: $current_date"
|
status_msg "Timestamp: ${current_date}"
|
||||||
mkdir -p $BACKUP_DIR/dwc2-backups/"$current_date"
|
mkdir -p "${BACKUP_DIR}/dwc2-backups/${current_date}"
|
||||||
cp -r $DWC2FK_DIR $_ && cp -r $DWC_ENV_DIR $_ && cp -r $DWC2_DIR $_
|
cp -r "${DWC2FK_DIR}" "${_}" && cp -r "${DWC_ENV_DIR}" "${_}" && cp -r "${DWC2_DIR}" "${_}"
|
||||||
ok_msg "Backup complete!"
|
ok_msg "Backup complete!"
|
||||||
else
|
else
|
||||||
ERROR_MSG=" Can't backup dwc2-for-klipper-socket and/or dwc2 directory!\n Not found!"
|
print_error "Can't backup dwc2-for-klipper-socket and/or dwc2 directory!\n Not found!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_mainsail(){
|
function backup_mainsail(){
|
||||||
if [ -d $MAINSAIL_DIR ]; then
|
if [ -d "${MAINSAIL_DIR}" ]; then
|
||||||
status_msg "Creating Mainsail backup ..."
|
status_msg "Creating Mainsail backup ..."
|
||||||
check_for_backup_dir
|
check_for_backup_dir
|
||||||
get_date
|
get_date
|
||||||
status_msg "Timestamp: $current_date"
|
status_msg "Timestamp: ${current_date}"
|
||||||
mkdir -p $BACKUP_DIR/mainsail-backups/"$current_date"
|
mkdir -p "${BACKUP_DIR}/mainsail-backups/${current_date}"
|
||||||
cp -r $MAINSAIL_DIR $_ && ok_msg "Backup complete!"
|
cp -r "${MAINSAIL_DIR}" "${_}" && ok_msg "Backup complete!"
|
||||||
else
|
else
|
||||||
ERROR_MSG=" Can't backup mainsail directory! Not found!"
|
print_error "Can't backup mainsail directory! Not found!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_fluidd(){
|
function backup_fluidd(){
|
||||||
if [ -d $FLUIDD_DIR ]; then
|
if [ -d "${FLUIDD_DIR}" ]; then
|
||||||
status_msg "Creating Fluidd backup ..."
|
status_msg "Creating Fluidd backup ..."
|
||||||
check_for_backup_dir
|
check_for_backup_dir
|
||||||
get_date
|
get_date
|
||||||
status_msg "Timestamp: $current_date"
|
status_msg "Timestamp: ${current_date}"
|
||||||
mkdir -p $BACKUP_DIR/fluidd-backups/"$current_date"
|
mkdir -p "${BACKUP_DIR}/fluidd-backups/${current_date}"
|
||||||
cp -r $FLUIDD_DIR $_ && ok_msg "Backup complete!"
|
cp -r "${FLUIDD_DIR}" "${_}" && ok_msg "Backup complete!"
|
||||||
else
|
else
|
||||||
ERROR_MSG=" Can't backup fluidd directory! Not found!"
|
print_error "Can't backup fluidd directory! Not found!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_moonraker(){
|
function backup_moonraker(){
|
||||||
if [ -d $MOONRAKER_DIR ] && [ -d $MOONRAKER_ENV ]; then
|
if [ -d "${MOONRAKER_DIR}" ] && [ -d "${MOONRAKER_ENV}" ]; then
|
||||||
status_msg "Creating Moonraker backup ..."
|
status_msg "Creating Moonraker backup ..."
|
||||||
check_for_backup_dir
|
check_for_backup_dir
|
||||||
get_date
|
get_date
|
||||||
status_msg "Timestamp: $current_date"
|
status_msg "Timestamp: ${current_date}"
|
||||||
mkdir -p $BACKUP_DIR/moonraker-backups/"$current_date"
|
mkdir -p "${BACKUP_DIR}/moonraker-backups/${current_date}"
|
||||||
cp -r $MOONRAKER_DIR $_ && cp -r $MOONRAKER_ENV $_ && ok_msg "Backup complete!"
|
cp -r "${MOONRAKER_DIR}" "${_}" && cp -r "${MOONRAKER_ENV}" "${_}" && ok_msg "Backup complete!"
|
||||||
else
|
else
|
||||||
ERROR_MSG=" Can't backup moonraker and/or moonraker-env directory! Not found!"
|
print_error "Can't backup moonraker and/or moonraker-env directory! Not found!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_octoprint(){
|
function backup_octoprint(){
|
||||||
if [ -d $OCTOPRINT_DIR ] && [ -d $OCTOPRINT_CFG_DIR ]; then
|
if [ -d "${OCTOPRINT_DIR}" ] && [ -d "${OCTOPRINT_CFG_DIR}" ]; then
|
||||||
status_msg "Creating OctoPrint backup ..."
|
status_msg "Creating OctoPrint backup ..."
|
||||||
check_for_backup_dir
|
check_for_backup_dir
|
||||||
get_date
|
get_date
|
||||||
status_msg "Timestamp: $current_date"
|
status_msg "Timestamp: ${current_date}"
|
||||||
mkdir -p $BACKUP_DIR/octoprint-backups/"$current_date"
|
mkdir -p "${BACKUP_DIR}/octoprint-backups/${current_date}"
|
||||||
cp -r $OCTOPRINT_DIR $_ && cp -r $OCTOPRINT_CFG_DIR $_
|
cp -r "${OCTOPRINT_DIR}" "${_}" && cp -r "${OCTOPRINT_CFG_DIR}" "${_}"
|
||||||
ok_msg "Backup complete!"
|
ok_msg "Backup complete!"
|
||||||
else
|
else
|
||||||
ERROR_MSG=" Can't backup OctoPrint and/or .octoprint directory!\n Not found!"
|
print_error "Can't backup OctoPrint and/or .octoprint directory!\n Not found!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_klipperscreen(){
|
function backup_klipperscreen(){
|
||||||
if [ -d $KLIPPERSCREEN_DIR ] ; then
|
if [ -d "${KLIPPERSCREEN_DIR}" ] ; then
|
||||||
status_msg "Creating KlipperScreen backup ..."
|
status_msg "Creating KlipperScreen backup ..."
|
||||||
check_for_backup_dir
|
check_for_backup_dir
|
||||||
get_date
|
get_date
|
||||||
status_msg "Timestamp: $current_date"
|
status_msg "Timestamp: ${current_date}"
|
||||||
mkdir -p $BACKUP_DIR/klipperscreen-backups/"$current_date"
|
mkdir -p "${BACKUP_DIR}/klipperscreen-backups/${current_date}"
|
||||||
cp -r $KLIPPERSCREEN_DIR $_
|
cp -r "${KLIPPERSCREEN_DIR}" "${_}"
|
||||||
ok_msg "Backup complete!"
|
ok_msg "Backup complete!"
|
||||||
else
|
else
|
||||||
ERROR_MSG=" Can't backup KlipperScreen directory!\n Not found!"
|
print_error "Can't backup KlipperScreen directory!\n Not found!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
backup_MoonrakerTelegramBot(){
|
function backup_MoonrakerTelegramBot(){
|
||||||
if [ -d $MOONRAKER_TELEGRAM_BOT_DIR ] ; then
|
if [ -d "${MOONRAKER_TELEGRAM_BOT_DIR}" ] ; then
|
||||||
status_msg "Creating MoonrakerTelegramBot backup ..."
|
status_msg "Creating MoonrakerTelegramBot backup ..."
|
||||||
check_for_backup_dir
|
check_for_backup_dir
|
||||||
get_date
|
get_date
|
||||||
status_msg "Timestamp: $current_date"
|
status_msg "Timestamp: ${current_date}"
|
||||||
mkdir -p $BACKUP_DIR/MoonrakerTelegramBot-backups/"$current_date"
|
mkdir -p "${BACKUP_DIR}/MoonrakerTelegramBot-backups/${current_date}"
|
||||||
cp -r $MOONRAKER_TELEGRAM_BOT_DIR $_
|
cp -r "${MOONRAKER_TELEGRAM_BOT_DIR}" "${_}"
|
||||||
ok_msg "Backup complete!"
|
ok_msg "Backup complete!"
|
||||||
else
|
else
|
||||||
ERROR_MSG=" Can't backup MoonrakerTelegramBot directory!\n Not found!"
|
print_error "Can't backup MoonrakerTelegramBot directory!\n Not found!"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user