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:
+121
-9
@@ -17,8 +17,9 @@
|
||||
# ── FUNCTIONS ─────────────────────────────────────────────────────────────────────────────────
|
||||
# platform_require_cmd — verify a platform command exists and is executable
|
||||
# platform_storage_healthy — array mounted and shfs active on /mnt/user
|
||||
# platform_get_disk_states — raw disks.ini content from emhttp state
|
||||
# platform_get_temp_thresholds — disk warn/crit °C from dynamix.cfg
|
||||
# platform_disk_states_path — path to the platform disk state file
|
||||
# platform_get_disk_states — raw disk state content from platform
|
||||
# platform_get_temp_thresholds — disk warn/crit °C from platform config
|
||||
# platform_is_maintenance_running — parity check/sync in progress
|
||||
# platform_is_service_enabled — docker or libvirt enabled in boot config
|
||||
# platform_restart_service — restart a named service via rc.d
|
||||
@@ -27,6 +28,14 @@
|
||||
# platform_is_mover_running — unRAID mover process check
|
||||
# platform_stop_user_scripts — kill all user.scripts background processes
|
||||
# platform_send_os_notification — native unRAID notify (dynamix)
|
||||
# platform_storage_path — root path for user shares/storage (e.g. /mnt/user)
|
||||
# platform_webui_install_path — where the platform serves the WebGUI plugin files from
|
||||
# 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_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
|
||||
# ==============================================================================================
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
@@ -79,23 +88,30 @@ platform_storage_healthy() {
|
||||
# Writes raw /var/local/emhttp/disks.ini to stdout.
|
||||
# Returns 1 if the file is absent (array not started or emhttp not running).
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
platform_disk_states_path() {
|
||||
echo "/var/local/emhttp/disks.ini"
|
||||
}
|
||||
|
||||
platform_get_disk_states() {
|
||||
local disks_ini="/var/local/emhttp/disks.ini"
|
||||
local disks_ini
|
||||
disks_ini=$(platform_disk_states_path)
|
||||
[[ -f "$disks_ini" ]] || return 1
|
||||
cat "$disks_ini"
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# platform_get_temp_thresholds
|
||||
# Writes two space-separated values to stdout: WARN_TEMP CRIT_TEMP (°C integers).
|
||||
# Falls back to 45 55 if dynamix.cfg is absent or the keys are missing.
|
||||
# Writes four space-separated values to stdout: HDD_HOT HDD_MAX SSD_HOT SSD_MAX (°C integers).
|
||||
# Falls back to 45/55/60/70 if dynamix.cfg is absent or keys are missing.
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
platform_get_temp_thresholds() {
|
||||
local cfg="/boot/config/plugins/dynamix/dynamix.cfg"
|
||||
local warn crit
|
||||
warn=$(grep -m1 '^diskWarn=' "$cfg" 2>/dev/null | cut -d= -f2 | tr -d '"')
|
||||
crit=$(grep -m1 '^diskCrit=' "$cfg" 2>/dev/null | cut -d= -f2 | tr -d '"')
|
||||
echo "${warn:-45} ${crit:-55}"
|
||||
local hdd_hot hdd_max ssd_hot ssd_max
|
||||
hdd_hot=$(grep -m1 '^hot=' "$cfg" 2>/dev/null | cut -d= -f2 | tr -d '"')
|
||||
hdd_max=$(grep -m1 '^max=' "$cfg" 2>/dev/null | cut -d= -f2 | tr -d '"')
|
||||
ssd_hot=$(grep -m1 '^hotssd=' "$cfg" 2>/dev/null | cut -d= -f2 | tr -d '"')
|
||||
ssd_max=$(grep -m1 '^maxssd=' "$cfg" 2>/dev/null | cut -d= -f2 | tr -d '"')
|
||||
echo "${hdd_hot:-45} ${hdd_max:-55} ${ssd_hot:-60} ${ssd_max:-70}"
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
@@ -200,6 +216,39 @@ platform_stop_user_scripts() {
|
||||
# severity: normal | warning | alert (default: normal)
|
||||
# Returns 1 if the notify script is absent.
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# ── Platform path defaults ─────────────────────────────────────────────────────────────────────
|
||||
# Set here so master.conf and core scripts never contain OS-specific path literals.
|
||||
# host*.conf may override any of these after the adapter is sourced.
|
||||
DOCKER_APPDATA_BASE="${DOCKER_APPDATA_BASE:-/mnt/user/appdata}"
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# platform_storage_path
|
||||
# Writes the root path where user shares and storage are accessible to stdout.
|
||||
# Used by array health checks and disk verification.
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
platform_storage_path() {
|
||||
echo "/mnt/user"
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# platform_webui_install_path
|
||||
# Writes the path where the platform serves WebGUI plugin files from.
|
||||
# On Unraid the PHP WebGUI is served from /boot/, separate from SCRIPTS_DIR.
|
||||
# Returns 1 (empty) if the platform serves directly from SCRIPTS_DIR (no sync needed).
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
platform_webui_install_path() {
|
||||
echo "/boot/config/plugins/varaverk"
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# platform_scripts_dir_probe_cmd
|
||||
# Writes a shell command suitable for running on a remote via SSH to discover
|
||||
# that remote's SCRIPTS_DIR. Each platform exposes its install path differently.
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
platform_scripts_dir_probe_cmd() {
|
||||
echo "grep -m1 'SCRIPTS_DIR' /boot/config/plugins/varaverk/varaverk.cfg 2>/dev/null | cut -d= -f2 | tr -d '\"'"
|
||||
}
|
||||
|
||||
platform_send_os_notification() {
|
||||
local message="$1"
|
||||
local subject="${2:-Varaverk}"
|
||||
@@ -209,3 +258,66 @@ platform_send_os_notification() {
|
||||
[[ -x "$notify_script" ]] || return 1
|
||||
"$notify_script" -e "Varaverk" -s "$subject" -d "$message" -i "$severity" 2>/dev/null
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# platform_get_templates_dir
|
||||
# Writes the path to the Unraid CA docker templates-user directory to stdout.
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
platform_get_templates_dir() {
|
||||
echo "/boot/config/plugins/dockerMan/templates-user"
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# platform_setup_db_path
|
||||
# Writes the path to the persistent Varaverk setup/wizard state database.
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
platform_setup_db_path() {
|
||||
echo "/boot/config/varaverk_setup.db"
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# platform_rebuild_container <container_name>
|
||||
# Rebuilds a container from its stored Unraid CA XML template (stops old, recreates on new
|
||||
# image digest, prunes old image). Returns 1 if the rebuild script is absent or fails.
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
platform_rebuild_container() {
|
||||
local container="$1"
|
||||
local rebuild_script="/usr/local/emhttp/plugins/dynamix.docker.manager/scripts/rebuild_container"
|
||||
[[ -x "$rebuild_script" ]] || return 1
|
||||
"$rebuild_script" "$container" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# platform_push_conf
|
||||
# Pushes master.conf to all listed hosts via the WebGUI PHP API.
|
||||
# Writes per-host push results to stdout. Returns 1 if any host failed.
|
||||
# Returns 0 silently if php is unavailable (caller should warn manually).
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
platform_push_conf() {
|
||||
command -v php &>/dev/null || return 0
|
||||
local rc=0
|
||||
php -r "
|
||||
require_once '/usr/local/emhttp/plugins/varaverk/include/config.php';
|
||||
\$results = vv_push_master_conf();
|
||||
if (empty(\$results)) { echo 'no remote hosts'; exit(0); }
|
||||
\$failed = 0;
|
||||
foreach (\$results as \$r) {
|
||||
echo \$r['host'] . ': ' . (\$r['ok'] ? 'pushed' : 'FAILED — ' . \$r['error']) . PHP_EOL;
|
||||
if (!\$r['ok']) \$failed++;
|
||||
}
|
||||
exit(\$failed > 0 ? 1 : 0);
|
||||
" 2>/dev/null
|
||||
rc=$?
|
||||
return $rc
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
# platform_push_setup_state
|
||||
# Pushes the Varaverk wizard setup state to all partners via the WebGUI PHP API.
|
||||
# No-op if php is unavailable. Always returns 0.
|
||||
# ──────────────────────────────────────────────────────────────────────────────────────────────
|
||||
platform_push_setup_state() {
|
||||
command -v php &>/dev/null || return 0
|
||||
php -r "require_once '/usr/local/emhttp/plugins/varaverk/include/config.php'; vv_push_setup_state();" 2>/dev/null
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user