From 1d57613a42dc57bef0f9e9e6bbdf612701edfe0e Mon Sep 17 00:00:00 2001 From: FailedProxy Date: Fri, 27 Mar 2026 21:34:03 +0000 Subject: [PATCH] test --- common.sh | 117 ++++++++++++++++++++++++++---------------------------- 1 file changed, 56 insertions(+), 61 deletions(-) diff --git a/common.sh b/common.sh index 222a333..ef88256 100644 --- a/common.sh +++ b/common.sh @@ -13,17 +13,22 @@ ICON_STOP="🛑" ICON_STOPPED="🟢" ICON_SYNC="🔄" -# ----------------------------- OUTPUT ----------------------------- +# ----------------------------- LOGGING ----------------------------- info() { echo "$ICON_INFO [INFO] $*"; } warn() { echo "$ICON_WARN [WARN] $*"; } error() { echo "$ICON_ERROR [ERROR] $*"; } success() { echo "$ICON_SUCCESS [OK] $*"; } +log() { [[ "${ENABLE_LOGGING:-false}" == true ]] && echo "[LOG] $*"; } -log() { - [[ "${ENABLE_LOGGING:-false}" == true ]] && echo "[LOG] $*" -} +# ----------------------------- LOAD MASTER CONFIG ----------------------------- +# MUST be defined before calling engine +# Example: +# source /boot/config/master.conf +if [[ -n "${MASTER_CONF_PATH:-}" ]]; then + source "$MASTER_CONF_PATH" +fi -# ----------------------------- ARG PARSER ----------------------------- +# ----------------------------- ARG PARSING ----------------------------- parse_args() { ENABLE_LOGGING=${ENABLE_LOGGING:-false} DRY_RUN=${DRY_RUN:-false} @@ -32,43 +37,18 @@ parse_args() { CLEAN_ARGS=() for ARG in "$@"; do - if [[ "$ARG" == *=* ]]; then - VAR="${ARG%%=*}" - VAL="${ARG#*=}" - - case "$VAR" in - LOG) - [[ "$VAL" == "true" ]] && ENABLE_LOGGING=true - [[ "$VAL" == "false" ]] && ENABLE_LOGGING=false - ;; - *) - if declare -p "$VAR" &>/dev/null; then - printf -v "$VAR" '%s' "$VAL" - log "Set $VAR=$VAL" - else - warn "Unknown variable: $VAR" - fi - ;; - esac - else - case "$ARG" in - --dry-run|-n) DRY_RUN=true ;; - --log) ENABLE_LOGGING=true ;; - --no-log) ENABLE_LOGGING=false ;; - --status|--summary) SHOW_STATUS=true ;; - *) CLEAN_ARGS+=("$ARG") ;; - esac - fi + case "$ARG" in + --dry-run|-n) DRY_RUN=true ;; + --log) ENABLE_LOGGING=true ;; + --no-log) ENABLE_LOGGING=false ;; + --status) SHOW_STATUS=true ;; + *) CLEAN_ARGS+=("$ARG") ;; + esac done PARSED_ARGS=("${CLEAN_ARGS[@]}") } -# ----------------------------- VALIDATION ----------------------------- -require_var() { - [[ -z "${!1:-}" ]] && error "Missing required: $1" && exit 1 -} - # ----------------------------- HOST DETECTION ----------------------------- detect_hosts() { LOCAL_HOSTNAME="$(hostname)" @@ -95,7 +75,7 @@ detect_hosts() { info "Host: $LOCAL_SERVER_NAME → $REMOTE_SERVER_NAME" } -# ----------------------------- REMOTE ----------------------------- +# ----------------------------- REMOTE RESOLVE ----------------------------- resolve_remote_ip() { REMOTE_SERVER=$(tailscale ip -4 "$REMOTE_SERVER_NAME" 2>/dev/null) [[ -z "$REMOTE_SERVER" ]] && error "Failed to resolve remote IP" && exit 1 @@ -168,57 +148,72 @@ wait_for_rsync() { exit 1 } -# ----------------------------- PROFILE CONFIG ----------------------------- -declare -A PROFILE_BW_LIMIT=( - [arrs_stack]=5000 - [critical-data]=9500 - [gmer4lfe]=8000 - [important-data]=9500 - [emby]=8000 -) +# ----------------------------------------------------------------------------------------------- +# ----------------------------- DEFAULT RSYNC OPTIONS ------------------------------------------- +# ----------------------------------------------------------------------------------------------- DEFAULT_RSYNC_OPTS=( --archive --delete --partial --compress + --info=progress2 + --stats ) -# ----------------------------- RSYNC OPTIONS ----------------------------- +# ----------------------------------------------------------------------------------------------- +# ----------------------------- PROFILE HANDLING (FROM MASTER.CONF) ------------------------------ +# ----------------------------------------------------------------------------------------------- + get_rsync_opts() { - RSYNC_OPTS=() - - # base profile options RSYNC_OPTS=("${DEFAULT_RSYNC_OPTS[@]}") - # bwlimit (FIXED + ALWAYS APPLIED) + # Ensure profile map exists + if [[ -z "${PROFILE_BW_LIMIT[*]}" ]]; then + warn "PROFILE_BW_LIMIT missing from Master.conf - using unlimited" + declare -A PROFILE_BW_LIMIT + fi + BW_LIMIT="${PROFILE_BW_LIMIT[$PROFILE_NAME]:-0}" if [[ "$BW_LIMIT" -gt 0 ]]; then RSYNC_OPTS+=(--bwlimit="$BW_LIMIT") - log "bwlimit=${BW_LIMIT}KB/s applied" + log "bwlimit=${BW_LIMIT}KB/s applied (profile: $PROFILE_NAME)" + else + log "bwlimit unlimited (profile: $PROFILE_NAME)" fi - # clean progress mode if [[ "${ENABLE_PROGRESS:-false}" == true ]]; then - RSYNC_OPTS+=( - --quiet - --info=progress2,name0,stats0 - --human-readable - --no-inc-recursive - ) log "Progress mode enabled" fi } +# ----------------------------- RSYNC EXECUTION (FIXED OUTPUT) ----------------------------- +run_rsync() { + + wait_for_rsync + get_rsync_opts + + echo "🚀 Running rsync..." + + # IMPORTANT FIX: + # - no --quiet + # - no output suppression + # - direct execution for real-time streaming + + rsync "${RSYNC_OPTS[@]}" \ + "$SRC/" \ + "root@$REMOTE_SERVER:$DEST/" +} + # ----------------------------- STATUS ----------------------------- show_status() { - echo "===== STATUS =====" + echo "===== SYNC STATUS =====" echo "Local: $LOCAL_SERVER_NAME" echo "Remote: $REMOTE_SERVER_NAME" echo "IP: $REMOTE_SERVER" echo "Profile: $PROFILE_NAME" echo "Progress: ${ENABLE_PROGRESS:-false}" - echo "==================" + echo "=======================" } \ No newline at end of file