summaryrefslogtreecommitdiff
path: root/ControllerFirmware/flash-controller.sh
blob: eda9b5adbfe9cc90e758f5053f30c1a69364730e (plain)
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
#!/usr/bin/env bash
# ===================================================================
#  NRL - Flash the Controller  (launcher, macOS / Linux)
#  Writes the prebuilt controller firmware to a plugged-in controller.
#  Usage:  bash flash-controller.sh    (or chmod +x and run it)
# ===================================================================
set -euo pipefail

here="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
script="$here/flash_controller.py"

# Find a usable Python 3 via the kit's installer helper (in ../tools/);
# if this ControllerFirmware folder was copied without tools/, fall back
# to whatever python3 is already on this machine.
pyexe=""
if [ -f "$here/../tools/ensure-python.sh" ]; then
    pyexe="$(bash "$here/../tools/ensure-python.sh")" || pyexe=""
fi
if [ -z "$pyexe" ] && command -v python3 >/dev/null 2>&1; then
    pyexe="python3"
fi
if [ -z "$pyexe" ]; then
    echo "[error] Python 3 was not found and could not be installed automatically." >&2
    echo "        Install Python 3 from https://www.python.org/downloads/ and re-run." >&2
    exit 1
fi
exec "$pyexe" "$script" "$@"