Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!
Did you like my answer?
Based on the context provided, it seems like you are trying to use a tar command within an action handler script to update a directory by extracting a tar.gz file. The error you are encountering suggests that the output of your script is not being parsed correctly as a JSON string.
Here are a few things you might want to check or try:
Ensure JSON Output: Make sure that the output of your script is a valid JSON string. The error message indicates that the output could not be parsed as JSON. Double-check the format of the JSON string you are echoing. It should be properly formatted, e.g., echo '{"status": "ok", "message": "New file updated"}'.
Error Handling: Consider adding error handling to your script to catch any issues with the cp or tar commands. This can help ensure that any errors are properly reported and do not interfere with the JSON output. For example:
if ! cp $SECONDARY_FIRMWARE_PATH /home/torizon/update.tar.gz; then
echo '{"status": "error", "message": "Failed to copy update package"}'
exit 1
fi
if ! tar -xvzf /home/torizon/update.tar.gz -C /home/torizon/polardelight/updates; then
echo '{"status": "error", "message": "Failed to extract update package"}'
exit 1
fi
echo '{"status": "ok", "message": "New file updated"}'
exit 0
Script Execution: Ensure that the script is being executed in an environment where all necessary variables (like $SECONDARY_FIRMWARE_PATH) are correctly set and accessible.
If these suggestions do not resolve the issue, you may need to provide more context or details about the environment and how the script is being executed.
Please, also check if these links can help you solve your problem:
The only way to get this error is if your action handler returned something other than an exit code of 0. This would mean something failed in your action handler. Could you share your full Aktualizr logs of the attempted update. If your action handler script gave some non-zero exit code then there should be a line like:
Ahh okay wait I see what is happening here. The issue is not the exit code it’s the output your script is producing actually.
Notice on your tar command you have the flag for verbose (-v). This produces a lot of non-json output from your script. The only output that is expected from the action handler is json i.e ({"status": "ok", "message": "New file updated"}). Since you have the verbose flag though it produces a lot of unexpected output that the system doesn’t know how to handle/parse.
Either you remove the verbose flag from tar and then the update should work. Or you redirect the output elsewhere so it’s not in the stdout of your action-handler script. You can redirect the output to a log file somewhere if you want to keep the output for review later.
Keep in mind you must make sure no non-json output is being produced from your action handler. This includes errors. For example normally cp is a “silent” command if successful, but if it fails then it produces something like:
cp: cannot stat 'foo': No such file or directory
To not break things you must redirect potential error messages as well. Again either redirect to a log file somewhere or redirect to /dev/null.
As I said before, while designing your action handler script be aware of any command that produces output on stdout or stderr. Otherwise you’ll end up in a similar situation.