From 2d51ec5c6fc35022dceb4c2cd1cfcd8e1f9c6dd3 Mon Sep 17 00:00:00 2001 From: FailedProxy Date: Tue, 24 Mar 2026 20:55:33 +0000 Subject: [PATCH] U --- Rsync/rsync.sh | 15 ++++++--------- common.sh | 28 ++++++++++++---------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/Rsync/rsync.sh b/Rsync/rsync.sh index 5c9cbb7..758c468 100644 --- a/Rsync/rsync.sh +++ b/Rsync/rsync.sh @@ -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 [--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" diff --git a/common.sh b/common.sh index 5d2bb44..784c8a3 100644 --- a/common.sh +++ b/common.sh @@ -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]}"