diff --git a/Rsync/rsync.sh b/Rsync/rsync.sh index 3fc3f4a..022157f 100644 --- a/Rsync/rsync.sh +++ b/Rsync/rsync.sh @@ -1,17 +1,14 @@ #!/bin/bash set -e -#----------------------------------------------------------------------------------------------- -# Main Rsync Script for unRAID -#----------------------------------------------------------------------------------------------- -#--------------------------------------------- +# --------------------------------------------------------------------------------- +# -------------------------- Rsync Script Using Master.conf ------------------------ +# --------------------------------------------------------------------------------- + # Detect script directory -#--------------------------------------------- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -#--------------------------------------------- -# Load Master.conf (hosts, keys, profiles, helpers) -#--------------------------------------------- +# Load Master.conf MASTER_CONF="$SCRIPT_DIR/../Master.conf" if [ -f "$MASTER_CONF" ]; then source "$MASTER_CONF" @@ -21,28 +18,22 @@ else exit 1 fi -#--------------------------------------------- -# Input Arguments: Directory (positional) -#--------------------------------------------- +# ----------------------------- Parse Input Arguments ----------------------------- DIRECTORY="$1" if [[ -z "$DIRECTORY" ]]; then - echo "Usage: $0 [--dry-run|-n] [VAR=value ...]" + echo "Usage: $0 [--dry-run] [VAR=value ...]" exit 1 fi -shift 1 # Remove directory from $@ so parse_args sees only options/VARs +shift 1 -#--------------------------------------------- -# Parse optional arguments (dry-run / VAR=VALUE) -#--------------------------------------------- -parse_args "$@" +# Handle optional flags & variable overrides +parse_args "$DIRECTORY" "$@" -echo "Detected profile: $(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]')" - -#--------------------------------------------- -# Apply profile defaults or fallback to Master.conf -#--------------------------------------------- +# -------------------------- Determine Profile & Settings ------------------------- PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]') +echo "Detected profile: $PROFILE_NAME" +# Profile-specific settings with fallback to global defaults 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]}) @@ -54,9 +45,7 @@ EXCLUDE_DIRS=(${PROFILE_EXCLUDE_DIRS[$PROFILE_NAME]:-${EXCLUDE_DIRS[@]}}) echo "Settings: MAX_RSYNC_PROCS=$MAX_RSYNC_PROCS, BW_LIMIT=$BW_LIMIT, CONTAINERS=${CRITICAL_CONTAINER_NAMES[*]}, EXCLUDES=${EXCLUDE_DIRS[*]}" -#--------------------------------------------- -# Dependency check -#--------------------------------------------- +# --------------------------- Dependency Check ------------------------------------ for cmd in rsync ssh ping timeout docker tailscale; do command -v "$cmd" >/dev/null 2>&1 || { echo "Error: Required command '$cmd' is not installed." @@ -66,9 +55,10 @@ done trap 'echo "Script interrupted. Exiting."; exit 130' INT TERM -#--------------------------------------------- -# Helper Functions -#--------------------------------------------- +# --------------------------------------------------------------------------------- +# ------------------------- RUNTIME LOGIC (DO NOT MODIFY) ------------------------- +# --------------------------------------------------------------------------------- + wait_for_rsync() { for attempt in $(seq 1 "$RETRY_COUNT"); do RSYNC_COUNT=$(pgrep -fc "rsync.*root@${REMOTE_SERVER}" || true) @@ -114,9 +104,6 @@ start_containers() { done } -#--------------------------------------------- -# Main sync logic -#--------------------------------------------- main() { echo "[$LOCAL_SERVER_NAME] Syncing $DIRECTORY → $REMOTE_SERVER:$DIRECTORY" @@ -173,7 +160,5 @@ main() { echo "[$LOCAL_SERVER_NAME] Sync complete." } -#--------------------------------------------- -# Execute -#--------------------------------------------- +# Execute main main \ No newline at end of file