0455
This commit is contained in:
@@ -64,24 +64,41 @@ dispatch_task() {
|
||||
task="$(jq -er '.task_name // empty' <<<"$json")" || task=""
|
||||
task_options="$(jq -r '.task_options // empty' <<<"$json")" || task_options=""
|
||||
|
||||
|
||||
# Pass after-upgrade metadata via -e by augmenting task_options (single source of truth)
|
||||
if [[ "$task" == "afterupgrade_check" ]]; then
|
||||
local attempt corr_id orig_at target_ver
|
||||
attempt="$(jq -r '.attempt // empty' <<<"$json")"
|
||||
corr_id="$(jq -r '.correlation_id // empty' <<<"$json")"
|
||||
orig_at="$(jq -r '.original_emitted_at // empty' <<<"$json")"
|
||||
target_ver="$(jq -r '.target_version // empty' <<<"$json")"
|
||||
# Supports both historic 'afterupgrade_check' and current 'afterupgrade_indoor_check'
|
||||
if [[ "$task" == "afterupgrade_indoor_check" || "$task" == "afterupgrade_check" ]]; then
|
||||
# Extract everything the publisher may send
|
||||
local attempt max_attempts cur_delay corr_id orig_at target_ver tv_full schema
|
||||
attempt="$(jq -r '.attempt // ""' <<<"$json")"
|
||||
max_attempts="$(jq -r '.max_attempts // ""' <<<"$json")"
|
||||
cur_delay="$(jq -r '.current_delay_sec // ""' <<<"$json")"
|
||||
corr_id="$(jq -r '.correlation_id // ""' <<<"$json")"
|
||||
orig_at="$(jq -r '.original_emitted_at // ""' <<<"$json")"
|
||||
target_ver="$(jq -r '.target_version // ""' <<<"$json")"
|
||||
tv_full="$(jq -r '.target_version_full // ""' <<<"$json")"
|
||||
schema="$(jq -r '.schema_version // ""' <<<"$json")"
|
||||
|
||||
[[ -n "$attempt" ]] && task_options+=" -e attempt=${attempt}"
|
||||
[[ -n "$corr_id" ]] && task_options+=" -e correlation_id=${corr_id}"
|
||||
[[ -n "$orig_at" ]] && task_options+=" -e original_emitted_at=${orig_at}"
|
||||
|
||||
if [[ -n "$target_ver" ]]; then
|
||||
local esc_tv=${target_ver//\'/\'\"\'\"\'} # replace ' with '\'' safely
|
||||
task_options+=" -e target_version='${esc_tv}'"
|
||||
# Backfill target_version from target_version_full if missing (e.g., fox200-2.2.1-r6801.bin → 2.2.1-r6801)
|
||||
if [[ -z "$target_ver" && -n "$tv_full" ]]; then
|
||||
target_ver="$(sed -nE 's/.*([0-9]+\.[0-9]+\.[0-9]+-r[0-9]+).*/\1/p' <<<"$tv_full" || true)"
|
||||
fi
|
||||
|
||||
# Safe single-quote escaper for -e 'value'
|
||||
esc() { local s="$1"; printf "%s" "${s//\'/\047}"; }
|
||||
|
||||
# Always pass the vars (even if empty), so the play never sees undefined
|
||||
task_options+=" -e attempt='$(esc "$attempt")'"
|
||||
task_options+=" -e max_attempts='$(esc "$max_attempts")'"
|
||||
task_options+=" -e current_delay_sec='$(esc "$cur_delay")'"
|
||||
task_options+=" -e correlation_id='$(esc "$corr_id")'"
|
||||
task_options+=" -e original_emitted_at='$(esc "$orig_at")'"
|
||||
task_options+=" -e target_version='$(esc "$target_ver")'"
|
||||
task_options+=" -e target_version_full='$(esc "$tv_full")'"
|
||||
task_options+=" -e schema_version='$(esc "$schema")'"
|
||||
fi
|
||||
|
||||
|
||||
if [[ -z "$device" || -z "$task" ]]; then
|
||||
warn "payload missing required keys (inscope_device/task_name). Skipping."
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user