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
+6 -9
View File
@@ -6,25 +6,21 @@ source "$SCRIPT_DIR/../common.sh"
# Load config
load_master_conf
detect_hosts
parse_args "$@"
# Input directory
DIRECTORY="$1"
if [[ -z "$DIRECTORY" ]]; then
echo "Usage: $0 <directory-to-sync> [--dry-run|-n] [VAR=value ...]"
exit 1
fi
shift
parse_args "$@"
# Detect hosts & SSH key
detect_hosts
# Determine profile
DIR_CLEAN="${DIRECTORY%/}"
PROFILE_NAME=$(basename "$DIR_CLEAN" | tr '[:upper:]' '[:lower:]')
# Determine profile from folder basename
PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]')
echo "Detected profile: $PROFILE_NAME"
# Apply profile defaults
# Apply profile settings
MAX_RSYNC_PROCS=${PROFILE_MAX_PROCS[$PROFILE_NAME]:-$MAX_RSYNC_PROCS}
BW_LIMIT=${PROFILE_BW_LIMIT[$PROFILE_NAME]:-$BW_LIMIT}
CRITICAL_CONTAINER_NAMES=(${PROFILE_CRITICAL_CONTAINER_NAMES[$PROFILE_NAME]})
@@ -34,6 +30,7 @@ RETRY_COUNT=${PROFILE_RETRY_COUNT[$PROFILE_NAME]:-$RETRY_COUNT}
SLEEP=${PROFILE_SLEEP[$PROFILE_NAME]:-$SLEEP}
EXCLUDE_DIRS=(${PROFILE_EXCLUDE_DIRS[$PROFILE_NAME]:-${EXCLUDE_DIRS[@]}})
# Validate
validate_int MAX_RSYNC_PROCS "$MAX_RSYNC_PROCS"
validate_int BW_LIMIT "$BW_LIMIT"
+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]}"