Repo is the install location; all scripts self-locate
Users now clone to a persistent ZFS pool and the repo stays in place. No files are copied on install — the PREINIT hook points directly into the clone. Scripts derive PATCH_DIR from their own path at runtime. - install.sh: PATCH_DIR=$(dirname $0); register patch/apply.sh as PREINIT target; chmod only, no cp; update pipe-install error message - patch/apply.sh: PATCH_DIR=$(dirname $0)/..; substitute PATCH_DIR into sitecustomize.py via sed when writing to site-packages; reference patch_ui.py as patch/patch_ui.py - recover.sh, uninstall.sh: PATCH_DIR=$(dirname $0) - uninstall.sh: look for patch/apply.sh in PREINIT registry - patch/create_task.py: _PATCH_DIR derived from __file__; apply.log path in error message derived from _PATCH_DIR - patch/sitecustomize.py: /data/truecloud-patch remains as placeholder substituted by apply.sh on each install - .gitignore: exclude runtime files (apply.log, hook_status.json, disabled) - README: document clone-to-pool install; update all example paths
This commit is contained in:
+10
-6
@@ -1,7 +1,6 @@
|
||||
#!/bin/bash
|
||||
# /data/truecloud-patch/apply.sh
|
||||
# patch/apply.sh — registered as a TrueNAS PREINIT initshutdownscript.
|
||||
#
|
||||
# Registered as a TrueNAS PREINIT initshutdownscript.
|
||||
# Runs on every boot BEFORE middlewared starts, so patches land before
|
||||
# the first Python process for middlewared is created.
|
||||
#
|
||||
@@ -18,7 +17,8 @@
|
||||
# A failed patch logs a warning and continues; middlewared always starts.
|
||||
# Never use `set -e` in a PREINIT script.
|
||||
|
||||
PATCH_DIR="/data/truecloud-patch"
|
||||
# Derive PATCH_DIR from this script's location (parent of the patch/ directory).
|
||||
PATCH_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
LOG="$PATCH_DIR/apply.log"
|
||||
|
||||
# Rotate log at 512 KB to avoid unbounded growth on a system volume.
|
||||
@@ -32,7 +32,7 @@ exec >> "$LOG" 2>&1
|
||||
echo "=== $(date -Iseconds) ==="
|
||||
|
||||
# Kill switch: if this file exists, skip all patching and exit cleanly.
|
||||
# Recovery: touch /data/truecloud-patch/disabled (then reboot or restart middlewared).
|
||||
# Recovery: touch "$PATCH_DIR/disabled" (then reboot or restart middlewared).
|
||||
if [ -f "$PATCH_DIR/disabled" ]; then
|
||||
echo "Kill switch active ($PATCH_DIR/disabled exists) — patch not applied."
|
||||
echo "To re-enable: rm $PATCH_DIR/disabled"
|
||||
@@ -98,7 +98,11 @@ else
|
||||
fi
|
||||
|
||||
if [ "$_can_install" = true ]; then
|
||||
if cp "$PATCH_DIR/sitecustomize.py" "$SITE_PKG/sitecustomize.py"; then
|
||||
# Substitute PATCH_DIR into the source so sitecustomize.py knows where
|
||||
# to write hook_status.json and check the kill switch at runtime.
|
||||
if sed "s|/data/truecloud-patch|$PATCH_DIR|g" \
|
||||
"$PATCH_DIR/patch/sitecustomize.py" \
|
||||
> "$SITE_PKG/sitecustomize.py"; then
|
||||
echo "OK: Installed sitecustomize.py → $SITE_PKG/sitecustomize.py"
|
||||
else
|
||||
echo "WARNING: Failed to write $SITE_PKG/sitecustomize.py (permission error?)"
|
||||
@@ -110,7 +114,7 @@ fi
|
||||
|
||||
echo "--- UI patch ---"
|
||||
|
||||
"$PYTHON" "$PATCH_DIR/patch_ui.py" || echo "WARNING: patch_ui.py exited non-zero; UI dropdown may still show Storj only."
|
||||
"$PYTHON" "$PATCH_DIR/patch/patch_ui.py" || echo "WARNING: patch_ui.py exited non-zero; UI dropdown may still show Storj only."
|
||||
|
||||
# ── Done ──────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
_STATUS_FILE = "/data/truecloud-patch/hook_status.json"
|
||||
_PATCH_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
_STATUS_FILE = os.path.join(_PATCH_DIR, "hook_status.json")
|
||||
|
||||
|
||||
def make_client(host, api_key, insecure=False):
|
||||
@@ -117,7 +118,7 @@ def cmd_verify():
|
||||
print("All patches installed. Run a test backup to confirm end-to-end.")
|
||||
else:
|
||||
print("One or more patches failed to apply.")
|
||||
print("Check /data/truecloud-patch/apply.log and journalctl -u middlewared")
|
||||
print(f"Check {os.path.join(_PATCH_DIR, 'apply.log')} and journalctl -u middlewared")
|
||||
sys.exit(1)
|
||||
|
||||
def cmd_list_credentials(client, _args):
|
||||
|
||||
Reference in New Issue
Block a user