This commit is contained in:
2026-03-24 20:55:33 +00:00
parent 4a012333bc
commit 2d51ec5c6f
2 changed files with 18 additions and 25 deletions
+12 -16
View File
@@ -1,22 +1,11 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------
# --------------------- Common Shared Functions for Unraid Scripts -----------------------------
#-----------------------------------------------------------------------------------------------
# This file contains ONLY reusable logic.
# No code should execute on load — only functions.
# All user configuration lives in Master.conf
#-----------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------
# Load Master.conf
#-----------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------
# Load Master.conf reliably
#-----------------------------------------------------------------------------------------------
# Load Master.conf
load_master_conf() {
# Hardcode the full path to your Master.conf
# Use absolute path to avoid "not found" errors
local master_conf="/mnt/user/appdata/unraid_scripts/Master.conf"
if [ -f "$master_conf" ]; then
@@ -28,7 +17,7 @@ load_master_conf() {
fi
}
# Parse CLI arguments (flags + VAR=value overrides)
# Parse CLI args (flags + VAR=value overrides)
parse_args() {
DRY_RUN=${DRY_RUN:-false}
for ARG in "$@"; do
@@ -63,7 +52,7 @@ validate_int() {
fi
}
# Require variable to be set
# Require variable
require_var() {
local var="$1"
if [[ -z "${!var:-}" ]]; then
@@ -72,9 +61,10 @@ require_var() {
fi
}
# Detect local/remote host and SSH key
# Detect local hostname
detect_hosts() {
LOCAL_HOSTNAME="$(hostname)"
if [[ "$LOCAL_HOSTNAME" == "$HOST1" ]]; then
LOCAL_SERVER_NAME="$HOST1"
REMOTE_SERVER_NAME="$HOST2"
@@ -96,7 +86,13 @@ detect_hosts() {
fi
echo "Resolved $REMOTE_SERVER_NAME$REMOTE_SERVER"
# SSH key lookup
# SSH key mapping
if ! declare -A SSH_KEYS &>/dev/null; then
declare -A SSH_KEYS
SSH_KEYS["$HOST1|$HOST2"]="/root/.ssh/Gmer4Lfe-rsync-key"
SSH_KEYS["$HOST2|$HOST1"]="/root/.ssh/Jayred365-rsync-key"
fi
KEY_ID="$LOCAL_SERVER_NAME|$REMOTE_SERVER_NAME"
if [[ -n "${SSH_KEYS[$KEY_ID]}" ]]; then
SSH_KEY="${SSH_KEYS[$KEY_ID]}"