#!/bin/bash # This script is not meant to be executed directly. It should be sourced by other scripts. # Single notification function notify() { local title="$1" message="$2" priority="${3:-5}" [ -n "${GOTIFY_URL:-}" ] && [ -n "${GOTIFY_TOKEN:-}" ] || return 0 curl -sS "$GOTIFY_URL/message?token=$GOTIFY_TOKEN" \ -F "title=$title" -F "message=$message" -F "priority=$priority" \ >/dev/null 2>&1 || true } # Pre-warm rclone connection function pre_warm_connection() { local script_title="$1" echo "Pre-warming rclone connection to MEGA..." local prewarm_success=false for attempt in 1 2 3; do echo "Connection attempt $attempt/3..." if timeout 120 rclone ls backup_remote: >/dev/null 2>&1; then echo "✓ Connection established on attempt $attempt" prewarm_success=true break else echo "✗ Attempt $attempt failed" [ $attempt -lt 3 ] && sleep 30 fi done if [ "$prewarm_success" = false ]; then echo "Warning: All pre-warm attempts failed. Operation may be slower or fail." notify "$script_title ($(whoami)@$(hostname))" "Pre-warm connection failed - operation may have issues" 6 fi }