-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_pis.sh
executable file
·56 lines (41 loc) · 1.31 KB
/
update_pis.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
#!/bin/bash
set -euo pipefail
# Devices maps Raspberry Pi IP address or name (if set in ssh config) to
# architecture. Binaries of the given architecture will be pushed to that pi.
declare -rA devices=(
["rpi"]="armv7"
["192.168.1.35"]="armv6"
)
readonly binary_name="iotcorelogger"
readonly service_name="iotcorelogger"
readonly commit="$(git rev-parse --verify --short HEAD)"
echo "Updating to binaries at commit ${commit}"
update_device() {
if [ "$#" -ne 2 ]; then
echo "expected two arguments"
return 2
fi
readonly device="$1"
if [ -z "${device}" ]; then
echo "expected device to be non-empty"
return 2
fi
readonly arch="$2"
if [ -z "${arch}" ]; then
echo "expected arch to be non-empty"
return 2
fi
readonly new_binary="${binary_name}_${arch}_${commit}"
echo -e "\n#################################################"
echo "# ${device}" "${arch}"
echo "#################################################"
ssh "${device}" "sudo systemctl stop ${service_name}.service"
scp "out/${arch}/${binary_name}" "${device}:~/${new_binary}"
ssh "${device}" "rm -f ${binary_name} && ln -s ${new_binary} ${binary_name}"
ssh "${device}" "sudo systemctl start ${service_name}.service"
}
for d in "${!devices[@]}"; do
arch="${devices[$d]}"
update_device "${d}" "${arch}" &
done
wait