-
Notifications
You must be signed in to change notification settings - Fork 0
/
nerves.sh
executable file
·87 lines (79 loc) · 1.59 KB
/
nerves.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash -xe
# ssh|sd|emmc|clean
MEDIA="${1:-ssh}"
# upgrade|complete
TYPE="${2:-upgrade}"
# bbb|rpi4
BOARD="${3:-bbb}"
# $HOST|10.77.3.171
HOST="${4:-$HOST}"
SSHO="-oStrictHostKeyChecking=no"
case $MEDIA in
sd|ssh)
export MIX_ENV=dev
export MIX_TARGET=$BOARD
;;
emmc)
export MIX_ENV=prod
export MIX_TARGET=bbb_emmc
;;
clean)
# ensure NFW_BIN is reset
rm -fr nfw/_build
exit
;;
deps)
mix local.hex --force
mix local.rebar --force
mix archive.install hex nerves_bootstrap --force
cd nfw
export MIX_ENV=dev
export MIX_TARGET=bbb
mix deps.get
export MIX_ENV=dev
export MIX_TARGET=rpi4
mix deps.get
export MIX_ENV=prod
export MIX_TARGET=bbb_emmc
mix deps.get
export -n MIX_ENV
export -n MIX_TARGET
exit
;;
esac
cd nfw
mix firmware
KEY=`pwd`/id_rsa
case $MEDIA in
ssh) #wont work for bbb_emmc
ssh-add $KEY
mix upload $HOST
;;
sd)
case $TYPE in
complete)
mix firmware.burn
sync
;;
upgrade)
IMAGES=_build/${BOARD}_dev/nerves
sudo fwup -aU -i $IMAGES/images/nfw.fw -t $TYPE
sync
;;
esac
;;
emmc)
IMAGES=_build/bbb_emmc_prod/nerves/images
(cd $IMAGES && sftp $SSHO -oIdentityFile=$KEY $HOST) << EOF
put nfw.fw /tmp/
quit
EOF
#iex(1)> cmd "fwup -aU -i /tmp/nfw.fw -d /dev/mmcblk1 -t upgrade"
#fwup: Expecting platform=bbb and architecture=arm
ssh $SSHO -i $KEY $HOST << EOF
r = cmd "fwup -aU -i /tmp/nfw.fw -d /dev/mmcblk1 -t $TYPE"
if r == 0, do: cmd "poweroff"
exit
EOF
;;
esac