-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-robot-radio
executable file
·46 lines (34 loc) · 1.48 KB
/
install-robot-radio
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
#!/bin/sh
set -e
BINARY_FILE=frc-radio-api
USER=root
SSH_ARGS="-o ConnectTimeout=5 -o StrictHostKeyChecking=no"
API_PORT=80
read -p "Device IP address: " TARGET
TARGET=${TARGET:-$DEFAULT_TARGET}
read -p "Set API password (leave blank to disable): " PASSWORD
read -p "Set firmware decryption secret key (leave blank to disable): " FIRMWARE_KEY
# Optionally build the binary.
if [ "$1" = "--build" ]; then
echo "Building binary..."
GOOS=linux GOARCH=arm go build -tags robot -o $BINARY_FILE
fi
echo "\nDeploying to $TARGET..."
# Stop the API if it is running to avoid a file conflict.
ssh $SSH_ARGS $USER@$TARGET "/etc/init.d/frc-radio-api stop 2>/dev/null || true"
# Copy over the API binary.
scp -O $SSH_ARGS $BINARY_FILE $USER@$TARGET:/usr/bin/
# Copy over the API init script.
scp -O $SSH_ARGS robot-radio.init $USER@$TARGET:/etc/init.d/frc-radio-api
# Create the API password file.
ssh $SSH_ARGS $USER@$TARGET "echo $PASSWORD > /root/frc-radio-api-password.txt"
# Create the firmware decryption secret key file.
ssh $SSH_ARGS $USER@$TARGET "echo $FIRMWARE_KEY > /root/frc-radio-api-firmware-key.txt"
# Start the API server.
ssh $SSH_ARGS $USER@$TARGET "chmod +x /usr/bin/frc-radio-api /etc/init.d/frc-radio-api && \
(ln -s ../init.d/frc-radio-api /etc/rc.d/S11frc-radio-api || true) && \
/etc/init.d/frc-radio-api start"
echo "\nChecking health..."
sleep 1
(curl -s --fail "http://$TARGET:$API_PORT/health" | grep OK) || (echo "Health check failed." && exit 1)
echo "\nDeployed successfully."