This commit is contained in:
2026-03-24 01:17:22 +00:00
parent 038acb6b5e
commit 21de9b39dc
2 changed files with 56 additions and 93 deletions
+9 -60
View File
@@ -3,56 +3,40 @@
#----------------------------- Master Variables for unRAID scripts ----------------------------- #----------------------------- Master Variables for unRAID scripts -----------------------------
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# Hostnames of both servers, used for SSH key mapping and remote detection (Actual UunRAID's Host Names) #-------------------- Host Configuration --------------------
# Hostnames of both servers
HOST1="unRAID-Gmer4Lfe" HOST1="unRAID-Gmer4Lfe"
HOST2="unRAID-Jayred365" HOST2="unRAID-Jayred365"
# SSH Key Mapping (used for rsync scripts to determine which SSH key to use based on source and destination) # SSH Key Mapping (data only)
declare -A SSH_KEYS declare -A SSH_KEYS
SSH_KEYS["unRAID-Gmer4Lfe|unRAID-Jayred365"]="/root/.ssh/Gmer4Lfe-rsync-key" SSH_KEYS["unRAID-Gmer4Lfe|unRAID-Jayred365"]="/root/.ssh/Gmer4Lfe-rsync-key"
SSH_KEYS["unRAID-Jayred365|unRAID-Gmer4Lfe"]="/root/.ssh/Jayred365-rsync-key" SSH_KEYS["unRAID-Jayred365|unRAID-Gmer4Lfe"]="/root/.ssh/Jayred365-rsync-key"
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
#----------------- User Variables, Please adjust here in Master.conf as needed ----------------- #----------------- User Variables --------------------------------------------------------------
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
#--------------------Rsync Script Defaults----------------------- #-------------------- Rsync Defaults -----------------------
# Network speed limit (KB/s)
BW_LIMIT=12500 BW_LIMIT=12500
# Retry logic
RETRY_COUNT=3 RETRY_COUNT=3
# Sleep between retries (seconds)
SLEEP=300 SLEEP=300
# Max number of concurrently running rsync processes
MAX_RSYNC_PROCS=1 MAX_RSYNC_PROCS=1
# Container start/stop/restart before and after rsync
CRITICAL_CONTAINER_NAMES=("") CRITICAL_CONTAINER_NAMES=("")
# Containers that need delayed before starting
DELAYED_CONTAINERS=("") DELAYED_CONTAINERS=("")
# Delay in seconds between starting containers, useful for things like Authelia
CONTAINER_DELAY=5 CONTAINER_DELAY=5
# Not include logs during transfer
EXCLUDE_DIRS=("") EXCLUDE_DIRS=("")
#-------------------- unRAID essentail scripts ------------------ #-------------------- Essential Scripts ------------------
# unRAID reboot script user warning time (seconds)
REBOOT_SLEEP=300 REBOOT_SLEEP=300
# unRAID mover stop script timeout (seconds)
MOVER_STOP_TIMEOUT=300 MOVER_STOP_TIMEOUT=300
# docker_syslog_filter.sh filter file path
FILTER_FILE="/etc/rsyslog.d/ignore-docker-veth.conf" FILTER_FILE="/etc/rsyslog.d/ignore-docker-veth.conf"
# php_fpm_max_children.sh php-fpm config file path
PHP_CONF="/etc/php-fpm.d/www.conf" PHP_CONF="/etc/php-fpm.d/www.conf"
# php_fpm_max_children.sh max children value
PHP_MAX_CHILDREN=250 PHP_MAX_CHILDREN=250
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
#----------------------------------- Profile System ------------------------------------------- #----------------------------------- Profile System -------------------------------------------
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Profiles are mainly used for rsync operations, but can be used for any variable that needs
# to be different based on the source or destination.
#
# Profiles are inferred from the directory basename (lowercased)
declare -A PROFILE_MAX_PROCS declare -A PROFILE_MAX_PROCS
PROFILE_MAX_PROCS["arrs_stack"]=2 PROFILE_MAX_PROCS["arrs_stack"]=2
@@ -109,42 +93,7 @@ PROFILE_EXCLUDE_DIRS["critical-data"]="logs *.tmp"
PROFILE_EXCLUDE_DIRS["gmer4lfe"]="logs *.tmp" PROFILE_EXCLUDE_DIRS["gmer4lfe"]="logs *.tmp"
PROFILE_EXCLUDE_DIRS["important-data"]="logs *.tmp" PROFILE_EXCLUDE_DIRS["important-data"]="logs *.tmp"
PROFILE_EXCLUDE_DIRS["emby"]="logs *.tmp" PROFILE_EXCLUDE_DIRS["emby"]="logs *.tmp"
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
#---------------End Of User Variables, Please adjust here in Master.conf as needed ------------- #----------------------------- End of Master.conf ----------------------------------------------
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# Detect local hostname
LOCAL_HOSTNAME="$(hostname)"
if [[ "$LOCAL_HOSTNAME" == "$HOST1" ]]; then
LOCAL_SERVER_NAME="$HOST1"
REMOTE_SERVER_NAME="$HOST2"
elif [[ "$LOCAL_HOSTNAME" == "$HOST2" ]]; then
LOCAL_SERVER_NAME="$HOST2"
REMOTE_SERVER_NAME="$HOST1"
else
echo "Error: Local hostname ($LOCAL_HOSTNAME) not recognized."
exit 1
fi
echo "Local server: $LOCAL_SERVER_NAME"
echo "Remote server: $REMOTE_SERVER_NAME"
# Remote Server Ip Resolution
# Resolve Tailscale IP dynamically
REMOTE_SERVER=$(tailscale ip -4 "$REMOTE_SERVER_NAME" 2>/dev/null)
if [[ -z "$REMOTE_SERVER" ]]; then
echo "Error: Could not resolve Tailscale IP for $REMOTE_SERVER_NAME"
exit 1
fi
# SSH Key Mapping
KEY_ID="$LOCAL_SERVER_NAME|$REMOTE_SERVER_NAME"
if [[ -n "${SSH_KEYS[$KEY_ID]}" ]]; then
SSH_KEY="${SSH_KEYS[$KEY_ID]}"
else
echo "Error: No SSH key defined for $LOCAL_SERVER_NAME → $REMOTE_SERVER_NAME"
exit 1
fi
echo "Using SSH key: $SSH_KEY"
+47 -33
View File
@@ -1,27 +1,13 @@
#!/bin/bash #!/bin/bash
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# --------------------- Common Shared Functions for Unraid Scripts ----------------------------- #--------------------- Common Shared Functions -------------------------------------------------
#-----------------------------------------------------------------------------------------------
#----------------- User Variables, Please adjust in Master.conf as needed ----------------------
#-----------------------------------------------------------------------------------------------
#
# Nothing to adjust here, all user variables should be in Master.conf
#
# This is just a script that has all common functions and logic that are shared
# between the different scripts.
#
# This way we can avoid code duplication and have a single source
# of truth for all common functions and logic.
#-----------------------------------------------------------------------------------------------
#---------------End Of User Variables, Please adjust in Master.conf as needed ------------------
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# Load Master.conf relative to calling script # Load Master.conf
load_master_conf() { load_master_conf() {
local script_dir local script_dir
script_dir="$(cd "$(dirname "${BASH_SOURCE[1]}")" && pwd)" script_dir="$(cd "$(dirname "${BASH_SOURCE[1]}")" && pwd)"
local master_conf="$script_dir/../Master.conf" local master_conf="$script_dir/../Master.conf"
if [ -f "$master_conf" ]; then if [ -f "$master_conf" ]; then
@@ -33,7 +19,7 @@ load_master_conf() {
fi fi
} }
# Parse CLI arguments (flags + VAR=value overrides) # Parse CLI arguments
parse_args() { parse_args() {
DRY_RUN=${DRY_RUN:-false} DRY_RUN=${DRY_RUN:-false}
@@ -43,44 +29,35 @@ parse_args() {
local VAR_VALUE="${ARG#*=}" local VAR_VALUE="${ARG#*=}"
if declare -p "$VAR_NAME" &>/dev/null; then if declare -p "$VAR_NAME" &>/dev/null; then
if [[ "$VAR_NAME" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then printf -v "$VAR_NAME" '%s' "$VAR_VALUE"
printf -v "$VAR_NAME" '%s' "$VAR_VALUE" echo "Overriding $VAR_NAME -> $VAR_VALUE"
echo "Overriding $VAR_NAME -> $VAR_VALUE"
else
echo "Warning: Invalid variable name $VAR_NAME"
fi
else else
echo "Warning: Unknown variable $VAR_NAME, ignoring." echo "Warning: Unknown variable $VAR_NAME, ignoring."
fi fi
else else
case "$ARG" in case "$ARG" in
--dry-run|-n) --dry-run|-n) DRY_RUN=true ;;
DRY_RUN=true
;;
--help|-h) --help|-h)
echo "Usage: script [--dry-run|-n] [VAR=value ...]" echo "Usage: script [--dry-run|-n] [VAR=value ...]"
exit 0 exit 0 ;;
;;
*) *)
echo "Warning: Unknown argument $ARG" echo "Warning: Unknown argument $ARG" ;;
;;
esac esac
fi fi
done done
} }
# Validate integer (non-negative) # Validate integer
validate_int() { validate_int() {
local name="$1" local name="$1"
local value="$2" local value="$2"
if ! [[ "${value:-}" =~ ^[0-9]+$ ]]; then if ! [[ "${value:-}" =~ ^[0-9]+$ ]]; then
echo "Error: $name must be a non-negative integer." echo "Error: $name must be a non-negative integer."
exit 1 exit 1
fi fi
} }
# Optional: require variable to be set # Require variable
require_var() { require_var() {
local var="$1" local var="$1"
if [[ -z "${!var:-}" ]]; then if [[ -z "${!var:-}" ]]; then
@@ -88,3 +65,40 @@ require_var() {
exit 1 exit 1
fi fi
} }
# 🔥 Host + SSH Detection (THE IMPORTANT FIX)
detect_hosts() {
LOCAL_HOSTNAME="$(hostname)"
if [[ "$LOCAL_HOSTNAME" == "$HOST1" ]]; then
LOCAL_SERVER_NAME="$HOST1"
REMOTE_SERVER_NAME="$HOST2"
elif [[ "$LOCAL_HOSTNAME" == "$HOST2" ]]; then
LOCAL_SERVER_NAME="$HOST2"
REMOTE_SERVER_NAME="$HOST1"
else
echo "Error: Local hostname ($LOCAL_HOSTNAME) not recognized."
exit 1
fi
echo "Local server: $LOCAL_SERVER_NAME"
echo "Remote server: $REMOTE_SERVER_NAME"
# Resolve Tailscale IP
REMOTE_SERVER=$(tailscale ip -4 "$REMOTE_SERVER_NAME" 2>/dev/null)
if [[ -z "$REMOTE_SERVER" ]]; then
echo "Error: Could not resolve Tailscale IP for $REMOTE_SERVER_NAME"
exit 1
fi
# Assign SSH key
KEY_ID="$LOCAL_SERVER_NAME|$REMOTE_SERVER_NAME"
if [[ -n "${SSH_KEYS[$KEY_ID]}" ]]; then
SSH_KEY="${SSH_KEYS[$KEY_ID]}"
else
echo "Error: No SSH key defined for $LOCAL_SERVER_NAME$REMOTE_SERVER_NAME"
exit 1
fi
echo "Using SSH key: $SSH_KEY"
}