Platform-agnostic refactor: eliminate OS-specific hardcodes from core scripts

All bash scripts are now platform-neutral. Unraid-specific paths, commands,
and service checks moved to Plugin/unraid/adapter.sh. Core scripts call
platform_*() functions exclusively — no direct OS paths in runtime logic.

New adapter functions: platform_storage_path, platform_webui_install_path,
platform_scripts_dir_probe_cmd, platform_setup_db_path, platform_storage_healthy,
platform_is_service_enabled, platform_get_temp_thresholds, platform_disk_states_path,
platform_rebuild_container, platform_push_conf, platform_push_setup_state,
platform_get_templates_dir, platform_send_os_notification.

Partnership services stack (Emby/Jellyfin/Seerr/SeerrFin) added as third
onboarding stack alongside auth and arr stacks.
This commit is contained in:
Gmer4Lfe
2026-06-14 00:59:19 -04:00
parent fd1c4c7e3a
commit 27bfc21cb0
61 changed files with 411 additions and 444 deletions
+17 -101
View File
@@ -155,6 +155,10 @@
# Containers parked here during partnership, restarted on offboard.
# Aliased by detect_hosts() → PARTNERSHIP_OWN_CONTAINERS
#
# HOST*_PARTNERSHIP_SERVICES_STACK
# Shared services XMLs (Emby, Jellyfin, Seerr, SeerrFin) deployed on mirror during onboard.
# Aliased by detect_hosts() → PARTNERSHIP_SERVICES_STACK
#
# ==============================================================================================
# RUNTIME MODES
# ==============================================================================================
@@ -187,6 +191,7 @@
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
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}"
@@ -235,11 +240,6 @@ if [[ "$EUID" -ne 0 ]]; then
exit 1
fi
platform_require_cmd \
"/usr/local/emhttp/plugins/dynamix/scripts/notify" \
"" "" \
"unRAID notify script" || warn "unRAID notify script not found — native notifications disabled"
if ! command -v docker &>/dev/null; then
error "Docker command not found"
exit 1
@@ -368,73 +368,6 @@ read_remote_state() {
"cat '$remote_file' 2>/dev/null" 2>/dev/null
}
# Reconfigure a container's WebUI on the remote server
reconfigure_webui() {
local container="$1" port="$2" target_ip="$3"
local ssh_key="$4" remote_ip="$5" label="${6:-remote}"
log "Reconfiguring $container WebUI → ${target_ip}:${port} on $label..."
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would reconfigure $container WebUI to http://${target_ip}:${port}/"
return 0
fi
local template
template=$(timeout "$SSH_TIMEOUT" ssh -i "$ssh_key" \
-o ConnectTimeout="$SSH_TIMEOUT" root@"$remote_ip" \
"grep -rl '<WebUI>' /boot/config/plugins/dockerMan/templates-user/ 2>/dev/null | \
xargs grep -l '\"$container\"' 2>/dev/null | head -1" 2>/dev/null)
if [[ -z "$template" ]]; then
warn "$container template not found on $label — WebUI needs manual reconfiguration"
return 1
fi
timeout "$SSH_TIMEOUT" ssh -i "$ssh_key" \
-o ConnectTimeout="$SSH_TIMEOUT" root@"$remote_ip" \
"sed -i 's|<WebUI>.*</WebUI>|<WebUI>http://${target_ip}:${port}/</WebUI>|g' '$template'" \
2>/dev/null && \
log "$container → http://${target_ip}:${port}/ ✅" || {
error "Failed to reconfigure $container WebUI on $label"
return 1
}
}
# Reconfigure local auth WebUIs to target IP
reconfigure_local_webuis() {
local target_ip="$1"
log "Reconfiguring local auth WebUIs → ${target_ip}..."
local failures=0
for entry in "${PARTNERSHIP_AUTH_WEBUIS[@]}"; do
[[ -z "$entry" ]] && continue
local container="${entry%%|*}"
local port="${entry##*|}"
local template
template=$(grep -rl '<WebUI>' \
/boot/config/plugins/dockerMan/templates-user/ 2>/dev/null | \
xargs grep -l "\"$container\"" 2>/dev/null | head -1)
if [[ -z "$template" ]]; then
warn "$container template not found locally"
(( failures++ ))
continue
fi
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would reconfigure $container → http://${target_ip}:${port}/"
continue
fi
sed -i "s|<WebUI>.*</WebUI>|<WebUI>http://${target_ip}:${port}/</WebUI>|g" \
"$template" 2>/dev/null && \
log "$container → http://${target_ip}:${port}/ ✅" || \
{ error "Failed to reconfigure $container"; (( failures++ )); }
done
return $failures
}
get_tailscale_device_id() {
local hostname="$1"
@@ -941,15 +874,16 @@ revoke_emby_admin() {
}
check_both_healthy() {
mountpoint -q /mnt/user 2>/dev/null || { error "Local array not healthy"; return 1; }
platform_storage_healthy || { error "Local array not healthy"; return 1; }
local mirror_ip
local mirror_ip _spath
mirror_ip=$(resolve_tailscale_ip "$MIRROR")
[[ -z "$mirror_ip" ]] && { error "Cannot resolve $MIRROR Tailscale IP"; return 1; }
_spath=$(platform_storage_path)
timeout "$SSH_TIMEOUT" ssh -i "$MIRROR_SSH_KEY" \
-o ConnectTimeout="$SSH_TIMEOUT" root@"$mirror_ip" \
"mountpoint -q /mnt/user && timeout 10 docker ps" >/dev/null 2>&1 || {
"mountpoint -q '$_spath' && timeout 10 docker ps" >/dev/null 2>&1 || {
error "Mirror $MIRROR not healthy"
return 1
}
@@ -972,12 +906,7 @@ do_final_sync() {
fi
done
else
bash "$SCRIPT_DIR/../Rsync/rsync.sh" \
"/mnt/user/appdata-Fallback/Critical-Data" \
--profile=critical-fallback --log
bash "$SCRIPT_DIR/../Rsync/rsync.sh" \
"/mnt/user/Media_Server/Emby" \
--profile=emby-fallback --log
warn "CRITICAL_SYNC_SHARES is empty — skipping final sync (configure in host*.conf)"
fi
else
warn "DRY RUN — would run final critical sync (${#CRITICAL_SYNC_SHARES[@]:-hardcoded} shares)"
@@ -1234,26 +1163,14 @@ if [[ "$MODE" == "onboard" ]]; then
echo ""
echo "Enabling partnership in master.conf..."
if [[ "$DRY_RUN" == false ]]; then
if command -v php &>/dev/null; then
php -r "
require_once '/usr/local/emhttp/plugins/varaverk/include/config.php';
\$master = vv_read_conf_raw('master.conf');
\$master = preg_replace('/^\s*PARTNERSHIP_ENABLED\s*=.*/m', 'PARTNERSHIP_ENABLED=true', \$master);
if (vv_write_conf_raw('master.conf', \$master)) {
\$results = vv_push_master_conf();
foreach (\$results as \$r) {
echo \$r['host'] . ': ' . (\$r['ok'] ? 'pushed' : 'FAILED — ' . \$r['error']) . PHP_EOL;
}
echo 'PARTNERSHIP_ENABLED=true' . PHP_EOL;
} else {
echo 'write_failed' . PHP_EOL;
}
" 2>/dev/null | grep -v '^$' | while IFS= read -r line; do
[[ "$line" == "PARTNERSHIP_ENABLED=true" ]] && log "PARTNERSHIP_ENABLED=true in master.conf ✅" || log "$line"
done
local _master_conf="${SCRIPTS_ROOT:-$(dirname "$SCRIPT_DIR")}/master.conf"
if grep -q "^[[:space:]]*PARTNERSHIP_ENABLED=" "$_master_conf" 2>/dev/null; then
sed -i "s|^[[:space:]]*PARTNERSHIP_ENABLED=.*|PARTNERSHIP_ENABLED=true|" "$_master_conf"
else
warn "php not available — set PARTNERSHIP_ENABLED=true in master.conf manually"
echo "PARTNERSHIP_ENABLED=true" >> "$_master_conf"
fi
log "PARTNERSHIP_ENABLED=true in master.conf ✅"
platform_push_conf | while IFS= read -r line; do log "$line"; done
else
warn "DRY RUN — would set PARTNERSHIP_ENABLED=true in master.conf and push"
fi
@@ -1267,8 +1184,7 @@ if (vv_write_conf_raw('master.conf', \$master)) {
else
echo "${flag_key}=true" >> "$local_state_file"
fi
command -v php &>/dev/null && \
php -r "require_once '/usr/local/emhttp/plugins/varaverk/include/config.php'; vv_push_setup_state();" 2>/dev/null || true
platform_push_setup_state
log "${MY_ID}_LOCAL_DONE=true written to setup.db ✅"
else
warn "DRY RUN — would write ${MY_ID}_LOCAL_DONE=true"