Fix four audit findings; simplify apply.sh boolean gate

- uninstall.sh: track _restore_failed separately from RESTORED so
  "No backup files found" only prints when find returns nothing (not
  when mv fails on existing backups); abort with exit 1 before rm -rf
  when any restore fails, leaving PATCH_DIR and recover.sh intact
- install.sh: extend log-scan grep to catch ERROR: lines from
  patch_ui.py (backup OSError was silently missed by WARNING:-only grep)
- install.sh: reword restart-failure message — hook IS already
  registered and sitecustomize.py IS installed; patch activates on
  next boot regardless
- apply.sh: replace `if $_can_install` with `[ "$_can_install" = true ]`
  (explicit test, no implicit command lookup); drop 2>/dev/null on
  install cp so OS error detail reaches the log
This commit is contained in:
2026-06-15 16:26:00 +00:00
parent 0b597387bd
commit fa6f6605b0
3 changed files with 17 additions and 5 deletions
+5 -3
View File
@@ -98,7 +98,7 @@ echo ""
echo "Patch log ($PATCH_DIR/apply.log):"
tail -30 "$PATCH_DIR/apply.log"
echo ""
if tail -c "+$((_log_start + 1))" "$PATCH_DIR/apply.log" 2>/dev/null | grep -q "WARNING:"; then
if tail -c "+$((_log_start + 1))" "$PATCH_DIR/apply.log" 2>/dev/null | grep -qE "WARNING:|ERROR:"; then
echo "WARNING: apply.sh reported one or more issues — see log above for details."
echo ""
fi
@@ -108,8 +108,10 @@ fi
echo "Restarting middlewared so the backend patch takes effect ..."
if ! systemctl restart middlewared; then
echo "" >&2
echo "ERROR: middlewared failed to restart. The patch files are installed but" >&2
echo "the hook is not yet active. Check the system log for the root cause:" >&2
echo "ERROR: middlewared failed to restart." >&2
echo " The patch IS installed and will activate automatically on the next boot." >&2
echo " To activate now, resolve the issue below and run: systemctl restart middlewared" >&2
echo " Check the system log for the root cause:" >&2
echo " journalctl -u middlewared -n 50" >&2
echo "If the problem is unrelated to this patch, recover with:" >&2
echo " bash $PATCH_DIR/recover.sh" >&2
+2 -2
View File
@@ -97,8 +97,8 @@ else
fi
fi
if $_can_install; then
if cp "$PATCH_DIR/sitecustomize.py" "$SITE_PKG/sitecustomize.py" 2>/dev/null; then
if [ "$_can_install" = true ]; then
if cp "$PATCH_DIR/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?)"
+10
View File
@@ -102,6 +102,7 @@ echo ""
echo "Restoring UI bundle backup ..."
RESTORED=0
_restore_failed=0
while IFS= read -r backup; do
original="${backup%.pre-truecloud-patch}"
if mv "$backup" "$original"; then
@@ -109,11 +110,20 @@ while IFS= read -r backup; do
RESTORED=1
else
echo " WARNING: Could not restore $original — backup left at $backup"
_restore_failed=1
fi
# Keep these paths in sync with WEBUI_CANDIDATES in patch/patch_ui.py
done < <(find /usr/share/truenas /usr/share/truenas-ui /var/www/truenas \
-name "*.js.pre-truecloud-patch" 2>/dev/null)
if [ "$_restore_failed" -eq 1 ]; then
echo ""
echo "ERROR: One or more UI bundle backups could not be restored." >&2
echo " $PATCH_DIR has been left intact (recover.sh and patch files are safe)." >&2
echo " Restore the backup(s) manually, then re-run uninstall.sh." >&2
exit 1
fi
if [ "$RESTORED" -eq 0 ]; then
echo " No backup files found."
echo " The UI patch will be undone automatically by the next TrueNAS update."