Improve midclt error handling in install.sh

- Capture midclt output via $(...) instead of > /dev/null so that
  failure detail (which midclt writes to stdout on TrueNAS) is
  preserved and shown to the user on error rather than silently
  discarded
- Expand update failure hint from a bare query command to an actionable
  recovery path: show the midclt output, then print the exact delete
  command with the known stale ID so the user can remove it and retry
This commit is contained in:
2026-06-15 17:51:56 +00:00
parent d97b87bc5d
commit 4730de75dd
+8 -5
View File
@@ -72,17 +72,20 @@ for s in json.load(sys.stdin):
if [ -n "$EXISTING_ID" ]; then if [ -n "$EXISTING_ID" ]; then
echo "Already registered (id=$EXISTING_ID). Updating path and enabling ..." echo "Already registered (id=$EXISTING_ID). Updating path and enabling ..."
if ! midclt call initshutdownscript.update "$EXISTING_ID" \ if ! _midclt_out=$(midclt call initshutdownscript.update "$EXISTING_ID" \
"{\"enabled\": true, \"script\": \"$PATCH_DIR/patch/apply.sh\"}" > /dev/null; then "{\"enabled\": true, \"script\": \"$PATCH_DIR/patch/apply.sh\"}" 2>&1); then
echo "ERROR: Failed to update PREINIT hook (id=$EXISTING_ID)." >&2 echo "ERROR: Failed to update PREINIT hook (id=$EXISTING_ID)." >&2
echo " midclt call initshutdownscript.query '[]'" >&2 [ -n "$_midclt_out" ] && echo " midclt: $_midclt_out" >&2
echo " To remove the stale entry and retry:" >&2
echo " midclt call initshutdownscript.delete $EXISTING_ID" >&2
exit 1 exit 1
fi fi
else else
if ! midclt call initshutdownscript.create \ if ! _midclt_out=$(midclt call initshutdownscript.create \
"{\"type\":\"SCRIPT\",\"script\":\"$PATCH_DIR/patch/apply.sh\",\"when\":\"PREINIT\",\"enabled\":true,\"comment\":\"$_HOOK_COMMENT\"}" \ "{\"type\":\"SCRIPT\",\"script\":\"$PATCH_DIR/patch/apply.sh\",\"when\":\"PREINIT\",\"enabled\":true,\"comment\":\"$_HOOK_COMMENT\"}" \
> /dev/null; then 2>&1); then
echo "ERROR: Failed to register PREINIT hook." >&2 echo "ERROR: Failed to register PREINIT hook." >&2
[ -n "$_midclt_out" ] && echo " midclt: $_midclt_out" >&2
exit 1 exit 1
fi fi
echo "Registered." echo "Registered."