summaryrefslogtreecommitdiff
path: root/files/common/etc/fsm/update/common.sh
blob: 8218dd59fedd77fa268dcdb158716c03cf5a20e2 (plain)
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
Tbl=/tmp/p2ptbl/update
TblIf=br-mesh
FwDir=/tmp/firmware

# updates global state using current internal state; implicit
# definition of the table format
GS_update () {
    p2ptbl update $Tbl "$NodeId" "$CurFw\t$TargetFw\t$TargetTime\t$AckTime" $TblIf
}

# assemble internal state
CurState=$1
CurTime=$(date +%s)
NodeId=$(cat /proc/sys/kernel/random/boot_id) # TODO: replace with stable machine id
CurFw="$(cat /etc/firmware)"
[ -n "$NodeId" -a -n "$CurFw" ]

# get current global state from p2ptable
p2ptbl init $Tbl
GS=$(p2ptbl get $Tbl $NodeId)
if [ -n "$GS" ]; then
    GSCurFw=$(   echo "$GS" | cut -f1)
    TargetFw=$(  echo "$GS" | cut -f2)
    TargetTime=$(echo "$GS" | cut -f3)
    AckTime=$(   echo "$GS" | cut -f4)
    # update stale firmware entries .. should only happen after manual
    # edit of /etc/firmware
    [ "$CurFw" == "$GSCurFw" ] || GS_update
else
    # no entry exists -> create one
    TargetFw=""
    TargetTime=""
    AckTime=""
    GS_update
fi
FwDst=$FwDir/$TargetFw
contact: Jan Huwald // Impressum