UpdateController/news_from_ismas

51 lines
2.0 KiB
Plaintext
Raw Normal View History

2022-06-02 18:11:04 +02:00
# !/bin/bash -
source ./log_helpers
2023-05-30 16:40:25 +02:00
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