This commit is contained in:
2026-03-24 20:40:05 +00:00
parent d703d7e153
commit 6c6d510fde
2 changed files with 37 additions and 21 deletions
+6 -11
View File
@@ -10,28 +10,23 @@ source "$SCRIPT_DIR/../common.sh"
# Load config
load_master_conf
# Parse arguments, etc...
# Detect hosts and SSH key
detect_hosts
#-----------------------------------------------------------------------------------------------
# --------------------------- Input Arguments --------------------------------------------------
#-----------------------------------------------------------------------------------------------
# Input arguments
DIRECTORY="$1"
if [[ -z "$DIRECTORY" ]]; then
echo "Usage: $0 <directory-to-sync> [--dry-run|-n] [VAR=value ...]"
exit 1
fi
shift # remove DIRECTORY
# Parse CLI args
shift
parse_args "$@"
#-----------------------------------------------------------------------------------------------
# --------------------------- Profile Detection -------------------------------------------------
#-----------------------------------------------------------------------------------------------
# Determine profile
PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]')
echo "Detected profile: $PROFILE_NAME"
# Apply profile defaults or fallback to global defaults
# Apply profile settings
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]})
+31 -10
View File
@@ -11,14 +11,21 @@
#-----------------------------------------------------------------------------------------------
# Load Master.conf
#-----------------------------------------------------------------------------------------------
# Load Master.conf
#-----------------------------------------------------------------------------------------------
# Load Master.conf reliably
#-----------------------------------------------------------------------------------------------
load_master_conf() {
# Resolve the folder of the calling script (rsync.sh)
# Determine the directory of THIS file (common.sh)
local script_dir
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Master.conf is one level up from Rsync/
local master_conf="$script_dir/../Master.conf"
# Master.conf is assumed to be in the parent directory of unRAID scripts root
# i.e., one level up from where common.sh lives
local master_conf="$script_dir/Master.conf"
if [ ! -f "$master_conf" ]; then
# fallback for Rsync/rsync.sh calling common.sh
master_conf="$script_dir/../Master.conf"
fi
if [ -f "$master_conf" ]; then
source "$master_conf"
@@ -29,9 +36,12 @@ load_master_conf() {
fi
}
# Parse CLI arguments
#-----------------------------------------------------------------------------------------------
# Parse CLI args
#-----------------------------------------------------------------------------------------------
parse_args() {
DRY_RUN=${DRY_RUN:-false}
for ARG in "$@"; do
if [[ "$ARG" == *=* ]]; then
local VAR_NAME="${ARG%%=*}"
@@ -40,19 +50,24 @@ parse_args() {
printf -v "$VAR_NAME" '%s' "$VAR_VALUE"
echo "Overriding $VAR_NAME -> $VAR_VALUE"
else
echo "Warning: Unknown variable $VAR_NAME"
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" ;;
--help|-h)
echo "Usage: script [--dry-run|-n] [VAR=value ...]"
exit 0 ;;
*)
echo "Warning: Unknown argument $ARG" ;;
esac
fi
done
}
#-----------------------------------------------------------------------------------------------
# Validate integer
#-----------------------------------------------------------------------------------------------
validate_int() {
local name="$1"
local value="$2"
@@ -62,7 +77,9 @@ validate_int() {
fi
}
#-----------------------------------------------------------------------------------------------
# Require variable
#-----------------------------------------------------------------------------------------------
require_var() {
local var="$1"
if [[ -z "${!var:-}" ]]; then
@@ -71,8 +88,10 @@ require_var() {
fi
}
# Detect local hostname and set remote
detect_remote() {
#-----------------------------------------------------------------------------------------------
# Detect local/remote hosts and resolve Tailscale IPs
#-----------------------------------------------------------------------------------------------
detect_hosts() {
LOCAL_HOSTNAME="$(hostname)"
if [[ "$LOCAL_HOSTNAME" == "$HOST1" ]]; then
LOCAL_SERVER_NAME="$HOST1"
@@ -87,6 +106,7 @@ detect_remote() {
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"
@@ -94,6 +114,7 @@ detect_remote() {
fi
echo "Resolved $REMOTE_SERVER_NAME$REMOTE_SERVER"
# SSH key lookup
KEY_ID="$LOCAL_SERVER_NAME|$REMOTE_SERVER_NAME"
if [[ -n "${SSH_KEYS[$KEY_ID]}" ]]; then
SSH_KEY="${SSH_KEYS[$KEY_ID]}"