diff --git a/backup/wp_backup.sh b/backup/wp_backup.sh index a29ad7c..1901bb3 100644 --- a/backup/wp_backup.sh +++ b/backup/wp_backup.sh @@ -4,7 +4,7 @@ # VARIABLES # #-----------------------------------# -this_script_url=https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/backup/wp_backup.sh" +this_script_url="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/backup/wp_backup.sh" this_script_name="WordPress Backup Script" formatter_url="https://git.hhf.technology/hhf/TaskFormatter/raw/branch/main/bash_task_formatter/task_formatter.sh" scriptname=$0 @@ -16,6 +16,40 @@ success=0 USER_TO_RUN_AS="${1:-$SUDO_USER}" USER_HOME=$(eval echo ~$USER_TO_RUN_AS) +#-----------------------------------# +# FORMATTER # +#-----------------------------------# + +# Download and source the formatter with error handling +download_formatter() { + if [ ! -f "task_formatter.sh" ]; then + if ! wget "$formatter_url" --no-check-certificate -O task_formatter.sh > /dev/null 2>&1; then + echo "Error: Failed to download task_formatter.sh" + exit 1 + fi + fi + + if [ ! -f "task_formatter.sh" ]; then + echo "Error: task_formatter.sh not found after download attempt" + exit 1 + fi + + chmod +x task_formatter.sh + source ./task_formatter.sh || { echo "Error: Failed to source task_formatter.sh"; exit 1; } + + if ! declare -f print_header > /dev/null; then + echo "Error: print_header function not found after sourcing." + exit 1 + fi +} + +# Call the download_formatter function +download_formatter + +#-----------------------------------# +# FUNCTIONS # +#-----------------------------------# + # Function to collect WordPress and backup variables collect_variables() { echo "Please provide the following information:" @@ -69,46 +103,12 @@ collect_variables() { read -p "Is this information correct? (y/n): " confirm if [[ $confirm != [Yy]* ]]; then echo "Please run the script again with correct information." - exit 1 + return 1 fi return 0 } -#-----------------------------------# -# FORMATTER # -#-----------------------------------# - -# Download and source the formatter with error handling -download_formatter() { - if [ ! -f "task_formatter.sh" ]; then - if ! wget "$formatter_url" --no-check-certificate -O task_formatter.sh > /dev/null 2>&1; then - echo "Error: Failed to download task_formatter.sh" - exit 1 - fi - fi - - if [ ! -f "task_formatter.sh" ]; then - echo "Error: task_formatter.sh not found after download attempt" - exit 1 - fi - - chmod +x task_formatter.sh - source ./task_formatter.sh || { echo "Error: Failed to source task_formatter.sh"; exit 1; } - - if ! declare -f print_header > /dev/null; then - echo "Error: print_header function not found after sourcing." - exit 1 - fi -} - -# Call the download_formatter function -download_formatter - -#-----------------------------------# -# FUNCTIONS # -#-----------------------------------# - # Function to check WordPress installation check_wordpress() { if [ ! -d "${WP_DIR}" ]; then