master with all helpers
This commit is contained in:
+67
-90
@@ -51,81 +51,64 @@ PHP_CONF="/etc/php-fpm.d/www.conf"
|
||||
# php_fpm_max_children.sh max children value
|
||||
PHP_MAX_CHILDREN=250
|
||||
|
||||
# Profiles
|
||||
declare -A PROFILE_MAX_PROCS=([arrs_stack]=2 [critical-data]=2 [gmer4lfe]=1 [important-data]=2 [emby]=1)
|
||||
declare -A PROFILE_BW_LIMIT=([arrs_stack]=5000 [critical-data]=9500 [gmer4lfe]=8000 [important-data]=9500 [emby]=8000)
|
||||
declare -A PROFILE_RETRY_COUNT=([arrs_stack]=3 [critical-data]=3 [gmer4lfe]=3 [important-data]=3 [emby]=3)
|
||||
declare -A PROFILE_SLEEP=([arrs_stack]=300 [critical-data]=300 [gmer4lfe]=300 [important-data]=300 [emby]=300)
|
||||
declare -A PROFILE_CRITICAL_CONTAINER_NAMES=(
|
||||
[arrs_stack]="Sonarr Lidarr Readarr Radarr Prowlarr Bazarr Pinchflat"
|
||||
[critical-data]="Mariadb-Authelia Redis-Authelia Lldap-Gmer4Lfe NginxProxyManager Authelia"
|
||||
[gmer4lfe]="Organizrv2-Gmer4Lfe UptimeKuma-Gmer4Lfe VaultWarden-Gmer4Lfe"
|
||||
[important-data]="Postgres-NextCloud NextCloud"
|
||||
[emby]=""
|
||||
)
|
||||
declare -A PROFILE_DELAYED_CONTAINERS=([arrs_stack]="" [critical-data]="Authelia" [gmer4lfe]="" [important-data]="NextCloud" [emby]="")
|
||||
declare -A PROFILE_CONTAINER_DELAY=([arrs_stack]=5 [critical-data]=10 [gmer4lfe]=5 [important-data]=10 [emby]=5)
|
||||
declare -A PROFILE_EXCLUDE_DIRS=([arrs_stack]="logs *.tmp" [critical-data]="logs *.tmp" [gmer4lfe]="logs *.tmp" [important-data]="logs *.tmp" [emby]="logs *.tmp")
|
||||
|
||||
#----------------------- Profile System ------------------------
|
||||
# ----------------------------- Common Helpers -----------------------------
|
||||
parse_args() {
|
||||
DRY_RUN=${DRY_RUN:-false}
|
||||
for ARG in "$@"; do
|
||||
if [[ "$ARG" == *=* ]]; then
|
||||
local VAR_NAME="${ARG%%=*}"
|
||||
local VAR_VALUE="${ARG#*=}"
|
||||
if declare -p "$VAR_NAME" &>/dev/null; then
|
||||
printf -v "$VAR_NAME" '%s' "$VAR_VALUE"
|
||||
echo "Overriding $VAR_NAME -> $VAR_VALUE"
|
||||
else
|
||||
echo "Warning: Unknown variable $VAR_NAME, ignoring."
|
||||
fi
|
||||
else
|
||||
case "$ARG" in
|
||||
--dry-run|-n) DRY_RUN=true ;;
|
||||
--help|-h) echo "Usage: script [--dry-run|-n] [VAR=value ...]"; exit 0 ;;
|
||||
*) echo "Warning: Unknown argument $ARG" ;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# 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)
|
||||
# Max rsync processes per profile
|
||||
declare -A PROFILE_MAX_PROCS
|
||||
PROFILE_MAX_PROCS["arrs_stack"]=2
|
||||
PROFILE_MAX_PROCS["critical-data"]=2
|
||||
PROFILE_MAX_PROCS["gmer4lfe"]=1
|
||||
PROFILE_MAX_PROCS["important-data"]=2
|
||||
PROFILE_MAX_PROCS["emby"]=1
|
||||
# Bandwidth limits per profile (KB/s, 0 = unlimited)
|
||||
declare -A PROFILE_BW_LIMIT
|
||||
PROFILE_BW_LIMIT["arrs_stack"]=5000
|
||||
PROFILE_BW_LIMIT["critical-data"]=9500
|
||||
PROFILE_BW_LIMIT["gmer4lfe"]=8000
|
||||
PROFILE_BW_LIMIT["important-data"]=9500
|
||||
PROFILE_BW_LIMIT["emby"]=8000
|
||||
# Retry logic per profile
|
||||
declare -A PROFILE_RETRY_COUNT
|
||||
PROFILE_RETRY_COUNT["arrs_stack"]=3
|
||||
PROFILE_RETRY_COUNT["critical-data"]=3
|
||||
PROFILE_RETRY_COUNT["gmer4lfe"]=3
|
||||
PROFILE_RETRY_COUNT["important-data"]=3
|
||||
PROFILE_RETRY_COUNT["emby"]=3
|
||||
# Sleep between retries per profile (seconds)
|
||||
declare -A PROFILE_SLEEP
|
||||
PROFILE_SLEEP["arrs_stack"]=300
|
||||
PROFILE_SLEEP["critical-data"]=300
|
||||
PROFILE_SLEEP["gmer4lfe"]=300
|
||||
PROFILE_SLEEP["important-data"]=300
|
||||
PROFILE_SLEEP["emby"]=300
|
||||
# Containers to stop/start per profile (space-separated strings)
|
||||
declare -A PROFILE_CRITICAL_CONTAINER_NAMES
|
||||
PROFILE_CRITICAL_CONTAINER_NAMES["arrs_stack"]="Sonarr Lidarr Readarr Radarr Prowlarr Bazarr Pinchflat"
|
||||
PROFILE_CRITICAL_CONTAINER_NAMES["critical-data"]="Mariadb-Authelia Redis-Authelia Lldap-Gmer4Lfe NginxProxyManager Authelia"
|
||||
PROFILE_CRITICAL_CONTAINER_NAMES["gmer4lfe"]="Organizrv2-Gmer4Lfe UptimeKuma-Gmer4Lfe VaultWarden-Gmer4Lfe"
|
||||
PROFILE_CRITICAL_CONTAINER_NAMES["important-data"]="Postgres-NextCloud NextCloud"
|
||||
PROFILE_CRITICAL_CONTAINER_NAMES["emby"]=""
|
||||
# Delayed containers per profile (space-separated strings)
|
||||
declare -A PROFILE_DELAYED_CONTAINERS
|
||||
PROFILE_DELAYED_CONTAINERS["arrs_stack"]=""
|
||||
PROFILE_DELAYED_CONTAINERS["critical-data"]="Authelia"
|
||||
PROFILE_DELAYED_CONTAINERS["gmer4lfe"]=""
|
||||
PROFILE_DELAYED_CONTAINERS["important-data"]="NextCloud"
|
||||
PROFILE_DELAYED_CONTAINERS["emby"]=""
|
||||
# Delay in seconds before starting delayed containers per profile (seconds)
|
||||
declare -A PROFILE_CONTAINER_DELAY
|
||||
PROFILE_CONTAINER_DELAY["arrs_stack"]=5
|
||||
PROFILE_CONTAINER_DELAY["critical-data"]=10
|
||||
PROFILE_CONTAINER_DELAY["gmer4lfe"]=5
|
||||
PROFILE_CONTAINER_DELAY["important-data"]=10
|
||||
PROFILE_CONTAINER_DELAY["emby"]=5
|
||||
# Not include logs or other file types during transfer per profile
|
||||
declare -A PROFILE_EXCLUDE_DIRS
|
||||
PROFILE_EXCLUDE_DIRS["arrs_stack"]="logs *.tmp"
|
||||
PROFILE_EXCLUDE_DIRS["critical-data"]="logs *.tmp"
|
||||
PROFILE_EXCLUDE_DIRS["gmer4lfe"]="logs *.tmp"
|
||||
PROFILE_EXCLUDE_DIRS["important-data"]="logs *.tmp"
|
||||
PROFILE_EXCLUDE_DIRS["emby"]="logs *.tmp"
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
#----------------------End Of User Variables, Please adjust Above as needed --------------------
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
#
|
||||
# Next is commom runtime logic, tried to include logic in a common script but was having trouble
|
||||
# So now its at the botton of the file, but please do not adjust unless you understand the code
|
||||
# and what it does, as changes here will affect all scripts that source this master.conf file
|
||||
#
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
#--------------------Run Logic, Do not adjust unless you understand the code -------------------
|
||||
#-----------------------------------------------------------------------------------------------
|
||||
# Detect local hostname
|
||||
require_var() {
|
||||
local var="$1"
|
||||
if [[ -z "${!var:-}" ]]; then
|
||||
echo "Error: Required variable $var is not set."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
validate_int() {
|
||||
local name="$1"
|
||||
local value="$2"
|
||||
if ! [[ "${value:-}" =~ ^[0-9]+$ ]]; then
|
||||
echo "Error: $name must be a non-negative integer."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# ----------------------------- Host Detection & SSH -----------------------------
|
||||
# Detect local/remote host
|
||||
LOCAL_HOSTNAME="$(hostname)"
|
||||
if [[ "$LOCAL_HOSTNAME" == "$HOST1" ]]; then
|
||||
LOCAL_SERVER_NAME="$HOST1"
|
||||
@@ -139,29 +122,23 @@ else
|
||||
fi
|
||||
echo "Local server: $LOCAL_SERVER_NAME"
|
||||
echo "Remote server: $REMOTE_SERVER_NAME"
|
||||
echo "DEBUG: LOCAL_HOSTNAME=$LOCAL_HOSTNAME, LOCAL_SERVER_NAME=$LOCAL_SERVER_NAME, REMOTE_SERVER_NAME=$REMOTE_SERVER_NAME"
|
||||
echo "DEBUG: KEY_ID=$KEY_ID, SSH_KEY=${SSH_KEYS[$KEY_ID]}"
|
||||
|
||||
# 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
|
||||
declare -A SSH_KEYS
|
||||
SSH_KEYS["$HOST1|$HOST2"]="$HOST1_SSH_KEY"
|
||||
SSH_KEYS["$HOST2|$HOST1"]="$HOST2_SSH_KEY"
|
||||
|
||||
# Determine which key to use
|
||||
KEY_ID="$LOCAL_SERVER_NAME|$REMOTE_SERVER_NAME"
|
||||
if [[ -n "${SSH_KEYS[$KEY_ID]}" ]]; then
|
||||
SSH_KEY="${SSH_KEYS[$KEY_ID]}"
|
||||
else
|
||||
SSH_KEY="${SSH_KEYS[$KEY_ID]}"
|
||||
if [[ -z "$SSH_KEY" ]]; then
|
||||
echo "Error: No SSH key defined for $LOCAL_SERVER_NAME → $REMOTE_SERVER_NAME"
|
||||
exit 1
|
||||
fi
|
||||
echo "Using SSH key: $SSH_KEY"
|
||||
echo "Using SSH key: $SSH_KEY"
|
||||
|
||||
# Remote IP via Tailscale
|
||||
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
|
||||
echo "Remote IP: $REMOTE_SERVER"
|
||||
Reference in New Issue
Block a user