-
Notifications
You must be signed in to change notification settings - Fork 14
/
run.sh
executable file
·61 lines (54 loc) · 2.05 KB
/
run.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
#!/bin/bash
set -euo pipefail
## Set [email protected] to decide which machine to run on.
TARGET_SSH=${TARGET_SSH:[email protected]}
## Set PROFILE=release for a release build.
PROFILE=${PROFILE:-debug}
## Set RUN=0 to push a new binary without running it.
RUN=${RUN:-1}
## Set USE_SYSTEMD=0 to run without process supervision (EXAMPLEs never use process supervision).
USE_SYSTEMD=${USE_SYSTEMD:-1}
## Set EXAMPLE=list-sensors to run the list-sensors example rather than mijia-homie.
EXAMPLE=${EXAMPLE:-}
## Set TARGET=aarch64-unknown-linux-gnu to build for aarch64 instead.
## The default is armv7 for Raspbian on a Raspberry Pi.
TARGET=${TARGET:-armv7-unknown-linux-gnueabihf}
if [ $# != 0 ]; then
echo "ERROR: $0 should be configured via the following environment variables:"
echo
grep '^## ' "$0" | sed 's/^## / /'
echo
exit 1
fi
if [ "$PROFILE" = release ]; then
PROFILE_FLAG=--release
elif [ "$PROFILE" = debug ]; then
PROFILE_FLAG=''
else
echo "Invalid profile '$PROFILE'"
exit 1
fi
cargo install cross
if [ "${EXAMPLE}" != "" ]; then
# shellcheck disable=SC2086
time cross build $PROFILE_FLAG --target "$TARGET" --example "$EXAMPLE"
time rsync --progress "target/$TARGET/$PROFILE/examples/$EXAMPLE" "$TARGET_SSH:$EXAMPLE"
else
# shellcheck disable=SC2086
time cross build $PROFILE_FLAG --target "$TARGET" --bin mijia-homie
time rsync --progress "target/$TARGET/$PROFILE/mijia-homie" "$TARGET_SSH:mijia-homie"
fi
if [ "$RUN" = 1 ]; then
if [ "$EXAMPLE" != "" ]; then
# shellcheck disable=SC2029
ssh "$TARGET_SSH" "./$EXAMPLE"
elif [ "$USE_SYSTEMD" = 1 ]; then
scp mijia-homie.service "$TARGET_SSH:mijia-homie.service"
ssh "$TARGET_SSH" sudo mv mijia-homie.service /etc/systemd/system/mijia-homie.service
ssh "$TARGET_SSH" sudo systemctl daemon-reload
ssh "$TARGET_SSH" sudo systemctl restart mijia-homie.service
ssh "$TARGET_SSH" sudo journalctl -u mijia-homie.service --output=cat --follow
else
ssh "$TARGET_SSH" ./mijia-homie
fi
fi