From ee5a07be1ca4be01a14fd6a877e382c1c28ca7c2 Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Sun, 14 Jun 2026 01:22:02 -0400 Subject: [PATCH] Remove remaining OS-specific hardcodes from core scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OS version reads now go through platform_get_os_version() and platform_os_version_probe_cmd() instead of grepping /etc/unraid-version directly. STATE_DIR fallbacks to /boot/config removed — STATE_DIR is always set by load_config.sh and the fallback encoded a platform-specific path. Setup DB path references use platform_setup_db_path() instead of the VARAVERK_SETUP_FILE/-/boot/config compound fallback. DOCKER_APPDATA_BASE default removed from arr_sync.sh — the adapter sets it. --- Fallback/fallback.sh | 6 ++-- Fallback/fallback_test.sh | 4 +-- Media/arr_sync.sh | 2 +- Orchestrators/sunday_morning_coffee_report.sh | 2 +- Partnership/onboard_cancel.sh | 2 +- Partnership/partnership_manager.sh | 14 ++++---- Partnership/partnership_offboard.sh | 10 +++--- Partnership/partnership_onboard.sh | 4 +-- Partnership/partnership_transfer.sh | 4 +-- Plugin/unraid/adapter.sh | 23 +++++++++++++ Rsync/rsync.sh | 2 +- common.sh | 34 +++++++++---------- 12 files changed, 65 insertions(+), 42 deletions(-) diff --git a/Fallback/fallback.sh b/Fallback/fallback.sh index 52409d7..7078e3c 100755 --- a/Fallback/fallback.sh +++ b/Fallback/fallback.sh @@ -345,7 +345,7 @@ state_init() { # Returns 0 (true) if the local partnership DB reports an ACTIVE partnership. # Reads /boot/config/partnership_.db — no subprocess, no SSH. check_partnership_active() { - local state_file="${STATE_DIR:-/boot/config}/partnership_${LOCAL_SERVER_NAME}.db" + local state_file="${STATE_DIR}/partnership_${LOCAL_SERVER_NAME}.db" local state state=$(grep "^state=" "$state_file" 2>/dev/null | cut -d= -f2) [[ "$state" == "ACTIVE" ]] @@ -603,13 +603,13 @@ if [[ "$SHOW_STATUS" == true ]]; then TIER4=$(state_get tier4_started) STRIKES=$(state_get handback_strikes) - local_ver=$(grep -oP '(?<=version=")[^"]+' /etc/unraid-version 2>/dev/null || echo "unknown") + local_ver=$(platform_get_os_version 2>/dev/null || echo "unknown") echo "" echo "━━━━━ $ICON_SUMMARY FALLBACK STATUS ━━━━━" echo "$ICON_HOST My ID: $MY_ID ($LOCAL_SERVER_NAME)" echo "$ICON_HOST Remote ID: $REMOTE_ID ($REMOTE_SERVER_NAME — $REMOTE_SERVER)" - echo "$ICON_GEAR unRAID ver: $local_ver" + echo "$ICON_GEAR OS ver: $local_ver" echo "$ICON_FALLBACK State: $CURRENT_STATE" echo "$ICON_NET Local DDNS: ${LOCAL_DDNS_CONTAINERS[*]:-none}" echo "$ICON_NET Remote DDNS: ${REMOTE_DDNS_CONTAINERS[*]:-none}" diff --git a/Fallback/fallback_test.sh b/Fallback/fallback_test.sh index 611731f..bf07083 100755 --- a/Fallback/fallback_test.sh +++ b/Fallback/fallback_test.sh @@ -185,13 +185,13 @@ log "$ICON_GEAR Config: remote=${REMOTE_SERVER_NAME} (${REMOTE_SERVER}) fallback # ━━━ Status ━━━ # ============================================================================================== if [[ "$SHOW_STATUS" == true ]]; then - local_ver=$(grep -oP '(?<=version=")[^"]+' /etc/unraid-version 2>/dev/null || echo "unknown") + local_ver=$(platform_get_os_version 2>/dev/null || echo "unknown") echo "" echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━" echo "$ICON_HOST My ID: $MY_ID ($LOCAL_SERVER_NAME)" echo "$ICON_HOST Remote ID: $REMOTE_ID ($REMOTE_SERVER_NAME — $REMOTE_SERVER)" - echo "$ICON_GEAR unRAID ver: $local_ver" + echo "$ICON_GEAR OS ver: $local_ver" echo "$ICON_FALLBACK Block wait: ${FALLBACK_TEST_BLOCK_WAIT}s" echo "$ICON_FALLBACK Handback wait: ${FALLBACK_TEST_HANDBACK_WAIT}s" echo "$ICON_FALLBACK Check interval: ${FALLBACK_CHECK_INTERVAL}s" diff --git a/Media/arr_sync.sh b/Media/arr_sync.sh index a7c6e34..b858a62 100755 --- a/Media/arr_sync.sh +++ b/Media/arr_sync.sh @@ -178,7 +178,7 @@ ARR_SYNC_ENABLED="${ARR_SYNC_ENABLED:-true}" ARR_SYNC_BLOCKLIST="${ARR_SYNC_BLOCKLIST:-${DATA_DIR}/arr_sync_blocklist.tsv}" ARR_SYNC_CONNECT_TIMEOUT="${ARR_SYNC_CONNECT_TIMEOUT:-10}" ARR_SYNC_API_TIMEOUT="${ARR_SYNC_API_TIMEOUT:-60}" -DOCKER_APPDATA_BASE="${DOCKER_APPDATA_BASE:-/mnt/user/appdata}" + ARR_SYNC_LIDARR_PORT="${ARR_SYNC_LIDARR_PORT:-8686}" ARR_SYNC_SONARR_PORT="${ARR_SYNC_SONARR_PORT:-8989}" ARR_SYNC_RADARR_PORT="${ARR_SYNC_RADARR_PORT:-7878}" diff --git a/Orchestrators/sunday_morning_coffee_report.sh b/Orchestrators/sunday_morning_coffee_report.sh index 5a3d6a5..5869d78 100755 --- a/Orchestrators/sunday_morning_coffee_report.sh +++ b/Orchestrators/sunday_morning_coffee_report.sh @@ -87,7 +87,7 @@ fi # ============================================================================================== # ━━━ Main ━━━ # ============================================================================================== -_unraid_ver=$(grep -oP '(?<=version=")[^"]+' /etc/unraid-version 2>/dev/null || echo "unknown") +_unraid_ver=$(platform_get_os_version 2>/dev/null || echo "unknown") _uptime_s=$(awk '{print int($1)}' /proc/uptime 2>/dev/null || echo 0) _container_count=$(docker ps -q 2>/dev/null | wc -l || echo 0) _rootfs_pct=$(df / --output=pcent 2>/dev/null | tail -1 | tr -d ' %') diff --git a/Partnership/onboard_cancel.sh b/Partnership/onboard_cancel.sh index d255790..a53da4a 100755 --- a/Partnership/onboard_cancel.sh +++ b/Partnership/onboard_cancel.sh @@ -54,7 +54,7 @@ OWNER_ID="${PARTNERSHIP_OWNER_HOST:-HOST1}" MIRROR_ID=$( [[ "$OWNER_ID" == "HOST1" ]] && echo "HOST2" || echo "HOST1" ) MIRROR="${!MIRROR_ID}" SSH_KEY_PUB="${SSH_KEY}.pub" -STATE_FILE="${VARAVERK_SETUP_FILE:-${STATE_DIR:-/boot/config}/varaverk_setup.db}" +STATE_FILE="$(platform_setup_db_path)" AUTH_KEYS="/root/.ssh/authorized_keys" MIRROR_SHORT="${MIRROR%%.*}" diff --git a/Partnership/partnership_manager.sh b/Partnership/partnership_manager.sh index f9f2f7e..4e10e5f 100755 --- a/Partnership/partnership_manager.sh +++ b/Partnership/partnership_manager.sh @@ -194,7 +194,7 @@ source "$SCRIPT_DIR/../load_config.sh" source "$SCRIPT_DIR/../Plugin/$PLATFORM/Partnership/containers.sh" SSH_TIMEOUT=15 -BLOCKLIST_FILE="${PARTNERSHIP_BLOCKLIST_FILE:-${STATE_DIR:-/boot/config}/partnership_blocklist.db}" +BLOCKLIST_FILE="${PARTNERSHIP_BLOCKLIST_FILE:-${STATE_DIR}/partnership_blocklist.db}" # ── Parse mode flags before parse_args ──────────────────────────────────────────────────────── MODE="" @@ -267,11 +267,11 @@ AM_MIRROR=false [[ "$MY_ID" == "$MIRROR_ID" ]] && AM_MIRROR=true # State files -LOCAL_STATE_FILE="${STATE_DIR:-/boot/config}/partnership_${LOCAL_SERVER_NAME}.db" -REMOTE_STATE_FILE="${STATE_DIR:-/boot/config}/partnership_${REMOTE_SERVER_NAME}.db" -OWNER_STATE_FILE="${STATE_DIR:-/boot/config}/partnership_${OWNER}.db" -MIRROR_STATE_FILE="${STATE_DIR:-/boot/config}/partnership_${MIRROR}.db" -OFFLINE_COUNTER="${STATE_DIR:-/boot/config}/partnership_offline_days.db" +LOCAL_STATE_FILE="${STATE_DIR}/partnership_${LOCAL_SERVER_NAME}.db" +REMOTE_STATE_FILE="${STATE_DIR}/partnership_${REMOTE_SERVER_NAME}.db" +OWNER_STATE_FILE="${STATE_DIR}/partnership_${OWNER}.db" +MIRROR_STATE_FILE="${STATE_DIR}/partnership_${MIRROR}.db" +OFFLINE_COUNTER="${STATE_DIR}/partnership_offline_days.db" # ── Exit Trap — restart locally stopped containers if script crashes mid-cleanup ────────────── # Used by cleanup_partner_containers() — also shared with partnership_offboard.sh which @@ -1175,7 +1175,7 @@ if [[ "$MODE" == "onboard" ]]; then fi # Write HOST1_LOCAL_DONE flag to setup.db - local_state_file="${VARAVERK_SETUP_FILE:-${STATE_DIR:-/boot/config}/varaverk_setup.db}" + local_state_file="$(platform_setup_db_path)" if [[ "$DRY_RUN" == false ]]; then flag_key="${MY_ID}_LOCAL_DONE" if grep -q "^${flag_key}=" "$local_state_file" 2>/dev/null; then diff --git a/Partnership/partnership_offboard.sh b/Partnership/partnership_offboard.sh index 41337dd..603f70f 100755 --- a/Partnership/partnership_offboard.sh +++ b/Partnership/partnership_offboard.sh @@ -120,11 +120,11 @@ AM_MIRROR=false [[ "$MY_ID" == "$OWNER_ID" ]] && AM_OWNER=true [[ "$MY_ID" == "$MIRROR_ID" ]] && AM_MIRROR=true -LOCAL_STATE_FILE="${STATE_DIR:-/boot/config}/partnership_${LOCAL_SERVER_NAME}.db" -REMOTE_STATE_FILE="${STATE_DIR:-/boot/config}/partnership_${REMOTE_SERVER_NAME}.db" -OWNER_STATE_FILE="${STATE_DIR:-/boot/config}/partnership_${OWNER}.db" -MIRROR_STATE_FILE="${STATE_DIR:-/boot/config}/partnership_${MIRROR}.db" -OFFLINE_COUNTER="${STATE_DIR:-/boot/config}/partnership_offline_days.db" +LOCAL_STATE_FILE="${STATE_DIR}/partnership_${LOCAL_SERVER_NAME}.db" +REMOTE_STATE_FILE="${STATE_DIR}/partnership_${REMOTE_SERVER_NAME}.db" +OWNER_STATE_FILE="${STATE_DIR}/partnership_${OWNER}.db" +MIRROR_STATE_FILE="${STATE_DIR}/partnership_${MIRROR}.db" +OFFLINE_COUNTER="${STATE_DIR}/partnership_offline_days.db" acquire_lock "strict" diff --git a/Partnership/partnership_onboard.sh b/Partnership/partnership_onboard.sh index 08bea50..f76ba5a 100755 --- a/Partnership/partnership_onboard.sh +++ b/Partnership/partnership_onboard.sh @@ -220,7 +220,7 @@ START=$(date +%s) write_onboard_phase() { local target_id="$1" phase="$2" local key="${target_id}_PHASE${phase}_DONE" - local state_file="${VARAVERK_SETUP_FILE:-${STATE_DIR:-/boot/config}/varaverk_setup.db}" + local state_file="$(platform_setup_db_path)" [[ "$DRY_RUN" == true ]] && { warn "DRY RUN — would write ${key}=true"; return 0; } if grep -q "^${key}=" "$state_file" 2>/dev/null; then sed -i "s|^${key}=.*|${key}=true|" "$state_file" @@ -412,7 +412,7 @@ elif [[ "$PHASE1_ONLY" == true ]]; then # Write key-ready flag so UI can show the manual-install state [[ "$DRY_RUN" == false ]] && { local kflag="${MIRROR_ID}_KEY_READY" - local _setup_f="${VARAVERK_SETUP_FILE:-${STATE_DIR:-/boot/config}/varaverk_setup.db}" + local _setup_f="$(platform_setup_db_path)" grep -q "^${kflag}=" "$_setup_f" 2>/dev/null \ && sed -i "s|^${kflag}=.*|${kflag}=true|" "$_setup_f" \ || echo "${kflag}=true" >> "$_setup_f" diff --git a/Partnership/partnership_transfer.sh b/Partnership/partnership_transfer.sh index bfa8ab6..4c6caca 100755 --- a/Partnership/partnership_transfer.sh +++ b/Partnership/partnership_transfer.sh @@ -140,8 +140,8 @@ AM_MIRROR=false [[ "$MY_ID" == "$OWNER_ID" ]] && AM_OWNER=true [[ "$MY_ID" == "$MIRROR_ID" ]] && AM_MIRROR=true -LOCAL_STATE_FILE="${STATE_DIR:-/boot/config}/partnership_${LOCAL_SERVER_NAME}.db" -REMOTE_STATE_FILE="${STATE_DIR:-/boot/config}/partnership_${REMOTE_SERVER_NAME}.db" +LOCAL_STATE_FILE="${STATE_DIR}/partnership_${LOCAL_SERVER_NAME}.db" +REMOTE_STATE_FILE="${STATE_DIR}/partnership_${REMOTE_SERVER_NAME}.db" acquire_lock "strict" diff --git a/Plugin/unraid/adapter.sh b/Plugin/unraid/adapter.sh index 4e043c6..64b25b8 100755 --- a/Plugin/unraid/adapter.sh +++ b/Plugin/unraid/adapter.sh @@ -33,6 +33,8 @@ # platform_scripts_dir_probe_cmd — shell command to run on a remote to discover its SCRIPTS_DIR # platform_get_templates_dir — path to Unraid CA docker templates-user directory # platform_setup_db_path — path to the persistent Varaverk setup/wizard state database +# platform_get_os_version — local OS version string (e.g. "7.2.3") +# platform_os_version_probe_cmd — shell command to run on a remote to retrieve its OS version # platform_rebuild_container — rebuild a container from its stored XML template # platform_push_conf — push master.conf to all listed hosts via WebGUI PHP # platform_push_setup_state — push wizard setup state to WebGUI PHP @@ -275,6 +277,27 @@ platform_setup_db_path() { echo "/boot/config/varaverk_setup.db" } +# ────────────────────────────────────────────────────────────────────────────────────────────── +# platform_get_os_version +# Writes the platform OS version string to stdout (e.g. "7.2.3"). +# Returns 1 if the version file is absent or unparseable. +# ────────────────────────────────────────────────────────────────────────────────────────────── +platform_get_os_version() { + local ver + ver=$(grep -oP '(?<=version=")[^"]+' /etc/unraid-version 2>/dev/null) + [[ -n "$ver" ]] || return 1 + echo "$ver" +} + +# ────────────────────────────────────────────────────────────────────────────────────────────── +# platform_os_version_probe_cmd +# Writes a shell command suitable for running on a remote via SSH to retrieve +# that remote's OS version string. Output format matches platform_get_os_version. +# ────────────────────────────────────────────────────────────────────────────────────────────── +platform_os_version_probe_cmd() { + echo "grep -oP '(?<=version=\")[^\"]+' /etc/unraid-version 2>/dev/null" +} + # ────────────────────────────────────────────────────────────────────────────────────────────── # platform_rebuild_container # Rebuilds a container from its stored Unraid CA XML template (stops old, recreates on new diff --git a/Rsync/rsync.sh b/Rsync/rsync.sh index 9b4d9ac..98d24f3 100755 --- a/Rsync/rsync.sh +++ b/Rsync/rsync.sh @@ -180,7 +180,7 @@ if ! check_rsync_enabled; then fi # Blocklist gate — refuse to sync with a partner blocked after offboard -BLOCKLIST_FILE="${PARTNERSHIP_BLOCKLIST_FILE:-${STATE_DIR:-/boot/config}/partnership_blocklist.db}" +BLOCKLIST_FILE="${PARTNERSHIP_BLOCKLIST_FILE:-${STATE_DIR}/partnership_blocklist.db}" if [[ -f "$BLOCKLIST_FILE" ]] && grep -q "^${REMOTE_SERVER_NAME}|" "$BLOCKLIST_FILE" 2>/dev/null; then error "Rsync blocked — $REMOTE_SERVER_NAME is on the partnership blocklist" error "Re-onboard the partnership to restore access: partnership_manager.sh --onboard" diff --git a/common.sh b/common.sh index ef05bc1..2d6e5f2 100755 --- a/common.sh +++ b/common.sh @@ -81,7 +81,7 @@ # # Three new safety functions added: # check_unraid_version_parity() — refuses remote ops on version mismatch -# reads /etc/unraid-version local and remote via SSH +# reads OS version via platform_get_os_version() / platform_os_version_probe_cmd() # major mismatch → abort | minor mismatch → configurable warn/abort # check_remote_docker_daemon() — verifies remote Docker daemon before # issuing any remote container commands — strike system → skip/retry/exit @@ -1741,7 +1741,7 @@ check_api() { # remote operation. Version mismatches can mean changed APIs, commands, or behaviours # that silently break remote container operations, rsync, or fallback logic. # -# Reads /etc/unraid-version on both sides — format: version="7.2.3" +# Reads platform OS version on both sides via adapter. # # Mismatch behaviour (UNRAID_VERSION_MISMATCH_ACTION in master.conf): # "warn" — log warning and continue (default for minor/patch differences) @@ -1754,28 +1754,26 @@ check_unraid_version_parity() { local local_version remote_version # Read local version - if [[ ! -f /etc/unraid-version ]]; then - warn "Cannot read local /etc/unraid-version — skipping version parity check" - return 0 - fi - local_version=$(grep -oP '(?<=version=")[^"]+' /etc/unraid-version 2>/dev/null) + local_version=$(platform_get_os_version 2>/dev/null) if [[ -z "$local_version" ]]; then - warn "Cannot parse local unRAID version — skipping parity check" + warn "Cannot read local OS version — skipping version parity check" return 0 fi # Read remote version via SSH + local _probe_cmd + _probe_cmd=$(platform_os_version_probe_cmd) remote_version=$(ssh -i "$SSH_KEY" -o ConnectTimeout=10 root@"$REMOTE_SERVER" \ - "grep -oP '(?<=version=\")[^\"]+' /etc/unraid-version 2>/dev/null" 2>/dev/null) + "$_probe_cmd" 2>/dev/null) if [[ -z "$remote_version" ]]; then - warn "Cannot read remote unRAID version from $REMOTE_SERVER_NAME — skipping parity check" + warn "Cannot read remote OS version from $REMOTE_SERVER_NAME — skipping parity check" return 0 fi log "Version parity: local=$local_version remote=$remote_version" if [[ "$local_version" == "$remote_version" ]]; then - log "unRAID versions match: $local_version ✅" + log "OS versions match: $local_version ✅" return 0 fi @@ -1785,20 +1783,22 @@ check_unraid_version_parity() { remote_major="${remote_version%%.*}" if [[ "$local_major" != "$remote_major" ]]; then - error "unRAID MAJOR version mismatch — local: $local_version remote: $remote_version" + error "OS MAJOR version mismatch — local: $local_version remote: $remote_version" error "Major version differences may break remote APIs, commands, and behaviours" error "Update both servers to the same major version before running remote operations" - notify "unRAID major version mismatch on $(hostname) — local: $local_version remote: $remote_version — remote operations aborted" "Version Parity" "warning" + notify "OS major version mismatch on $(hostname) — local: $local_version remote: $remote_version — remote operations aborted" \ + "Version Parity" "warning" return 1 fi # Minor/patch mismatch — action depends on config local action="${UNRAID_VERSION_MISMATCH_ACTION:-warn}" - warn "unRAID version mismatch — local: $local_version remote: $remote_version" + warn "OS version mismatch — local: $local_version remote: $remote_version" if [[ "$action" == "abort" ]]; then error "UNRAID_VERSION_MISMATCH_ACTION=abort — refusing to continue" - notify "unRAID version mismatch on $(hostname) — local: $local_version remote: $remote_version — aborted" "Version Parity" "warning" + notify "OS version mismatch on $(hostname) — local: $local_version remote: $remote_version — aborted" \ + "Version Parity" "warning" return 1 fi @@ -1906,14 +1906,14 @@ validate_unraid_cmd() { show_status() { local local_ver - local_ver=$(grep -oP '(?<=version=")[^"]+' /etc/unraid-version 2>/dev/null || echo "unknown") + local_ver=$(platform_get_os_version 2>/dev/null || echo "unknown") echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━" echo "Local: $LOCAL_SERVER_NAME" echo "Remote: $REMOTE_SERVER_NAME" echo "IP: ${REMOTE_SERVER:-not resolved}" echo "My ID: ${MY_ID:-not set}" echo "Remote ID: ${REMOTE_ID:-not set}" - echo "unRAID ver: $local_ver" + echo "OS ver: $local_ver" echo "Profile: ${PROFILE_NAME:-n/a}" echo "DryRun: ${DRY_RUN:-false}"