2022-06-02 18:11:04 +02:00
|
|
|
# !/bin/bash -
|
2022-06-03 19:59:50 +02:00
|
|
|
|
|
|
|
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]}
|
2022-06-03 19:59:50 +02:00
|
|
|
readonly APISM_DIRECT_PORT=7778
|
|
|
|
|
|
|
|
updates_available () {
|
|
|
|
local func="${FUNCNAME[0]}"
|
|
|
|
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
|
2023-06-29 13:27:01 +02:00
|
|
|
sleep 5) | nc localhost $APISM_DIRECT_PORT)"
|
2022-06-03 19:59:50 +02:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
local trigger="$(echo $json_response | jq -r .Fileupload.TRG)"
|
2023-06-29 13:27:01 +02:00
|
|
|
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
|
2022-06-03 19:59:50 +02:00
|
|
|
else
|
2023-06-29 13:27:01 +02:00
|
|
|
log_error "$func:${LINENO}: APISM REQUEST FAILED"
|
2022-06-03 19:59:50 +02:00
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
update_status () {
|
|
|
|
local func="${FUNCNAME[0]}"
|
|
|
|
local json_response="$((echo -n '#M=APISM #C=REQ_ISMASParameter #J={}';
|
2023-06-29 13:27:01 +02:00
|
|
|
sleep 5) | nc localhost $APISM_DIRECT_PORT)"
|
2022-06-03 19:59:50 +02:00
|
|
|
local trigger=""
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
trigger="$(echo $json_response | jq -r .Fileupload.TRG)"
|
2023-06-29 13:27:01 +02:00
|
|
|
log_info "$func:${LINENO}: apism_trigger=<$trigger>"
|
2022-06-03 19:59:50 +02:00
|
|
|
else
|
|
|
|
log_error "$func:${LINENO}: apism request failed"
|
|
|
|
fi
|
|
|
|
echo "$trigger"
|
|
|
|
}
|
|
|
|
fi
|