forked from frc1418/de
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathde
executable file
·86 lines (74 loc) · 2.33 KB
/
de
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
#!/usr/bin/env bash
# You should set the following environment variables:
# $DE_START_NETWORK_PSK: Password/PSK of your current network
# $DE_ROBOT_NETWORK_PSK: ...of your robot network
# $DE_ROBOT_NETWORK_SSID: The SSID of your robot's network
RED="\e[31m"
CYAN="\e[36m"
YELLOW="\e[33m"
GREEN="\e[32m"
EULER="\e^(iπ)+1=0"
RESET="\e[0m"
function task { printf "${CYAN}$1... ${RESET}"; }
function succ { printf "${GREEN}success.${RESET}\n"; }
function warn { printf "${YELLOW}Warning: $1${RESET}\n" >&2; }
function fail {
if [[ "$1" = "" ]]; then
printf "${RED}failed.${RESET}\n" >&2
else
printf "${RED}$1${RESET}\n" >&2
fi
exit 1
}
# Default options
reconnect=false
if ifconfig en3 &>/dev/null; then ethernet=true; else ethernet=false; fi
tests=true
# Parse flags
while :; do
case "$1" in
--reconnect|-r)
reconnect=true
;;
--wifi|-w)
ethernet=false
;;
--skip-tests|-s)
tests=false
;;
*)
break
esac
shift
done
if [[ -n "$(git status --porcelain)" ]]; then
warn "You have uncommitted changes!"
git status --short
fi
if [[ -z "$DE_START_NETWORK_PSK" ]]; then warn "\$DE_START_NETWORK_PSK not set."; fi
if [[ -z "$DE_ROBOT_NETWORK_PSK" ]]; then warn "\$DE_ROBOT_NETWORK_PSK not set."; fi
if [[ -z "$DE_ROBOT_NETWORK_SSID" ]]; then warn "\$DE_ROBOT_NETWORK_SSID not set."; fi
start_network=$(networksetup -getairportnetwork en0 | cut -d ' ' -f 4)
robot_network=$DE_ROBOT_NETWORK_SSID
cur_ip=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')
rio_ip=$(cut -d '.' -f1-3 <<< $cur_ip).2
function connect {
if $ethernet; then return; fi
if [[ $start_network = $robot_network ]]; then return; fi
task "Connecting to $1"
# Even when networksetup fails, exit status will bizarrely be 0.
# Thus, consider no output success.
if [[ -z "$(networksetup -setairportnetwork en0 $1 $2)" ]]; then succ; else fail; fi
}
if $ethernet; then
task "Pinging RoboRIO at $rio_ip"
ping -c 1 -t 1 $rio_ip >/dev/null
if [ $? = 0 ]; then succ; else fail; fi
fi
connect $robot_network $DE_ROBOT_NETWORK_PSK
if $tests; then
python3 robot/robot.py deploy
else
python3 robot/robot.py deploy --skip-tests
fi
if $reconnect; then connect $start_network $DE_START_NETWORK_PSK; fi