Harden for Python 3.12+, add disclaimer, audit for robustness

- sitecustomize.py: replace deprecated find_module/load_module with
  find_spec/exec_module (required for Python 3.12+ / TrueNAS SCALE 25.x)
- apply.sh: remove set -e (PREINIT must not fail catastrophically);
  detect middlewared's actual Python binary instead of assuming python3;
  log rotation to avoid unbounded growth; independent failure per step
- patch_ui.py: detect multiple bundle matches; include TrueNAS version
  in pattern-not-found warning; better MARKER specificity
- uninstall.sh: mirror Python detection logic from apply.sh
- README: lead with Storj $5→$50 price context; prominent unsupported
  disclaimer; Python version compatibility matrix; post-update checklist
- Add MIT LICENSE
This commit is contained in:
2026-06-15 02:13:24 +00:00
parent 21b9333324
commit 0a54bcba9d
8 changed files with 559 additions and 211 deletions
+41 -13
View File
@@ -1,5 +1,5 @@
#!/bin/bash
# uninstall.sh — removes all traces of the patch from a TrueNAS box.
# uninstall.sh — remove all traces of truecloud-patch from a TrueNAS box.
set -euo pipefail
@@ -8,12 +8,20 @@ PATCH_DIR="/data/truecloud-patch"
echo "=== TrueNAS TrueCloud Provider Patch — Uninstall ==="
echo ""
if [ "$(id -u)" -ne 0 ]; then
echo "ERROR: must be run as root." >&2
exit 1
fi
if ! command -v midclt &>/dev/null; then
echo "ERROR: midclt not found. Run this script on TrueNAS SCALE." >&2
exit 1
fi
# ── Remove PREINIT registration ───────────────────────────────────────────────
# ── Remove PREINIT hook ───────────────────────────────────────────────────────
echo "Removing PREINIT boot hook ..."
IDS=$(midclt call initshutdownscript.query '[]' | \
python3 -c "
import sys, json
@@ -25,46 +33,67 @@ for s in json.load(sys.stdin):
if [ -n "$IDS" ]; then
for id in $IDS; do
midclt call initshutdownscript.delete "$id" > /dev/null
echo "Removed initshutdownscript id=$id"
echo " Removed initshutdownscript id=$id"
done
else
echo "No initshutdownscript entry found (already removed or never installed)."
echo " No entry found (already removed or never installed)."
fi
echo ""
# ── Remove sitecustomize.py ───────────────────────────────────────────────────
SITE_PKG=$(python3 -c "import site; print(site.getsitepackages()[0])" 2>/dev/null || true)
echo "Removing sitecustomize.py ..."
# Use the same Python detection logic as apply.sh
PYTHON="python3"
if [ -x /usr/bin/middlewared ]; then
shebang=$(dd if=/usr/bin/middlewared bs=256 count=1 2>/dev/null | head -1 || true)
if [[ "$shebang" =~ ^'#!'(/[^[:space:]]+python[^[:space:]]*) ]]; then
PYTHON="${BASH_REMATCH[1]}"
fi
fi
SITE_PKG=$("$PYTHON" -c "import site; print(site.getsitepackages()[0])" 2>/dev/null || true)
if [ -n "$SITE_PKG" ] && [ -f "$SITE_PKG/sitecustomize.py" ]; then
if grep -q "truecloud-patch" "$SITE_PKG/sitecustomize.py" 2>/dev/null; then
rm "$SITE_PKG/sitecustomize.py"
echo "Removed $SITE_PKG/sitecustomize.py"
echo " Removed $SITE_PKG/sitecustomize.py"
# Restore a pre-existing sitecustomize.py if we backed one up
if [ -f "$SITE_PKG/sitecustomize.py.pre-truecloud-patch" ]; then
mv "$SITE_PKG/sitecustomize.py.pre-truecloud-patch" \
"$SITE_PKG/sitecustomize.py"
echo "Restored previous sitecustomize.py"
echo " Restored previous sitecustomize.py"
fi
else
echo " $SITE_PKG/sitecustomize.py is not ours; leaving it alone."
fi
else
echo " Not found (already removed or install didn't place it here)."
fi
echo ""
# ── Restore UI bundle backup ──────────────────────────────────────────────────
# ── Restore UI bundle ─────────────────────────────────────────────────────────
echo "Restoring UI bundle backup ..."
RESTORED=0
for backup in $(find /usr/share/truenas /var/www/truenas -name "*.js.pre-truecloud-patch" 2>/dev/null); do
for backup in $(find /usr/share/truenas /var/www/truenas \
-name "*.js.pre-truecloud-patch" 2>/dev/null); do
original="${backup%.pre-truecloud-patch}"
mv "$backup" "$original"
echo "Restored: $original"
echo " Restored: $original"
RESTORED=1
done
if [ "$RESTORED" -eq 0 ]; then
echo "No UI bundle backups found (patch will be undone by the next TrueNAS update)."
echo " No backup files found."
echo " The UI patch will be undone automatically by the next TrueNAS update."
fi
echo ""
# ── Remove patch directory ────────────────────────────────────────────────────
if [ -d "$PATCH_DIR" ]; then
rm -rf "$PATCH_DIR"
echo "Removed $PATCH_DIR"
@@ -73,6 +102,5 @@ echo ""
echo "Restarting middlewared ..."
systemctl restart middlewared
echo ""
echo "Uninstall complete. Refresh your browser to see the restored UI."