From b56af23cbfad5430cc6e6350ecfe67ebe04df917 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Sun, 15 Mar 2026 23:43:27 +1300 Subject: [PATCH] Add scripts: start, copy ESP32 main, install boot service Made-with: Cursor --- scripts/cp-esp32-main.sh | 4 ++++ scripts/install-boot-service.sh | 20 ++++++++++++++++++++ scripts/led-controller.service | 17 +++++++++++++++++ scripts/start.sh | 5 +++++ 4 files changed, 46 insertions(+) create mode 100644 scripts/cp-esp32-main.sh create mode 100755 scripts/install-boot-service.sh create mode 100644 scripts/led-controller.service create mode 100755 scripts/start.sh diff --git a/scripts/cp-esp32-main.sh b/scripts/cp-esp32-main.sh new file mode 100644 index 0000000..3683e02 --- /dev/null +++ b/scripts/cp-esp32-main.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +# Copy esp32/main.py to the connected ESP32 as /main.py (single line, no wrap). +cd "$(dirname "$0")/.." +pipenv run mpremote fs cp esp32/main.py :/main.py diff --git a/scripts/install-boot-service.sh b/scripts/install-boot-service.sh new file mode 100755 index 0000000..5023851 --- /dev/null +++ b/scripts/install-boot-service.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Install systemd service so LED controller starts at boot. +# Run once: sudo scripts/install-boot-service.sh +set -e +cd "$(dirname "$0")/.." +REPO="$(pwd)" +SERVICE_NAME="led-controller.service" +UNIT_PATH="/etc/systemd/system/$SERVICE_NAME" +if [ ! -f "scripts/led-controller.service" ]; then + echo "Run this script from the repo root." + exit 1 +fi +chmod +x scripts/start.sh +sudo cp "scripts/led-controller.service" "$UNIT_PATH" +sudo systemctl daemon-reload +sudo systemctl enable "$SERVICE_NAME" +echo "Installed and enabled $SERVICE_NAME" +echo "Start now: sudo systemctl start $SERVICE_NAME" +echo "Status: sudo systemctl status $SERVICE_NAME" +echo "Logs: journalctl -u $SERVICE_NAME -f" diff --git a/scripts/led-controller.service b/scripts/led-controller.service new file mode 100644 index 0000000..d9de8e7 --- /dev/null +++ b/scripts/led-controller.service @@ -0,0 +1,17 @@ +[Unit] +Description=LED Controller web server +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=pi +WorkingDirectory=/home/pi/led-controller +Environment=PORT=80 +Environment=PATH=/home/pi/.local/bin:/usr/local/bin:/usr/bin:/bin +ExecStart=/bin/bash /home/pi/led-controller/scripts/start.sh +Restart=on-failure +RestartSec=5 + +[Install] +WantedBy=multi-user.target diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100755 index 0000000..2395416 --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +# Start the LED controller web server (port 80 by default). +cd "$(dirname "$0")/.." +export PORT="${PORT:-80}" +pipenv run run