UpdateController/news_from_ismas
Gerhard Hoffmann 0e7f5938c7 1: Wait 5 seconds for ISMAS response.
2: For ISMAS response: check if device_id (=machine_nr) sent from ISMAS
is the same as the local machine_nr. If NO, return 1 (fail).
2023-06-29 13:27:01 +02:00

51 lines
2.0 KiB
Plaintext
Executable File

# !/bin/bash -
source ./log_helpers
if [ "${news_from_ismas_sourced:-1}" = "1" ]; then # include only once
readonly news_from_ismas_sourced=${BASH_SOURCE[0]}
readonly APISM_DIRECT_PORT=7778
updates_available () {
local func="${FUNCNAME[0]}"
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
sleep 5) | nc localhost $APISM_DIRECT_PORT)"
if [ $? -eq 0 ]; then
local trigger="$(echo $json_response | jq -r .Fileupload.TRG)"
local ismas_device_id="$(echo $json_response | jq -r .Dev_ID.Device_ID)"
local machine_nr=$(cat "/etc/machine_nr")
log_info "$func:${LINENO}: json_response=$json_response"
log_info "$func:${LINENO}: apism_trigger=<$trigger> device_id=<$ismas_device_id> machine_nr=<$machine_nr>"
if [ ! -z "$ismas_device_id" -a "$ismas_device_id" != " " ]; then
if [ ! -z "$machine_nr" -a "$machine_nr" != " " ]; then
if [ "$ismas_device_id" != "$machine_nr" ]; then
log_error "$func:${LINENO}: ISMAS DEVICE ID <$ismas_deviceId> != LOCAL_MACHINE_NUMBER <$machine_nr>"
return 1
fi
fi
fi
if grep -qE "WAIT" <<< "$trigger"; then
log_info "$func:${LINENO}: FOUND WAIT TRIGGER"
return 0
fi
else
log_error "$func:${LINENO}: APISM REQUEST FAILED"
fi
return 1
}
update_status () {
local func="${FUNCNAME[0]}"
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
sleep 5) | nc localhost $APISM_DIRECT_PORT)"
local trigger=""
if [ $? -eq 0 ]; then
trigger="$(echo $json_response | jq -r .Fileupload.TRG)"
log_info "$func:${LINENO}: apism_trigger=<$trigger>"
else
log_error "$func:${LINENO}: apism request failed"
fi
echo "$trigger"
}
fi