feat: Aufsetz- und Ausliefer-Skripte der Recovery-Station
setup_pi.sh ist idempotent und laesst eine vorhandene Konfiguration in Ruhe; deploy.sh prueft jedes Image mit nl_mkimage --verify, bevor es etwas uebertraegt. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
df8e796f1e
commit
fda732d6c4
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
# Richtet einen Raspberry Pi als ninlight-Recovery-Station ein. Idempotent:
|
||||
# mehrfaches Ausfuehren aendert nichts und schadet nicht.
|
||||
#
|
||||
# Aufruf: tools/station/setup_pi.sh <pi-host>
|
||||
set -euo pipefail
|
||||
HOST=${1:?Aufruf: tools/station/setup_pi.sh <pi-host>}
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
|
||||
echo "== Voraussetzungen auf $HOST pruefen =="
|
||||
ssh "$HOST" 'set -e
|
||||
systemctl is-active --quiet NetworkManager || { echo "NetworkManager laeuft nicht - dieser Plan setzt ihn voraus" >&2; exit 1; }
|
||||
nmcli -t -f DEVICE,STATE device | grep -q "^wlan0:" || { echo "wlan0 wird nicht von NetworkManager verwaltet" >&2; exit 1; }
|
||||
python3 -c "import sys; sys.exit(0 if sys.version_info >= (3,11) else 1)" || { echo "Python 3.11+ noetig" >&2; exit 1; }
|
||||
echo " ok"'
|
||||
|
||||
echo "== Konfiguration =="
|
||||
scp -q "$HERE/station.conf.example" "$HOST:/tmp/ninlight-station.conf.example"
|
||||
ssh "$HOST" 'set -e
|
||||
if [ -f /etc/ninlight-station.conf ]; then
|
||||
echo " /etc/ninlight-station.conf existiert bereits, bleibt unveraendert"
|
||||
else
|
||||
sudo install -m 0600 /tmp/ninlight-station.conf.example /etc/ninlight-station.conf
|
||||
echo " /etc/ninlight-station.conf aus der Vorlage angelegt"
|
||||
fi
|
||||
rm -f /tmp/ninlight-station.conf.example'
|
||||
|
||||
echo "== Server, CLI und Unit installieren =="
|
||||
scp -q "$HERE/server.py" "$HERE/ninlight-station" "$HERE/ninlight-station.service" "$HOST:/tmp/"
|
||||
ssh "$HOST" 'set -e
|
||||
sudo install -d -m 0755 /opt/ninlight-station /opt/ninlight-station/images
|
||||
sudo install -m 0755 /tmp/server.py /opt/ninlight-station/server.py
|
||||
sudo install -m 0755 /tmp/ninlight-station /usr/local/bin/ninlight-station
|
||||
sudo install -m 0644 /tmp/ninlight-station.service /etc/systemd/system/ninlight-station.service
|
||||
rm -f /tmp/server.py /tmp/ninlight-station /tmp/ninlight-station.service
|
||||
sudo systemctl daemon-reload
|
||||
echo " installiert"'
|
||||
|
||||
echo "== NetworkManager-Profil =="
|
||||
ssh "$HOST" 'set -e
|
||||
. /etc/ninlight-station.conf
|
||||
if nmcli -t -f NAME con show | grep -qx "$AP_CONNECTION"; then
|
||||
sudo nmcli con mod "$AP_CONNECTION" \
|
||||
802-11-wireless.ssid "$SSID" wifi-sec.psk "$PSK" \
|
||||
ipv4.addresses 192.168.8.1/24 ipv4.method shared \
|
||||
connection.autoconnect no
|
||||
echo " Profil $AP_CONNECTION aktualisiert"
|
||||
else
|
||||
sudo nmcli con add type wifi ifname wlan0 con-name "$AP_CONNECTION" ssid "$SSID" \
|
||||
802-11-wireless.mode ap 802-11-wireless.band bg 802-11-wireless.channel 6 \
|
||||
wifi-sec.key-mgmt wpa-psk wifi-sec.proto rsn wifi-sec.pairwise ccmp wifi-sec.group ccmp \
|
||||
wifi-sec.psk "$PSK" \
|
||||
ipv4.method shared ipv4.addresses 192.168.8.1/24 ipv6.method disabled \
|
||||
connection.autoconnect no >/dev/null
|
||||
echo " Profil $AP_CONNECTION angelegt"
|
||||
fi'
|
||||
|
||||
cat <<'EOF'
|
||||
|
||||
Fertig. Die Station ist absichtlich noch AUS.
|
||||
|
||||
Naechste Schritte:
|
||||
tools/station/deploy.sh <pi-host> Images ausliefern
|
||||
ssh <pi-host> ninlight-station on Station einschalten
|
||||
ssh <pi-host> ninlight-station off wieder ausschalten (nicht vergessen)
|
||||
EOF
|
||||
Reference in New Issue
Block a user