This commit is contained in:
2026-03-24 20:46:21 +00:00
parent f3955a172b
commit 5d23bf7f58
2 changed files with 41 additions and 133 deletions
+7 -24
View File
@@ -14,20 +14,13 @@
#-----------------------------------------------------------------------------------------------
# Load Master.conf reliably
#-----------------------------------------------------------------------------------------------
# Load Master.conf
load_master_conf() {
# Determine the directory of THIS file (common.sh)
local script_dir
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
local master_conf="$script_dir/../Master.conf"
# Master.conf is assumed to be in the parent directory of unRAID scripts root
# i.e., one level up from where common.sh lives
local master_conf="$script_dir/Master.conf"
if [ ! -f "$master_conf" ]; then
# fallback for Rsync/rsync.sh calling common.sh
master_conf="$script_dir/../Master.conf"
fi
if [ -f "$master_conf" ]; then
if [[ -f "$master_conf" ]]; then
source "$master_conf"
echo "Loaded Master.conf from $master_conf"
else
@@ -36,12 +29,9 @@ load_master_conf() {
fi
}
#-----------------------------------------------------------------------------------------------
# Parse CLI args
#-----------------------------------------------------------------------------------------------
# Parse CLI arguments (flags + VAR=value overrides)
parse_args() {
DRY_RUN=${DRY_RUN:-false}
for ARG in "$@"; do
if [[ "$ARG" == *=* ]]; then
local VAR_NAME="${ARG%%=*}"
@@ -58,16 +48,13 @@ parse_args() {
--help|-h)
echo "Usage: script [--dry-run|-n] [VAR=value ...]"
exit 0 ;;
*)
echo "Warning: Unknown argument $ARG" ;;
*) echo "Warning: Unknown argument $ARG" ;;
esac
fi
done
}
#-----------------------------------------------------------------------------------------------
# Validate integer
#-----------------------------------------------------------------------------------------------
validate_int() {
local name="$1"
local value="$2"
@@ -77,9 +64,7 @@ validate_int() {
fi
}
#-----------------------------------------------------------------------------------------------
# Require variable
#-----------------------------------------------------------------------------------------------
# Require variable to be set
require_var() {
local var="$1"
if [[ -z "${!var:-}" ]]; then
@@ -88,9 +73,7 @@ require_var() {
fi
}
#-----------------------------------------------------------------------------------------------
# Detect local/remote hosts and resolve Tailscale IPs
#-----------------------------------------------------------------------------------------------
# Detect local/remote host and SSH key
detect_hosts() {
LOCAL_HOSTNAME="$(hostname)"
if [[ "$LOCAL_HOSTNAME" == "$HOST1" ]]; then