Structure Changes

This commit is contained in:
2026-03-21 20:10:18 +00:00
parent 798517baf5
commit 546686ac8c
4 changed files with 123 additions and 235 deletions
+51 -30
View File
@@ -1,8 +1,28 @@
#!/bin/bash
set -e
#-----------------------------------------------------------------------------------------------
#----------------- User Variables, Please adjust in Master.cong as needed ----------------------
#-----------------------------------------------------------------------------------------------
#
# User vaiables can be adjusted in Master.conf
# scripts now just contain runtime codes
#
# This allows for profiles and multiple things to use the core script
# use arguments in unRAID User Plugin for directory
# Example = /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh
# /mnt/user/appdata-Failover/Arrs_Stack/
#
# /mnt/user/appdata-Failover/Arrs_Stack/ is the argument
# If the last name /Arrs-Stack/ matches a profile in Master.conf then profiles are used
# If no matches then Global Configureation is used in Master.conf
#
#-----------------------------------------------------------------------------------------------
#---------------End Of User Variables, Please adjust in Master.cong as needed ------------------
#-----------------------------------------------------------------------------------------------
# Detect script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Load Master.conf from Git repo
# Load Master.conf
MASTER_CONF="$SCRIPT_DIR/../Master.conf"
if [ -f "$MASTER_CONF" ]; then
source "$MASTER_CONF"
@@ -11,24 +31,27 @@ else
echo "Error: Master.conf not found at $MASTER_CONF"
exit 1
fi
# Input Arguments & Directory
DIRECTORY="$1" # Directory to sync
# Input Arguments
DIRECTORY="$1" # Directory to sync
if [[ -z "$DIRECTORY" ]]; then
echo "Usage: $0 <directory-to-sync> [--dry-run] [VAR=value ...]"
exit 1
fi
# Optional dry-run
DRY_RUN=false
# Handle optional dry-run
if [[ "$2" == "--dry-run" ]]; then
shift 1
if [[ "$1" == "--dry-run" ]]; then
DRY_RUN=true
shift 1
fi
# Handle optional variable overrides: VAR=value format
for ARG in "${@:2}"; do
# Optional variable overrides: VAR=value
for ARG in "$@"; do
if [[ "$ARG" == *=* ]]; then
VAR_NAME="${ARG%%=*}"
VAR_VALUE="${ARG#*=}"
# Only override if variable already exists
if declare -p "$VAR_NAME" &>/dev/null; then
eval "$VAR_NAME=\"$VAR_VALUE\""
echo "Overriding $VAR_NAME -> $VAR_VALUE"
@@ -38,19 +61,20 @@ for ARG in "${@:2}"; do
fi
done
#-----------------------------------------------------------------------------------------------
#----------------------------- User Variables, Please adjust as needed -------------------------
#-----------------------------------------------------------------------------------------------
#---------------------------- These variables Over Ride The Master.conf ------------------------
#-----------------------------------------------------------------------------------------------
CRITICAL_CONTAINER_NAMES=("Sonarr" "Lidarr" "Readarr" "Radarr" "Prowlarr" "Bazarr" "Pinchflat")
DELAYED_CONTAINERS=("")
EXCLUDE_DIRS=("")
#-----------------------------------------------------------------------------------------------
#---------------------------- These variables Over Ride The Master.conf ------------------------
#-----------------------------------------------------------------------------------------------
#------------------------End Of User Variables, Please adjust Above as needed ------------------
#-----------------------------------------------------------------------------------------------
# Determine profile
PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]')
echo "Detected profile: $PROFILE_NAME"
# Apply profile defaults or fallback to master.conf
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]})
DELAYED_CONTAINERS=(${PROFILE_DELAYED_CONTAINERS[$PROFILE_NAME]})
CONTAINER_DELAY=${PROFILE_CONTAINER_DELAY[$PROFILE_NAME]:-$CONTAINER_DELAY}
RETRY_COUNT=${PROFILE_RETRY_COUNT[$PROFILE_NAME]:-$RETRY_COUNT}
SLEEP=${PROFILE_SLEEP[$PROFILE_NAME]:-$SLEEP}
echo "Settings: MAX_RSYNC_PROCS=$MAX_RSYNC_PROCS, BW_LIMIT=$BW_LIMIT, CONTAINERS=${CRITICAL_CONTAINER_NAMES[*]}"
# Dependency check
for cmd in rsync ssh ping timeout docker tailscale; do
@@ -62,11 +86,11 @@ done
trap 'echo "Script interrupted. Exiting."; exit 130' INT TERM
#------------------------- Helper Functions -------------------------
# Helper functions
wait_for_rsync() {
for attempt in $(seq 1 "$RETRY_COUNT"); do
RSYNC_COUNT=$(pgrep -fc "rsync.*root@${REMOTE_SERVER}" || true)
if [ "$RSYNC_COUNT" -gt "$MAX_RSYNC_PROCS" ]; then
if [ "$RSYNC_COUNT" -ge "$MAX_RSYNC_PROCS" ]; then
echo "[$LOCAL_SERVER_NAME] Waiting... ($RSYNC_COUNT active rsync processes)"
sleep "$SLEEP"
else
@@ -78,7 +102,7 @@ wait_for_rsync() {
}
check_server_online() {
timeout 5 ping -c 1 "$REMOTE_SERVER" &> /dev/null
timeout 5 ping -c 1 "$REMOTE_SERVER" &>/dev/null
}
declare -a RUNNING_CONTAINERS=()
@@ -108,7 +132,8 @@ start_containers() {
done
}
#------------------------- Main -------------------------
# Main sync logic
main() {
echo "[$LOCAL_SERVER_NAME] Syncing $DIRECTORY$REMOTE_SERVER:$DIRECTORY"
@@ -135,10 +160,6 @@ main() {
--no-whole-file
)
for ex in "${EXCLUDE_DIRS[@]}"; do
RSYNC_OPTS+=(--exclude="$ex")
done
[ "$DRY_RUN" = true ] && RSYNC_OPTS+=("--dry-run")
for attempt in $(seq 1 "$RETRY_COUNT"); do
@@ -165,5 +186,5 @@ main() {
echo "[$LOCAL_SERVER_NAME] Sync complete."
}
# Run
# Execute
main