Structure change and vissually fixing code to make it easier to read

This commit is contained in:
2026-03-26 22:35:44 +00:00
parent 84cdc6169b
commit 4ef4c1428c
14 changed files with 253 additions and 141 deletions
+16 -11
View File
@@ -1,7 +1,7 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------
#----------------------------- Master Variables for unRAID scripts -----------------------------
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# ---------------------------- Master Variables for unRAID scripts -----------------------------
# ----------------------------------------------------------------------------------------------
# This is the master.conf file, it contains all the variables used by
# all scripts.
#
@@ -11,11 +11,11 @@
# This is where you should adjust any settings or variables
# that you want to apply globally across all your scripts
#
#-----------------------------------------------------------------------------------------------
#----------------- User Variables, Please adjust here in Master.conf as needed -----------------
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust here in Master.conf as needed -----------------
# ----------------------------------------------------------------------------------------------
#-------------------- Host Configuration --------------------
# ----------------------- Host Configuration --------------------
# List the Hostnames of both servers
HOST1="unRAID-Gmer4Lfe"
HOST2="unRAID-Jayred365"
@@ -24,11 +24,16 @@ HOST2="unRAID-Jayred365"
HOST1_SSH_KEY="/root/.ssh/Gmer4Lfe-rsync-key"
HOST2_SSH_KEY="/root/.ssh/Jayred365-rsync-key"
# -------------------------- Logging ---------------------------
# -------------------------- Logging ----------------------------
ENABLE_LOGGING=true # false = only echo user-facing messages
# ------------------ 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"
SSH_PORT=221
#--------------------Rsync Script Defaults-----------------------
# -------------------Rsync Script Defaults-----------------------
# Network speed limit (KB/s)
BW_LIMIT=12500
# Retry logic
@@ -48,7 +53,7 @@ EXCLUDE_DIRS=("")
# Default global rsync options
DEFAULT_RSYNC_OPTS=(-av --info=progress2 --human-readable --bwlimit="$BW_LIMIT" --delete --inplace --no-whole-file)
#-------------------- unRAID essentail scripts ------------------
# ------------------- unRAID essentail scripts ------------------
# unRAID reboot script user warning time (seconds)
REBOOT_SLEEP=300
# unRAID mover stop script timeout (seconds)
@@ -60,7 +65,7 @@ PHP_CONF="/etc/php-fpm.d/www.conf"
# php_fpm_max_children.sh max children value
PHP_MAX_CHILDREN=250
#---------------------- Profile System -------------------------
# --------------------- Profile System -------------------------
# Profiles are inferred from the directory basename (lowercased)
# Profile-specific rsync options (override global) must list all options as they do not inherit from global
# For example, look up at global rsync options above
+5
View File
@@ -16,3 +16,8 @@ This opens the script and passes the folder overas an argument
This allows for multiple rsync ops running off a single core script
All changes made to 1 single core script then works for all user scripts that point to rsync.sh
The Master.conf file is where all user changeable variables live, This is for all scripts
A common.sh file also is used to share all common codes that multiple scripts use
This allows for easier managment of scripts, editing, and what not
+88 -26
View File
@@ -1,37 +1,99 @@
#!/bin/bash
set -e
# ----------------------------------------------------------------------------------------------
# --------------------------------- Git, Pull & Exectute Script --------------------------------
# ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust in Master.conf as needed ----------------------
# ----------------------------------------------------------------------------------------------
#
# User variables can be adjusted in Master.conf
#
# Scripts now just contain runtime logic
#
# This new setup allows for profiles and arguments to use the core script
# ----------------------------------------------------------------------------------------------
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
# ----------------------------------------------------------------------------------------------
#!/bin/bash
set -e
# -----------------------------
# Configurable variables
# -----------------------------
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"
SSH_PORT=221
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Core System
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
parse_args "$@"
# Status Mode
echo "===== GIT SYNC STATUS ====="
echo "Repo: $REPO_SSH"
echo "Target: $TARGET_DIR"
echo "SSH Key: $SSH_KEY"
echo "SSH Port: $SSH_PORT"
echo "Logging: $ENABLE_LOGGING"
echo "Dry Run: $DRY_RUN"
echo "==========================="
exit 0
fi
# Validation
require_var REPO_SSH
require_var TARGET_DIR
require_var SSH_KEY
require_var SSH_PORT
# Start
info "Starting repository sync"
log "Repo: $REPO_SSH"
log "Target: $TARGET_DIR"
# -----------------------------
# Create target directory if it doesn't exist
# -----------------------------
mkdir -p "$TARGET_DIR"
cd "$TARGET_DIR"
# -----------------------------
# Clone or pull repo (discard local changes)
# -----------------------------
if [ -d ".git" ]; then
echo "Repository already exists. Resetting local changes and pulling latest..."
git reset --hard
git clean -fd
GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" git pull
else
echo "Cloning $REPO_SSH into $TARGET_DIR..."
GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" git clone "$REPO_SSH" .
# Dry Run
if [[ "$DRY_RUN" == true ]]; then
info "Dry-run mode enabled"
info "Would sync repository: $REPO_SSH"
info "Would target directory: $TARGET_DIR"
exit 0
fi
# -----------------------------
# Ensure scripts are executable
# -----------------------------
echo "Setting executable permissions on scripts..."
# Git Logic
if [[ -d ".git" ]]; then
info "Existing repo detected → updating"
log "git reset --hard"
git reset --hard
log "git clean -fd"
git clean -fd
info "Pulling latest changes..."
GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" git pull
else
info "No repo found → cloning"
log "git clone $REPO_SSH"
GIT_SSH_COMMAND="ssh -i $SSH_KEY -p $SSH_PORT" \
git clone "$REPO_SSH" .
fi
# Permissions
info "Setting script permissions..."
find "$TARGET_DIR" -type f -name "*.sh" -exec chmod +x {} \;
echo "Repository is up to date and scripts are executable."
# Summary
echo "===== GIT SYNC SUMMARY ====="
echo "Repository: $REPO_SSH"
echo "Directory: $TARGET_DIR"
echo "Status: SUCCESS"
echo "Logging: $ENABLE_LOGGING"
echo "Dry Run: $DRY_RUN"
echo "============================"
info "Repository sync complete"
+24 -7
View File
@@ -1,5 +1,22 @@
#!/bin/bash
set -e
# ----------------------------------------------------------------------------------------------
# --------------------------------- Rsync Core Script ------------------------------------------
# ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust in Master.conf as needed ----------------------
# ----------------------------------------------------------------------------------------------
#
# User variables can be adjusted in Master.conf
#
# Scripts now just contain runtime logic
#
# This new setup allows for profiles and arguments to use the core script
#
# Use arguments in unRAID User Plugin for directory
# Example = /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh --dry-run
# ----------------------------------------------------------------------------------------------
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -7,7 +24,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
# ----------------------------- Input -----------------------------
# Input
DIRECTORY="$1"
if [[ -z "$DIRECTORY" ]]; then
echo "Usage: $0 <directory-to-sync> [--dry-run] [VAR=value ...]"
@@ -16,11 +33,11 @@ fi
shift
parse_args "$@"
# ----------------------------- Host & IP -----------------------------
# Host & IP
detect_hosts
resolve_remote_ip
# ----------------------------- Profile -----------------------------
# Profile
PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]')
MAX_RSYNC_PROCS=${PROFILE_MAX_PROCS[$PROFILE_NAME]:-$MAX_RSYNC_PROCS}
@@ -32,14 +49,14 @@ RETRY_COUNT=${PROFILE_RETRY_COUNT[$PROFILE_NAME]:-$RETRY_COUNT}
SLEEP=${PROFILE_SLEEP[$PROFILE_NAME]:-$SLEEP}
EXCLUDE_DIRS=(${PROFILE_EXCLUDE_DIRS[$PROFILE_NAME]:-${EXCLUDE_DIRS[@]}})
# ----------------------------- Status Mode -----------------------------
# Status Mode
if [[ "$SHOW_STATUS" == true ]]; then
show_status
exit 0
fi
# ----------------------------- User Info -----------------------------
# User Info
echo "============================================================"
echo " Sync Job Starting"
echo "------------------------------------------------------------"
@@ -53,7 +70,7 @@ log "Settings: MAX_RSYNC_PROCS=$MAX_RSYNC_PROCS, BW_LIMIT=$BW_LIMIT"
log "Containers: ${CRITICAL_CONTAINER_NAMES[*]}"
log "Excludes: ${EXCLUDE_DIRS[*]}"
# ----------------------------- Rsync Wait -----------------------------
# Rsync Wait
wait_for_rsync() {
for attempt in $(seq 1 "$RETRY_COUNT"); do
RSYNC_COUNT=$(pgrep -fc "rsync.*root@${REMOTE_SERVER}" || true)
@@ -69,7 +86,7 @@ wait_for_rsync() {
exit 1
}
# ----------------------------- Main -----------------------------
# Main
main() {
echo ""
echo "🔍 Checking remote connectivity..."
+9 -6
View File
@@ -1,17 +1,20 @@
!/bin/bash
#-----------------------------------------------------------------------------------------------
#------------------------------------- Rsync command -------------------------------------------
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# ------------------------------------ Rsync command -------------------------------------------
# ----------------------------------------------------------------------------------------------
/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-test/Arrs/
#-----------------------------------------------------------------------------------------------
#-------------------------------------------- Info ---------------------------------------------
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# ------------------------------------------- Info ---------------------------------------------
# ----------------------------------------------------------------------------------------------
#
# These global configuartions can be added as arguments at the end of the script after folder location
#
# Its better to add profile in Master.conf for perm changes
#
# Profiles in Master.conf match the last string of folder location
#
# if a match is made with a list in Master.conf then the associated profile will be used
# If no match is made it defualts to global defualts
+9 -10
View File
@@ -3,7 +3,7 @@
# ----------------------- Common Helpers for Unraid Scripts -------------------------------------
# -----------------------------------------------------------------------------------------------
# ----------------------------- Output Helpers -----------------------------
# Output Helpers
info() {
echo "[INFO] $*"
}
@@ -20,8 +20,7 @@ log() {
[[ "$ENABLE_LOGGING" == true ]] && echo "[LOG] $*"
}
# ----------------------------- Argument Parsing -----------------------------
parse_args() {
# Argument Parsing
DRY_RUN=${DRY_RUN:-false}
ENABLE_LOGGING=${ENABLE_LOGGING:-false}
@@ -79,7 +78,7 @@ parse_args() {
done
}
# ----------------------------- Validation -----------------------------
# Validation
require_var() {
local var="$1"
if [[ -z "${!var:-}" ]]; then
@@ -98,7 +97,7 @@ validate_int() {
fi
}
# ----------------------------- Host Detection -----------------------------
# Host Detection
detect_hosts() {
LOCAL_HOSTNAME="$(hostname)"
@@ -129,7 +128,7 @@ detect_hosts() {
log "SSH key: $SSH_KEY"
}
# ----------------------------- Remote IP -----------------------------
# Remote IP
resolve_remote_ip() {
log "Resolving Tailscale IP for $REMOTE_SERVER_NAME..."
@@ -143,13 +142,13 @@ resolve_remote_ip() {
info "Remote IP: $REMOTE_SERVER"
}
# ----------------------------- Connectivity -----------------------------
# Connectivity
check_remote_online() {
log "Pinging $REMOTE_SERVER..."
ping -c 1 "$REMOTE_SERVER" &>/dev/null
}
# ----------------------------- Containers -----------------------------
# Containers
declare -a RUNNING_CONTAINERS=()
stop_containers() {
@@ -196,7 +195,7 @@ start_containers() {
done
}
# ----------------------------- Rsync Options -----------------------------
# Rsync Options
get_rsync_opts() {
if [[ -n "${PROFILE_RSYNC_OPTS[$PROFILE_NAME]:-}" ]]; then
read -r -a RSYNC_OPTS <<< "${PROFILE_RSYNC_OPTS[$PROFILE_NAME]}"
@@ -207,7 +206,7 @@ get_rsync_opts() {
fi
}
# ----------------------------- Status Output -----------------------------
# Status Output
show_status() {
echo "===== RSYNC STATUS ====="
echo "Local: $LOCAL_SERVER_NAME"
+3 -4
View File
@@ -1,9 +1,8 @@
#!/bin/bash
set -e
#-----------------------------------------------------------------------------------------------
# Clear Unraid system logs and Docker container logs safely
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# ------------- Clear Unraid system logs and Docker container logs safely ----------------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../common.sh"
+16 -4
View File
@@ -1,9 +1,21 @@
#!/bin/bash
set -e
#-----------------------------------------------------------------------------------------------
# Suppress noisy Docker veth/docker0 syslog messages on Unraid boot
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# ----------- Suppress noisy Docker veth/docker0 syslog messages on Unraid boot ----------------
# ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust in Master.conf as needed ----------------------
# ----------------------------------------------------------------------------------------------
#
# User variables can be adjusted in Master.conf
#
# Scripts now just contain runtime logic
#
# This new setup allows for profiles and arguments to use the core script
# Use arguments in unRAID User Plugin for directory
# Example: /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh --dry-run
# ----------------------------------------------------------------------------------------------
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../common.sh"
+8 -8
View File
@@ -1,11 +1,10 @@
#!/bin/bash
set -e
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# --------------------------- Mover Stop Script for Unraid -------------------------------------
#-----------------------------------------------------------------------------------------------
#----------------- User Variables, Please adjust in Master.conf as needed ----------------------
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust in Master.conf as needed ----------------------
# ----------------------------------------------------------------------------------------------
#
# User variables can be adjusted in Master.conf
#
@@ -14,9 +13,10 @@ set -e
# This new setup allows for profiles and arguments to use the core script
# Use arguments in unRAID User Plugin for directory
# Example: /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh --dry-run
#-----------------------------------------------------------------------------------------------
#---------------End Of User Variables, Please adjust in Master.conf as needed ------------------
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../common.sh"
+16 -4
View File
@@ -1,9 +1,21 @@
#!/bin/bash
set -e
#-----------------------------------------------------------------------------------------------
# Persistently set PHP-FPM pm.max_children on Unraid
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# ------------------ Persistently set PHP-FPM pm.max_children on Unraid ------------------------
# ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust in Master.conf as needed ----------------------
# ----------------------------------------------------------------------------------------------
#
# User variables can be adjusted in Master.conf
#
# Scripts now just contain runtime logic
#
# This new setup allows for profiles and arguments to use the core script
# Use arguments in unRAID User Plugin for directory
# Example: /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh --dry-run
# ----------------------------------------------------------------------------------------------
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../common.sh"
+3 -4
View File
@@ -1,9 +1,8 @@
#!/bin/bash
set -e
#-----------------------------------------------------------------------------------------------
# Stop all running Rsync processes for Unraid
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# ------------------------ Stop all running Rsync processes for Unraid -------------------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../common.sh"
+8 -8
View File
@@ -1,10 +1,10 @@
#!/bin/bash
#-----------------------------------------------------------------------------------------------
set -e
# ----------------------------------------------------------------------------------------------
# ---------------------------- Unattended Reboot Script for Unraid -----------------------------
#-----------------------------------------------------------------------------------------------
#----------------- User Variables, Please adjust in Master.conf as needed ----------------------
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust in Master.conf as needed ----------------------
# ----------------------------------------------------------------------------------------------
#
# User variables can be adjusted in Master.conf
#
@@ -13,9 +13,9 @@
# This new setup allows for profiles and arguments to use the core script
# Use arguments in unRAID User Plugin for directory
# Example: /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh --dry-run
#-----------------------------------------------------------------------------------------------
#---------------End Of User Variables, Please adjust in Master.conf as needed ------------------
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../common.sh"
+3 -4
View File
@@ -1,9 +1,8 @@
#!/bin/bash
set -e
#-----------------------------------------------------------------------------------------------
# Stop all running User Scripts spawned by the User Scripts plugin
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# ----------------- Stop all running User Scripts spawned by the User Scripts plugin -----------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../common.sh"
+3 -3
View File
@@ -1,9 +1,9 @@
#!/bin/bash
set -e
#-----------------------------------------------------------------------------------------------
# ZFS ARC & Memory Snapshot for Unraid
#-----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# --------------------------- ZFS ARC & Memory Snapshot for Unraid -----------------------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../common.sh"