From 0491598c1fe8a5d8d76c7271e2c6045093dd43e8 Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Mon, 16 Jan 2023 14:26:04 +0100 Subject: [PATCH] hook functions --- client/lib/main.sh | 39 ++++++++++++++++++++++++++------------- client/zzz_evobackup.sh | 41 ++++++++++++++++++++++++----------------- 2 files changed, 50 insertions(+), 30 deletions(-) diff --git a/client/lib/main.sh b/client/lib/main.sh index 090af60..deb8275 100644 --- a/client/lib/main.sh +++ b/client/lib/main.sh @@ -13,9 +13,9 @@ set -u # to exit with a non-zero status, or zero if all commands exit successfully. set -o pipefail -local_tasks() { - log_error "The 'local_tasks' function hasn't been customized" -} +source "${LIBDIR}/utilities.sh" +source "${LIBDIR}/dump.sh" + # Called from main, it is wrapping the local_tasks function defined in the real script local_tasks_wrapper() { log "START LOCAL_TASKS" @@ -23,17 +23,19 @@ local_tasks_wrapper() { # Remove old log directories find "${LOCAL_BACKUP_DIR}/" -type d -name "${PROGNAME}.errors-*" -ctime +30 -delete - # This function must be defined in the calling script - local_tasks + local_tasks_type="$(type -t local_tasks)" + if [ "${local_tasks_type}" = "function" ]; then + local_tasks + else + log_error "There is no 'local_tasks' function to execute" + fi # TODO: check if this is still needed # print_error_files_content log "STOP LOCAL_TASKS" } -sync_tasks() { - log_error "The 'sync_tasks' function hasn't been customized" -} + # Called from main, it is wrapping the sync_tasks function defined in the real script sync_tasks_wrapper() { declare -a SERVERS # Indexed array for server/port values @@ -121,8 +123,12 @@ sync_tasks_wrapper() { ) readonly rsync_default_excludes - # This function must be defined in the calling script - sync_tasks + sync_tasks_type="$(type -t sync_tasks)" + if [ "${sync_tasks_type}" = "function" ]; then + sync_tasks + else + log_error "There is no 'sync_tasks' function to execute" + fi } sync() { @@ -171,7 +177,7 @@ sync() { rsync_server=$(echo "${server}" | cut -d':' -f1) rsync_port=$(echo "${server}" | cut -d':' -f2) - log "START SYNC_TASKS - ${sync_name} : server=${server}" + log "START SYNC_TASKS - \"${sync_name}\" : server=${server}" # Rsync complete log file for the current run RSYNC_LOGFILE="/var/log/${PROGNAME}.${sync_name}.rsync.log" @@ -261,7 +267,7 @@ sync() { rsync_main_args+=("root@${rsync_server}:${REMOTE_BACKUP_DIR}/") # … log it - log "SYNC_TASKS - ${sync_name} Rsync main command : ${rsync_bin} ${rsync_main_args[*]}" + log "SYNC_TASKS - \"${sync_name}\" Rsync main command : ${rsync_bin} ${rsync_main_args[*]}" # … execute it ${rsync_bin} "${rsync_main_args[@]}" @@ -315,7 +321,7 @@ sync() { setup() { # Default return-code (0 == succes) - declare -i GLOBAL_RC=0 + GLOBAL_RC=0 # Possible error codes readonly E_NOSRVAVAIL=21 # No server is available @@ -376,6 +382,12 @@ setup() { # Enable/disable mtree (default: enabled) : "${MTREE_ENABLED:=1}" + # If "setup_custom" exists and is a function, let's call it + setup_custom_type="$(type -t setup_custom)" + if [ "${setup_custom_type}" = "function" ]; then + setup_custom + fi + ## Force umask umask 077 @@ -385,6 +397,7 @@ setup() { trap "clean_temp_files" EXIT } + main() { # Start timer START_EPOCH=$(/bin/date +%s) diff --git a/client/zzz_evobackup.sh b/client/zzz_evobackup.sh index 83d4944..ba08fa6 100644 --- a/client/zzz_evobackup.sh +++ b/client/zzz_evobackup.sh @@ -186,12 +186,12 @@ local_tasks() { ########## Network ################ # Dump network routes with mtr and traceroute (warning: could be long with aggressive firewalls) - ### dump_traceroute + dump_traceroute ########## Server state ########### # Run dump-server-state to extract system information - ### dump_server_state + dump_server_state # Dump file access control lists ### dump_facl @@ -235,24 +235,31 @@ local_tasks() { ### log "LOCAL_TASKS - stop ${dump_file}" ### } -########## Libraries ################################################## - -source ./lib/utilities.sh -source ./lib/dump.sh -source ./lib/main.sh - ########## Optional configuration ##################################### -# If you set a value (like "linux", "openbsd"…) it will be used, -# Default: uname(1) in lowercase. -### SYSTEM="linux" +setup_custom() { + # If you set a value (like "linux", "openbsd"…) it will be used, + # Default: uname(1) in lowercase. + ### SYSTEM="linux" -# If you set a value it will be used, -# Default: hostname(1). -### HOSTNAME="example-host" + # If you set a value it will be used, + # Default: hostname(1). + ### HOSTNAME="example-host" -# Email subect for notifications -### MAIL_SUBJECT="[info] EvoBackup - Client ${HOSTNAME}"}" + # Email subect for notifications + ### MAIL_SUBJECT="[info] EvoBackup - Client ${HOSTNAME}" + + # No-op in case nothing is executed + : +} + +########## Libraries ################################################## + +# Change this to wherever you install the libraries +LIBDIR="./lib" + +source "${LIBDIR}/main.sh" + +########## Let's go! ################################################## -# Call main function main \ No newline at end of file