From 78d2c944c0ed290b109bde7afac4e1be02475554 Mon Sep 17 00:00:00 2001 From: FailedProxy Date: Sun, 5 Apr 2026 06:39:30 +0000 Subject: [PATCH] moved some things to common.sh --- Master.conf | 2 +- Orchestrators/daily_sync.sh | 10 ---------- Rsync/rsync.sh | 5 ++++- common.sh | 31 +++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Master.conf b/Master.conf index 10e8a84..0393be5 100644 --- a/Master.conf +++ b/Master.conf @@ -18,7 +18,7 @@ # ------------------ Git, Pull & Execute Script ----------------- REPO_SSH="git@192.168.50.2:FailedProxy/Unraid_Scripts.git" TARGET_DIR="/mnt/user/appdata/unraid_scripts" - SSH_KEY="/root/.ssh/id_gitea_rsync" + GITEA_SSH_KEY="/root/.ssh/id_gitea_rsync" SSH_PORT=221 # -------------------Rsync Script Defaults----------------------- diff --git a/Orchestrators/daily_sync.sh b/Orchestrators/daily_sync.sh index 6097a74..d3f7dd3 100644 --- a/Orchestrators/daily_sync.sh +++ b/Orchestrators/daily_sync.sh @@ -14,16 +14,6 @@ source "$SCRIPT_DIR/../common.sh" RSYNC_SCRIPT="$SCRIPT_DIR/../Rsync/rsync.sh" -# ----------------------------------------------------------------------------------------------- -# Duration Formatter -# ----------------------------------------------------------------------------------------------- -format_duration() { - local secs=$1 - local mins=$((secs / 60)) - local rem=$((secs % 60)) - [[ $mins -gt 0 ]] && echo "${mins}m${rem}s" || echo "${rem}s" -} - # ----------------------------------------------------------------------------------------------- # Tracking # ----------------------------------------------------------------------------------------------- diff --git a/Rsync/rsync.sh b/Rsync/rsync.sh index 4f9ed55..f6ca990 100644 --- a/Rsync/rsync.sh +++ b/Rsync/rsync.sh @@ -29,6 +29,7 @@ parse_args "${RAW_ARGS[@]}" detect_hosts resolve_remote_ip +check_connectivity # ----------------------------------------------------------------------------------------------- # Profile resolution — inferred from the directory basename @@ -74,6 +75,8 @@ START=$(date +%s) RSYNC_SUCCESS=false for i in $(seq 1 "$RETRY_COUNT"); do + # dirname "$DIRECTORY" is intentional — rsync recreates the final directory on the remote + # e.g. source /mnt/user/Movies → remote receives /mnt/user/Movies (not /mnt/user/Movies/Movies) if rsync "${RSYNC_OPTS[@]}" \ -e "ssh -i $SSH_KEY -T -o Compression=no -o IPQoS=throughput" \ "$DIRECTORY" "root@${REMOTE_SERVER}:$(dirname "$DIRECTORY")/"; then @@ -94,7 +97,7 @@ echo "" echo "===== SUMMARY =====" echo "Directory: $DIRECTORY" echo "Profile: $PROFILE_NAME" -echo "Duration: $((END - START))s" +echo "Duration: $(format_duration $((END - START)))" if [[ "$RSYNC_SUCCESS" == true ]]; then echo "Status: $ICON_SUCCESS DONE" else diff --git a/common.sh b/common.sh index 8e00168..6960f9c 100644 --- a/common.sh +++ b/common.sh @@ -2,6 +2,11 @@ # ----------------------------------------------------------------------------------------------- # ----------------- UNRAID OPS COMMON LIBRARY (STABLE FRAMEWORK v1) ---------------------------- # ----------------------------------------------------------------------------------------------- +# Version: 1.1 +# Changed: format_duration moved here from daily_sync.sh for shared use +# SSH_KEY collision documented — gitea key renamed GITEA_SSH_KEY in Master.conf +# Version and changelog tracking added +# ----------------------------------------------------------------------------------------------- # ICONS ICON_INFO="ℹ️" @@ -24,6 +29,18 @@ log() { [[ "${ENABLE_LOGGING:-false}" == true ]] && echo "[LOG] $*" } +# ----------------------------------------------------------------------------------------------- +# DURATION FORMATTER +# Converts raw seconds to human readable format — e.g. 10m53s or 47s +# Used by rsync.sh and daily_sync.sh +# ----------------------------------------------------------------------------------------------- +format_duration() { + local secs=$1 + local mins=$((secs / 60)) + local rem=$((secs % 60)) + [[ $mins -gt 0 ]] && echo "${mins}m${rem}s" || echo "${rem}s" +} + # ----------------------------------------------------------------------------------------------- # ARG PARSER # ----------------------------------------------------------------------------------------------- @@ -118,6 +135,20 @@ resolve_remote_ip() { info "Remote IP: $REMOTE_SERVER" } +# ----------------------------------------------------------------------------------------------- +# CONNECTIVITY CHECK +# Verifies remote is reachable before attempting rsync. +# Prevents retry loop burning all attempts against an unreachable host. +# ----------------------------------------------------------------------------------------------- +check_connectivity() { + log "Checking connectivity to $REMOTE_SERVER..." + if ! ping -c1 -W3 "$REMOTE_SERVER" &>/dev/null; then + error "Remote $REMOTE_SERVER is unreachable — aborting" + exit 1 + fi + log "Remote is reachable" +} + # ----------------------------------------------------------------------------------------------- # CONTAINERS # CRITICAL_CONTAINER_NAMES and DELAYED_CONTAINERS must be bash arrays before calling these.