From 3019c8e6ee7be8720ef7b67a1fcc87cb00191f3b Mon Sep 17 00:00:00 2001 From: Eric Renfro Date: Mon, 2 Sep 2024 15:06:33 -0400 Subject: [PATCH] Changing configuration around to cleaner approach --- {scripts => src}/functions.sh | 50 ++++++++++++++++++++++++-- src/srb | 8 +++++ templates/config/{base.cfg => srb.cfg} | 14 ++++---- 3 files changed, 63 insertions(+), 9 deletions(-) rename {scripts => src}/functions.sh (66%) mode change 100644 => 100755 src/srb rename templates/config/{base.cfg => srb.cfg} (80%) diff --git a/scripts/functions.sh b/src/functions.sh similarity index 66% rename from scripts/functions.sh rename to src/functions.sh index ee99ee5..989f9fc 100644 --- a/scripts/functions.sh +++ b/src/functions.sh @@ -1,13 +1,59 @@ -#!/bin/bash +#!/bin/bash + +########################################################### +### Default global configuration definitions +########################################################### + +restic_version="0.17.0" +resticprofile_version="0.28.0" +systemrescuecd_version="11.02" +backup_engine="resticprofile" + +scriptPath="$(dirname "$(readlink -f "$0")")" +configPath="$(readlink -f "${scriptPath}/../config")" + +if [[ ! -d "${configPath}" ]]; then + # Start searching for common configuration paths + if [[ -r "$HOME/.config/systemrescue-backup/srb.cfg" ]]; then + configPath="$HOME/.config/systemrescue-backup" + elif [[ -r "/etc/systemrescue-backup/srb.cfg" ]]; then + configPath="/etc/systemrescue-backup" + else + echoerr "No configuration file path found. Defaults will be used." 1>&2 + fi +fi + +if [[ -f "${configPath}/srb.cfg" ]]; then + # Fail on any issues loading configuration + trap "echo \"ERROR: Configuration failed to load without error\"" ERR + set -e + source "${configPath}/srb.cfg" + set +e + trap - ERR +fi + ########################################################### ### Utility & Common Functions ########################################################### -function is_bin_in_path { +is_bin_in_path() { builtin type -P "$1" &>/dev/null } +echoerr() { + echo "$*" 1>&2 +} + +exit_fail() { + local rc=$1 + shift + + echoerr "$*" + exit "$rc" +} + + ########################################################### ### BACKUP and RESTORE FUNCTIONS ########################################################### diff --git a/src/srb b/src/srb old mode 100644 new mode 100755 index 4201e8d..603c561 --- a/src/srb +++ b/src/srb @@ -1,4 +1,12 @@ #!/bin/bash scriptPath="$(dirname "$(readlink -f "$0")")" +#configPath="$(dirname "$(readlink -f "${scriptPath}/../config")")" + +if [[ -r "${scriptPath}/functions.sh" ]]; then + source "${scriptPath}/functions.sh" +else + echo "FATAL: Cannot find installed engine." + exit 255 +fi diff --git a/templates/config/base.cfg b/templates/config/srb.cfg similarity index 80% rename from templates/config/base.cfg rename to templates/config/srb.cfg index b9e1832..4e10f58 100644 --- a/templates/config/base.cfg +++ b/templates/config/srb.cfg @@ -2,17 +2,17 @@ # This is where persistent larger files reside. Including the SystemRescueCD and Backup ISO's reside. # NOTE: This is not where actual backups will reside. -systemrescueBaseDir="/var/backups/systemrescue-backup" +systemrescue_data_dir="/var/backups/systemrescue-backup" # Backup Engine to use: # Options are either resticprofile or borgmatic. -backupEngine="resticprofile" +backup_engine="resticprofile" # ResticProfile Options: # These are versions of restic and resticprofile to download and use with the # SystemRescueBackup recovery image. -resticVersion="0.17.0" -resticprofileVersion="0.28.0" +restic_version="0.17.0" +resticprofile_version="0.28.0" # Borgmatic Options: # This is the SystemRescueBackup SRM Module to include in the recovery image. @@ -21,12 +21,12 @@ resticprofileVersion="0.28.0" # cowpacman2srm borgmatic.srm # And upon success, copy the borgmatic.srm to your host system and provide # the path to it here: -borgmaticSRM="" +borgmatic_srm="" # SystemRescueCD Version to Download and Use. If you're using borgmatic, this # version will be relevant to the previously provided borgmaticSRM module. -systemrescueVersion="11.02" +systemrescuecd_version="11.02" # Temporary working directory, mostly for downloads to generate the # SystemRescueBackup disc image. -systemrescueTempDir="/tmp/systemrescue-backup" +systemrescue_temp_dir="/tmp/systemrescue-backup"