-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoUpdater
More file actions
executable file
·53 lines (45 loc) · 1.48 KB
/
AutoUpdater
File metadata and controls
executable file
·53 lines (45 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
set -e
COMMAND="$1"
shift
update_parameters() {
MESSAGE="$1"
ENABLED=$(echo "$MESSAGE" | jq -r '.enabled // false')
INTERVAL=$(echo "$MESSAGE" | jq -r '.interval // "weekly"')
# Add your custom logic here
# create event
text="Changing auto updater. enabled=$ENABLED, interval=$INTERVAL"
timestamp=""
detect_change="false"
tedge mqtt pub -q 1 'c8y/s/us' "408,\"${text}\",${timestamp},${detect_change},AutoUpdater.enabled,BOOLEAN,$ENABLED,AutoUpdater.interval,STRING,\"$INTERVAL\""
# Workaround: manually update the digital twin property though normally this is done by the Device Parameter microservice
tedge mqtt pub -r te/device/main///twin/AutoUpdater "{\"enabled\":$ENABLED,\"interval\":\"$INTERVAL\"}"
}
init_parameters() {
# TODO: Does it make sense to have an init command, and a get?
# create event
text="Publishing initial values: auto update. enabled=$ENABLED, interval=$INTERVAL"
timestamp=""
detect_change="false"
ENABLED=false
INTERVAL="unset"
tedge mqtt pub -q 1 'c8y/s/us' "408,\"${text}\",${timestamp},${detect_change},AutoUpdater.enabled,BOOLEAN,$ENABLED,AutoUpdater.interval,STRING,\"$INTERVAL\""
}
get() {
echo "{\"enabled\":true,\"interval\":\"daily\"}"
}
case "$COMMAND" in
init)
init_parameters
;;
set)
update_parameters "$@"
;;
get)
get "$@"
;;
*)
echo "Unknown command. name=$COMMAND" >&2
exit 1
;;
esac