Compare commits
11
Commits
87633ab50d
...
v1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31e1176c45 | ||
|
|
4f942bd770 | ||
|
|
94c3e2a952 | ||
|
|
5b0048e8db | ||
|
|
0c08275482 | ||
|
|
fb13bb8ae3 | ||
|
|
e6aab7589a | ||
|
|
28266b4441 | ||
|
|
7f1d09c753 | ||
|
|
9d86304b8a | ||
|
|
5ff1089551 |
+4
-2
@@ -38,8 +38,10 @@ C2_URL=http://localhost:8888
|
||||
|
||||
# Icecast (local container — usually no need to change)
|
||||
# Live listening only. Call recording and Discord voice use PulseAudio instead.
|
||||
ICECAST_SOURCE_PASSWORD=hackme
|
||||
ICECAST_ADMIN_PASSWORD=admin
|
||||
# REQUIRED, no default — the container refuses to start without them.
|
||||
# Generate with: openssl rand -base64 24
|
||||
ICECAST_SOURCE_PASSWORD=
|
||||
ICECAST_ADMIN_PASSWORD=
|
||||
ICECAST_HOST=localhost
|
||||
ICECAST_PORT=8000
|
||||
ICECAST_MOUNT=/radio
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# Shell scripts run inside Linux containers. A CRLF shebang there fails as
|
||||
# "bad interpreter: /bin/sh^M", which surfaces only as a container that will
|
||||
# not start. Windows checkouts have core.autocrlf=true, so pin these to LF.
|
||||
*.sh text eol=lf
|
||||
@@ -1,7 +1,12 @@
|
||||
.PHONY: setup test up up-prebuilt pull down logs
|
||||
|
||||
# Local-dev only: seed .env from the example so `make up` has something to read.
|
||||
# A real edge node is provisioned with install.sh (one-shot bootstrap for a
|
||||
# clean Pi — clones, enrolls with C2, pulls prebuilt images):
|
||||
# curl -fsSL https://git.vpn.cusano.net/logan/node-26/raw/tag/v1/install.sh | sudo bash -s -- --help
|
||||
setup:
|
||||
@bash setup.sh
|
||||
@test -f .env || cp .env.example .env
|
||||
@echo ".env ready — edit it, then 'make up' (local build) or 'make up-prebuilt'"
|
||||
|
||||
# Run pytest inside the running edge-node container.
|
||||
# Requires: docker compose up (or at least the edge-node image built).
|
||||
|
||||
@@ -135,21 +135,32 @@ Client/
|
||||
|
||||
## Setup
|
||||
|
||||
### Provision a real node — `install.sh`
|
||||
|
||||
One-shot bootstrap for a clean Raspberry Pi OS (arm64). Installs Docker, clones
|
||||
this repo at the `v1` tag, enrols with C2, pulls the prebuilt images and starts:
|
||||
|
||||
```bash
|
||||
# 1. Copy env template
|
||||
cp .env.example .env
|
||||
|
||||
# 2. Fill in at minimum: NODE_ID and MQTT_BROKER
|
||||
nano .env
|
||||
|
||||
# 3. Build all images (op25 takes ~10-15 minutes first time)
|
||||
docker compose build
|
||||
|
||||
# 4. Start
|
||||
docker compose up -d
|
||||
curl -fsSL https://git.vpn.cusano.net/logan/node-26/raw/tag/v1/install.sh \
|
||||
| sudo bash -s -- --token DRB-xxxx --node-id node-003 \
|
||||
--c2-url https://api.<domain> --mqtt-broker mqtt.<domain>
|
||||
```
|
||||
|
||||
The node will appear as **pending** in the server admin dashboard. An admin must approve it before it becomes operational. After approval, assign a radio system in the dashboard and the node will start decoding automatically.
|
||||
Mint the `--token` at **Settings → Nodes** in the web app (the panel prints the
|
||||
whole command). Run `install.sh --help` for every flag; each also has a
|
||||
`DRB_*` env var. `--build` compiles op25 on the Pi (~1h) instead of pulling.
|
||||
|
||||
### Local dev / manual
|
||||
|
||||
```bash
|
||||
make setup # seeds .env from .env.example
|
||||
nano .env # at minimum: NODE_ID, MQTT_BROKER, C2_URL
|
||||
make up # build locally (op25 ~10-15 min first time)
|
||||
# or: make up-prebuilt # pull images, no local build
|
||||
```
|
||||
|
||||
The node appears as **pending** in the admin dashboard. An admin approves it,
|
||||
then assigns a radio system, and the node starts decoding automatically.
|
||||
|
||||
## Environment Variables (`.env`)
|
||||
|
||||
@@ -167,8 +178,8 @@ The node will appear as **pending** in the server admin dashboard. An admin must
|
||||
| `ICECAST_HOST` | No | `localhost` | Icecast hostname (leave as localhost — host network mode) |
|
||||
| `ICECAST_PORT` | No | `8000` | Icecast HTTP port |
|
||||
| `ICECAST_MOUNT` | No | `/radio` | Icecast mount point |
|
||||
| `ICECAST_SOURCE_PASSWORD` | No | `hackme` | Icecast source password — change this |
|
||||
| `ICECAST_ADMIN_PASSWORD` | No | `hackme` | Icecast admin password — change this |
|
||||
| `ICECAST_SOURCE_PASSWORD` | **Yes** | none | Icecast source password. No default — the container refuses to start without it. `install.sh` generates one; otherwise `openssl rand -base64 24` |
|
||||
| `ICECAST_ADMIN_PASSWORD` | **Yes** | none | Icecast admin password. Same rules |
|
||||
| `OP25_API_URL` | No | `http://localhost:8001` | OP25 container HTTP API |
|
||||
| `OP25_TERMINAL_URL` | No | `http://localhost:8081` | OP25 HTTP terminal (live talkgroup metadata) |
|
||||
|
||||
|
||||
+4
-2
@@ -5,8 +5,10 @@ services:
|
||||
restart: unless-stopped
|
||||
network_mode: host
|
||||
environment:
|
||||
ICECAST_SOURCE_PASSWORD: ${ICECAST_SOURCE_PASSWORD:-hackme}
|
||||
ICECAST_ADMIN_PASSWORD: ${ICECAST_ADMIN_PASSWORD:-admin}
|
||||
# :? not :- — a missing password must stop the stack, not silently
|
||||
# become a credential that is published in this file.
|
||||
ICECAST_SOURCE_PASSWORD: ${ICECAST_SOURCE_PASSWORD:?set ICECAST_SOURCE_PASSWORD in .env (run setup.sh, or openssl rand -base64 24)}
|
||||
ICECAST_ADMIN_PASSWORD: ${ICECAST_ADMIN_PASSWORD:?set ICECAST_ADMIN_PASSWORD in .env (run setup.sh, or openssl rand -base64 24)}
|
||||
|
||||
# No `ports:` here — network_mode: host makes it a no-op either way. The
|
||||
# control API (:8001) and OP25's HTTP terminal (:8081) are unauthenticated,
|
||||
|
||||
@@ -42,7 +42,8 @@ class Settings(BaseSettings):
|
||||
icecast_host: str = "localhost"
|
||||
icecast_port: int = 8000
|
||||
icecast_mount: str = "/radio"
|
||||
icecast_source_password: str = "hackme"
|
||||
# No default: see icecast/entrypoint.sh, which refuses to start without one.
|
||||
icecast_source_password: str = ""
|
||||
|
||||
# PulseAudio — the low-latency path used for call recording and Discord voice.
|
||||
# Liquidsoap (op25 container) writes into the `drb_sink` null sink; we capture
|
||||
|
||||
@@ -7,14 +7,16 @@ A persistent capture process runs for the lifetime of the node. Spawning FFmpeg
|
||||
per call used to lose the first 1-2 s to process startup, which meant short
|
||||
transmissions produced empty files, so capture never stops.
|
||||
|
||||
RAW PCM, NOT MP3 — this is the change everything else hangs off. FFmpeg is
|
||||
asked for s16le/22050/mono on stdout instead of an MP3 stream, so:
|
||||
RAW PCM, NOT A COMPRESSED STREAM — this is the change everything else hangs
|
||||
off. FFmpeg is asked for s16le/22050/mono on stdout instead of an encoded
|
||||
stream, so:
|
||||
|
||||
* silence detection is integer arithmetic over each chunk as it arrives, with
|
||||
no decode, which is what makes AUDIO-DRIVEN call boundaries possible;
|
||||
* trimming is a byte-offset slice, not a second FFmpeg pass;
|
||||
* MP3 encoding happens exactly ONCE, at save time, so uploads are no longer
|
||||
double-encoded.
|
||||
* encoding happens exactly ONCE, at save time, so uploads are no longer
|
||||
double-encoded. That encode is now FLAC (lossless) rather than 16 kbps MP3
|
||||
— see the AUDIO_* constants below for why.
|
||||
|
||||
TWO BUFFERS, TWO JOBS — this split is load-bearing:
|
||||
|
||||
@@ -94,14 +96,32 @@ RING_BUFFER_SECONDS = 30
|
||||
# under PRE_ROLL_SECONDS and well under the shortest utterance we care about.
|
||||
READ_CHUNK_BYTES = 2048
|
||||
|
||||
# Encoder settings for the single encode at save time, matched on purpose to
|
||||
# what Liquidsoap already pushes to Icecast — %mp3(bitrate=16, samplerate=22050,
|
||||
# stereo=false) — so the C2 /upload endpoint keeps receiving exactly the kind of
|
||||
# MP3 it has always received (multipart "audio/mpeg", stored to GCS as .mp3,
|
||||
# then fed to Whisper). MP3_SAMPLE_RATE MUST equal pcm.SAMPLE_RATE: the encode
|
||||
# is a straight pass with no resampling.
|
||||
MP3_BITRATE = "16k"
|
||||
MP3_SAMPLE_RATE = str(pcm.SAMPLE_RATE)
|
||||
# Encoder settings for the single encode at save time.
|
||||
#
|
||||
# This used to be %mp3(bitrate=16) chosen to match what Liquidsoap pushes to
|
||||
# Icecast. That was the wrong thing to match: Icecast is the LISTENING path and
|
||||
# 16 kbps is a bandwidth budget for a live stream, while this file is the
|
||||
# ACCURACY path — it is what Whisper transcribes, and the transcript is what
|
||||
# every downstream stage is hostage to. P25 audio has already been through a
|
||||
# vocoder; 16 kbps MP3 stacked a second lossy stage on top of that, on the one
|
||||
# copy that had to stay faithful.
|
||||
#
|
||||
# FLAC instead: lossless, so the bytes Whisper receives are the bytes PulseAudio
|
||||
# captured. Roughly 1.3 MB/min against 120 KB/min for 16k MP3 — larger, but a
|
||||
# 600 s call is still ~13 MB, inside both Whisper's 25 MB request cap and the
|
||||
# C2 upload_max_bytes (100 MB). Icecast's own 16 kbps stream is untouched;
|
||||
# nothing about the listening path changes.
|
||||
#
|
||||
# AUDIO_SAMPLE_RATE MUST equal pcm.SAMPLE_RATE: the encode is a straight pass
|
||||
# with no resampling. Whisper resamples to 16 kHz itself, so handing it 22050
|
||||
# unresampled keeps the one resample in the pipeline inside the model.
|
||||
AUDIO_SAMPLE_RATE = str(pcm.SAMPLE_RATE)
|
||||
AUDIO_FORMAT = "flac"
|
||||
AUDIO_SUFFIX = ".flac"
|
||||
AUDIO_MIME = "audio/flac"
|
||||
# -compression_level 5 is ffmpeg's default: near-best ratio, and the encode is
|
||||
# off the hot path anyway (once per call, at save).
|
||||
FLAC_COMPRESSION_LEVEL = "5"
|
||||
|
||||
# Bounded so a wedged encoder can never stall the upload path.
|
||||
ENCODE_TIMEOUT_SECONDS = 60.0
|
||||
@@ -218,9 +238,12 @@ class Recording:
|
||||
all_silence: bool = False
|
||||
|
||||
|
||||
async def encode_mp3(audio: bytes, path: Path) -> bool:
|
||||
async def encode_recording(audio: bytes, path: Path) -> bool:
|
||||
"""
|
||||
The one and only encode in the pipeline: raw PCM in, MP3 file out.
|
||||
The one and only encode in the pipeline: raw PCM in, FLAC file out.
|
||||
|
||||
Lossless on purpose — see the AUDIO_* constants above. This file is what
|
||||
Whisper transcribes, so the encode must not throw anything away.
|
||||
|
||||
Module-level rather than a method so tests can substitute it without
|
||||
needing FFmpeg, and so the "exactly one encode per call" property is
|
||||
@@ -233,13 +256,13 @@ async def encode_mp3(audio: bytes, path: Path) -> bool:
|
||||
"-hide_banner", "-nostdin", "-nostats",
|
||||
"-loglevel", "warning", "-y",
|
||||
"-f", "s16le",
|
||||
"-ar", MP3_SAMPLE_RATE,
|
||||
"-ar", AUDIO_SAMPLE_RATE,
|
||||
"-ac", str(pcm.CHANNELS),
|
||||
"-i", "pipe:0",
|
||||
"-ar", MP3_SAMPLE_RATE,
|
||||
"-ar", AUDIO_SAMPLE_RATE,
|
||||
"-ac", str(pcm.CHANNELS),
|
||||
"-b:a", MP3_BITRATE,
|
||||
"-f", "mp3", str(path),
|
||||
"-compression_level", FLAC_COMPRESSION_LEVEL,
|
||||
"-f", AUDIO_FORMAT, str(path),
|
||||
]
|
||||
try:
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
@@ -327,7 +350,7 @@ class CallRecorder:
|
||||
"-loglevel", "warning",
|
||||
"-f", "pulse", "-i", settings.pulse_source,
|
||||
"-ac", str(pcm.CHANNELS),
|
||||
"-ar", MP3_SAMPLE_RATE,
|
||||
"-ar", AUDIO_SAMPLE_RATE,
|
||||
# Raw PCM on stdout. No muxer, so no -flush_packets games: s16le is
|
||||
# a bare byte stream and every byte FFmpeg produces is immediately
|
||||
# readable, which is what keeps arrival timestamps honest.
|
||||
@@ -360,7 +383,7 @@ class CallRecorder:
|
||||
|
||||
async def _run_capture(self) -> None:
|
||||
cmd = self._ffmpeg_command()
|
||||
logger.info(f"Starting capture: ffmpeg -f pulse -i {settings.pulse_source} (s16le/{MP3_SAMPLE_RATE}/mono)")
|
||||
logger.info(f"Starting capture: ffmpeg -f pulse -i {settings.pulse_source} (s16le/{AUDIO_SAMPLE_RATE}/mono)")
|
||||
self._last_stderr_lines.clear()
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
*cmd,
|
||||
@@ -674,9 +697,9 @@ class CallRecorder:
|
||||
|
||||
self._recordings_dir.mkdir(parents=True, exist_ok=True)
|
||||
ts_str = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
|
||||
output_path = self._recordings_dir / f"{ts_str}_{recording.call_id}.mp3"
|
||||
output_path = self._recordings_dir / f"{ts_str}_{recording.call_id}{AUDIO_SUFFIX}"
|
||||
|
||||
if not await encode_mp3(audio, output_path):
|
||||
if not await encode_recording(audio, output_path):
|
||||
output_path.unlink(missing_ok=True)
|
||||
return None
|
||||
|
||||
@@ -766,7 +789,7 @@ class CallRecorder:
|
||||
with open(file_path, "rb") as f:
|
||||
r = await client.post(
|
||||
upload_url,
|
||||
files={"file": (file_path.name, f, "audio/mpeg")},
|
||||
files={"file": (file_path.name, f, AUDIO_MIME)},
|
||||
data=form,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@@ -27,7 +27,8 @@ class RadioBot:
|
||||
self._channel_id: Optional[int] = None
|
||||
self._was_streaming: bool = False
|
||||
|
||||
async def join(self, guild_id: int, channel_id: int, token: str, call_active: bool = False, system_name: str = None) -> bool:
|
||||
async def join(self, guild_id: int, channel_id: int, token: str,
|
||||
call_active: bool = False, system_name: str = None) -> bool:
|
||||
# (Re)start the bot if the token changed or the bot isn't running
|
||||
if self._current_token != token or not self._is_bot_running():
|
||||
if not await self._start_bot(token):
|
||||
|
||||
@@ -8,6 +8,7 @@ from app.internal import credentials
|
||||
|
||||
_CACHE_FILE = Path(settings.config_path) / "systems_cache.json"
|
||||
|
||||
|
||||
async def fetch_and_cache_systems() -> bool:
|
||||
"""Fetch all systems from the C2 server and cache them locally."""
|
||||
if not settings.c2_url:
|
||||
@@ -23,7 +24,7 @@ async def fetch_and_cache_systems() -> bool:
|
||||
r = await client.get(url, headers=headers)
|
||||
r.raise_for_status()
|
||||
systems = r.json()
|
||||
|
||||
|
||||
_CACHE_FILE.parent.mkdir(parents=True, exist_ok=True)
|
||||
_CACHE_FILE.write_text(json.dumps(systems, indent=2))
|
||||
logger.info(f"Cached {len(systems)} systems from C2.")
|
||||
@@ -32,6 +33,7 @@ async def fetch_and_cache_systems() -> bool:
|
||||
logger.warning(f"Failed to fetch systems from C2: {e}. Offline cache will be used.")
|
||||
return False
|
||||
|
||||
|
||||
def load_cached_systems() -> List[Dict[str, Any]]:
|
||||
"""Load cached systems from disk."""
|
||||
if _CACHE_FILE.exists():
|
||||
@@ -41,6 +43,7 @@ def load_cached_systems() -> List[Dict[str, Any]]:
|
||||
logger.error(f"Failed to read systems cache: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def get_cached_system(system_id: str) -> Optional[Dict[str, Any]]:
|
||||
"""Retrieve a single system config from the cache."""
|
||||
systems = load_cached_systems()
|
||||
|
||||
@@ -297,7 +297,11 @@ async def lifespan(app: FastAPI):
|
||||
initial_status = "online" if node_cfg.configured else "unconfigured"
|
||||
await mqtt_manager.publish_status(initial_status)
|
||||
|
||||
active_config = node_cfg.override_config if (node_cfg.override_system_id and node_cfg.override_config) else node_cfg.system_config
|
||||
active_config = (
|
||||
node_cfg.override_config
|
||||
if (node_cfg.override_system_id and node_cfg.override_config)
|
||||
else node_cfg.system_config
|
||||
)
|
||||
if node_cfg.configured and active_config:
|
||||
from app.internal.op25_client import op25_client
|
||||
logger.info("Node is configured — waiting for OP25 API then generating config.")
|
||||
|
||||
@@ -25,12 +25,16 @@ router = APIRouter(prefix="/api", tags=["api"], dependencies=[Depends(auth.requi
|
||||
async def get_status():
|
||||
node_cfg = load_node_config()
|
||||
op25_status = await op25_client.status()
|
||||
|
||||
|
||||
active_tgid = metadata_watcher.current_tgid
|
||||
active_tgid_name = metadata_watcher.current_tgid_name
|
||||
system_name = None
|
||||
|
||||
active_config = node_cfg.override_config if (node_cfg.override_system_id and node_cfg.override_config) else node_cfg.system_config
|
||||
|
||||
active_config = (
|
||||
node_cfg.override_config
|
||||
if (node_cfg.override_system_id and node_cfg.override_config)
|
||||
else node_cfg.system_config
|
||||
)
|
||||
if active_config:
|
||||
system_name = active_config.name
|
||||
if active_tgid:
|
||||
@@ -126,7 +130,7 @@ async def set_override(
|
||||
):
|
||||
node_cfg = load_node_config()
|
||||
config = None
|
||||
|
||||
|
||||
if system_id:
|
||||
from app.internal.system_cacher import get_cached_system
|
||||
cached = get_cached_system(system_id)
|
||||
@@ -139,19 +143,19 @@ async def set_override(
|
||||
config = SystemConfig(**system_config)
|
||||
else:
|
||||
raise HTTPException(400, "Must specify system_id or system_config.")
|
||||
|
||||
|
||||
node_cfg.override_system_id = config.system_id
|
||||
node_cfg.override_config = config
|
||||
save_node_config(node_cfg)
|
||||
|
||||
|
||||
from app.main import _generate_op25_config
|
||||
if not await _generate_op25_config(config):
|
||||
raise HTTPException(500, f"Failed to generate OP25 config for override: {config.name}")
|
||||
|
||||
|
||||
await op25_client.stop()
|
||||
await asyncio.sleep(2)
|
||||
await op25_client.start()
|
||||
|
||||
|
||||
await mqtt_manager._publish_checkin()
|
||||
return {"ok": True}
|
||||
|
||||
@@ -161,20 +165,20 @@ async def revert_config():
|
||||
node_cfg = load_node_config()
|
||||
if not node_cfg.override_system_id:
|
||||
return {"ok": True, "message": "No override active."}
|
||||
|
||||
|
||||
node_cfg.override_system_id = None
|
||||
node_cfg.override_config = None
|
||||
save_node_config(node_cfg)
|
||||
|
||||
|
||||
if node_cfg.system_config:
|
||||
from app.main import _generate_op25_config
|
||||
if not await _generate_op25_config(node_cfg.system_config):
|
||||
raise HTTPException(500, "Failed to regenerate original OP25 config.")
|
||||
|
||||
|
||||
await op25_client.stop()
|
||||
await asyncio.sleep(2)
|
||||
await op25_client.start()
|
||||
|
||||
|
||||
await mqtt_manager._publish_checkin()
|
||||
return {"ok": True}
|
||||
|
||||
@@ -183,10 +187,10 @@ async def revert_config():
|
||||
async def ack_override(timeout_minutes: int = Body(1440)):
|
||||
if not settings.c2_url:
|
||||
raise HTTPException(400, "C2_URL not configured.")
|
||||
|
||||
|
||||
api_key = credentials.get_api_key()
|
||||
headers = {"Authorization": f"Bearer {api_key}"} if api_key else {}
|
||||
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.post(
|
||||
|
||||
@@ -59,7 +59,7 @@ def encodes(monkeypatch):
|
||||
path.write_bytes(audio)
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(recorder_mod, "encode_mp3", _encode)
|
||||
monkeypatch.setattr(recorder_mod, "encode_recording", _encode)
|
||||
return calls
|
||||
|
||||
|
||||
@@ -412,21 +412,31 @@ async def test_a_failed_encode_leaves_no_file_and_no_recording(recorder, monkeyp
|
||||
async def _fail(audio, path):
|
||||
return False
|
||||
|
||||
monkeypatch.setattr(recorder_mod, "encode_mp3", _fail)
|
||||
monkeypatch.setattr(recorder_mod, "encode_recording", _fail)
|
||||
ingest(recorder, T0, T0 + 5.0)
|
||||
await recorder.start_recording("call-1", start_epoch=T0 + 1.0)
|
||||
|
||||
assert await recorder.stop_recording(end_epoch=T0 + 3.0) is None
|
||||
assert list(recorder._recordings_dir.glob("*.mp3")) == []
|
||||
assert list(recorder._recordings_dir.glob("*.flac")) == []
|
||||
|
||||
|
||||
def test_encoder_command_contract_matches_what_c2_expects():
|
||||
"""
|
||||
/upload has always received mono MP3 at 22050 Hz / 16 kbps, and Whisper
|
||||
consumes it downstream. The single encode must not quietly change that.
|
||||
The saved file is what Whisper transcribes, so the encode must stay
|
||||
LOSSLESS and must not resample. It was 16 kbps MP3 — a bitrate copied from
|
||||
Icecast's live stream, i.e. the listening path's budget applied to the
|
||||
accuracy path — which put a second lossy stage on top of the P25 vocoder.
|
||||
|
||||
The sample rate must equal pcm.SAMPLE_RATE or the encode stops being a
|
||||
straight pass and the byte-offset trim arithmetic no longer lines up.
|
||||
"""
|
||||
assert recorder_mod.MP3_SAMPLE_RATE == str(pcm.SAMPLE_RATE) == "22050"
|
||||
assert recorder_mod.MP3_BITRATE == "16k"
|
||||
assert recorder_mod.AUDIO_SAMPLE_RATE == str(pcm.SAMPLE_RATE) == "22050"
|
||||
assert recorder_mod.AUDIO_FORMAT == "flac"
|
||||
assert recorder_mod.AUDIO_SUFFIX == ".flac"
|
||||
assert recorder_mod.AUDIO_MIME == "audio/flac"
|
||||
# No bitrate constant should exist: a bitrate on a lossless codec would mean
|
||||
# someone reintroduced lossy encoding.
|
||||
assert not hasattr(recorder_mod, "MP3_BITRATE")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -523,7 +533,7 @@ async def test_discard_drops_the_audio_without_writing_anything(recorder, encode
|
||||
|
||||
assert not recorder.is_recording
|
||||
assert encodes == []
|
||||
assert list(recorder._recordings_dir.glob("*.mp3")) == []
|
||||
assert list(recorder._recordings_dir.glob("*.flac")) == []
|
||||
# ...and the recorder is immediately reusable.
|
||||
assert await recorder.start_recording("call-next", start_epoch=T0 + 2.0) is True
|
||||
|
||||
|
||||
+13
-2
@@ -1,8 +1,19 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
ICECAST_SOURCE_PASSWORD="${ICECAST_SOURCE_PASSWORD:-hackme}"
|
||||
ICECAST_ADMIN_PASSWORD="${ICECAST_ADMIN_PASSWORD:-admin}"
|
||||
# No defaults here on purpose. This container binds all interfaces, so a
|
||||
# fallback password is a published credential on every node that ever accepted
|
||||
# it -- and the source password is what lets a caller PUSH audio into the
|
||||
# stream the frontend plays as live radio. Refuse to start instead.
|
||||
for var in ICECAST_SOURCE_PASSWORD ICECAST_ADMIN_PASSWORD; do
|
||||
eval "value=\${$var}"
|
||||
if [ -z "$value" ]; then
|
||||
echo "icecast: $var is not set." >&2
|
||||
echo "icecast: set it in the node's .env -- 'bash setup.sh' generates a random one," >&2
|
||||
echo "icecast: or run: openssl rand -base64 24" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
export ICECAST_SOURCE_PASSWORD ICECAST_ADMIN_PASSWORD
|
||||
|
||||
|
||||
+538
@@ -0,0 +1,538 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# DRB edge node — one-shot bootstrap for a clean Raspberry Pi OS (arm64).
|
||||
#
|
||||
# curl -fsSL https://git.vpn.cusano.net/logan/node-26/raw/tag/v1/install.sh \
|
||||
# | sudo bash -s -- --token DRB-xxxx --node-id node-003 \
|
||||
# --c2-url https://api.<domain> --mqtt-broker mqtt.<domain>
|
||||
#
|
||||
# (fetch install.sh from the same tag it installs; use raw/branch/main with
|
||||
# --track-main for the owner's own always-latest nodes)
|
||||
#
|
||||
# Hosting, the pinned ref, and setup.sh's retirement are settled (owner
|
||||
# decisions, 2026-09-06). One standing hazard remains — D3 below.
|
||||
#
|
||||
# What it does, in order:
|
||||
# 1. Preflight (root, arch, apt, SDR present)
|
||||
# 2. Install Docker + compose plugin + git + curl + jq
|
||||
# 3. Clone logan/node-26 at a PINNED ref into $INSTALL_DIR
|
||||
# 4. Write .env (non-interactive from flags/env, interactive fallback)
|
||||
# 5. Enroll with C2 (POST /nodes/enroll) and poll for the api_key
|
||||
# 6. docker compose pull && up -d (prebuilt; --build opts into the ~1h build)
|
||||
# 7. Print the approval step
|
||||
#
|
||||
# It does NOT set up WireGuard. WireGuard-per-node was evaluated and rejected
|
||||
# (Server/MQTT-PUBLIC-AUTH-PLAN.md, Server/infra/main.tf:67-73). A field node
|
||||
# reaches production over the public internet only:
|
||||
# https://api.<domain> enrollment + /upload (Caddy, real TLS)
|
||||
# mqtt.<domain>:8883 MQTT over TLS, username=NODE_ID password=api_key
|
||||
# The two stale "nodes reach it via WireGuard" comments in
|
||||
# Server/docker-compose.prod.yml:6 and Server/infra/main.tf:69 are leftovers.
|
||||
#
|
||||
# ---------------------------------------------------------------------------
|
||||
# SETTLED (owner decisions, 2026-09-06 — node-26#4)
|
||||
#
|
||||
# D1 HOSTING. git.vpn.cusano.net is PUBLIC — it is a CNAME to
|
||||
# cusano-net.duckdns.org (71.117.95.129) with a real Let's Encrypt cert,
|
||||
# resolvable from any public resolver. install.sh, `git clone` and
|
||||
# `docker compose pull` all work from a customer's Pi with no VPN.
|
||||
# Caveat, not a blocker: that IP is a dynamic-DNS record on the owner's
|
||||
# home uplink, so it is a single point of failure and a bandwidth limit
|
||||
# — fine for the beachhead, revisit before scaling node count.
|
||||
#
|
||||
# D2 PIN. node-26 gets a `v1` tag (owner cuts it — see the git command in
|
||||
# the mint panel / node-26#4). DEFAULT_REF below is `v1`. `--track-main`
|
||||
# stays as an opt-in for the owner's own nodes.
|
||||
#
|
||||
# STANDING HAZARD
|
||||
#
|
||||
# D3 SOURCE-OVERLAY. docker-compose.yml bind-mounts ./drb-edge-node/app and
|
||||
# ./op25-container/app OVER the image's /app. So even in prebuilt mode
|
||||
# the running Python is the CLONED REF's code against the pulled image's
|
||||
# dependencies. `v1` == the commit CI built the current :latest/:stable
|
||||
# from, so today they match — but the moment `v1` and the image tags
|
||||
# diverge this silently mixes them. Fix: drop those two mounts from the
|
||||
# prod compose path, or always retag images from the same ref as `v1`.
|
||||
# ---------------------------------------------------------------------------
|
||||
set -euo pipefail
|
||||
|
||||
# ── Defaults ────────────────────────────────────────────────────────────────
|
||||
DEFAULT_REF="v1" # D2
|
||||
DEFAULT_REPO_URL="https://git.vpn.cusano.net/logan/node-26.git" # D1 (public)
|
||||
DEFAULT_INSTALL_DIR="/opt/drb/node-26"
|
||||
|
||||
REPO_URL="${DRB_REPO_URL:-$DEFAULT_REPO_URL}"
|
||||
REF="${DRB_REF:-$DEFAULT_REF}"
|
||||
INSTALL_DIR="${DRB_INSTALL_DIR:-$DEFAULT_INSTALL_DIR}"
|
||||
|
||||
NODE_ID="${DRB_NODE_ID:-}"
|
||||
NODE_NAME="${DRB_NODE_NAME:-}"
|
||||
NODE_LAT="${DRB_NODE_LAT:-}"
|
||||
NODE_LON="${DRB_NODE_LON:-}"
|
||||
C2_URL="${DRB_C2_URL:-}"
|
||||
MQTT_BROKER="${DRB_MQTT_BROKER:-}"
|
||||
MQTT_PORT="${DRB_MQTT_PORT:-8883}"
|
||||
MQTT_TLS="${DRB_MQTT_TLS:-true}"
|
||||
ENROLLMENT_TOKEN="${DRB_ENROLLMENT_TOKEN:-}"
|
||||
DASHBOARD_USER="${DRB_DASHBOARD_USERNAME:-admin}"
|
||||
DASHBOARD_PASS="${DRB_DASHBOARD_PASSWORD:-}"
|
||||
REGISTRY="${DRB_IMAGE_REGISTRY:-git.vpn.cusano.net}" # D1 (public host)
|
||||
DOCKER_ORG="${DRB_DOCKER_ORG:-logan}"
|
||||
DOCKER_REPO="${DRB_DOCKER_REPO:-node-26}"
|
||||
REGISTRY_USER="${DRB_REGISTRY_USER:-}"
|
||||
REGISTRY_PASS="${DRB_REGISTRY_PASS:-}"
|
||||
|
||||
DO_BUILD=0 # 0 = pull prebuilt images (default), 1 = build on the Pi (~1h for op25)
|
||||
DO_START=1
|
||||
ASSUME_YES=0
|
||||
ENROLL_WAIT="${DRB_ENROLL_WAIT:-0}" # seconds to block waiting for admin approval; 0 = don't block
|
||||
|
||||
C='\033[0;36m'; G='\033[0;32m'; Y='\033[1;33m'; R='\033[0;31m'; N='\033[0m'
|
||||
say() { printf "${C}==>${N} %s\n" "$*"; }
|
||||
ok() { printf "${G} ok${N} %s\n" "$*"; }
|
||||
warn() { printf "${Y} !!${N} %s\n" "$*" >&2; }
|
||||
die() { printf "${R}error:${N} %s\n" "$*" >&2; exit 1; }
|
||||
|
||||
usage() {
|
||||
cat <<'USAGE'
|
||||
Usage: install.sh [options]
|
||||
|
||||
--token TOKEN Enrollment token (Settings -> Nodes -> New token)
|
||||
--node-id ID Unique node id, e.g. node-003
|
||||
--name NAME Display name (default: node id)
|
||||
--lat N --lon N Decimal degrees for the map
|
||||
--c2-url URL e.g. https://api.drb.example.net
|
||||
--mqtt-broker HOST e.g. mqtt.drb.example.net
|
||||
--mqtt-port N default 8883
|
||||
--no-tls plaintext MQTT (LAN/dev brokers only)
|
||||
--dashboard-pass PW local dashboard password (generated if omitted)
|
||||
--ref REF git ref to install (default: v1)
|
||||
--track-main install main HEAD instead of the v1 tag
|
||||
--dir PATH install location (default /opt/drb/node-26)
|
||||
--build build images locally instead of pulling (~1h for op25)
|
||||
--no-start configure and enroll, but do not start containers
|
||||
--wait-approval SEC block up to SEC seconds polling for admin approval
|
||||
-y, --yes never prompt; fail instead of asking
|
||||
|
||||
Every option also has an env var: DRB_NODE_ID, DRB_C2_URL, DRB_ENROLLMENT_TOKEN,
|
||||
DRB_MQTT_BROKER, DRB_REF, DRB_INSTALL_DIR, DRB_REGISTRY_USER/PASS, ...
|
||||
Secrets are read from the environment or prompted on the TTY, never from a pipe.
|
||||
USAGE
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--token) ENROLLMENT_TOKEN="$2"; shift 2 ;;
|
||||
--node-id) NODE_ID="$2"; shift 2 ;;
|
||||
--name) NODE_NAME="$2"; shift 2 ;;
|
||||
--lat) NODE_LAT="$2"; shift 2 ;;
|
||||
--lon) NODE_LON="$2"; shift 2 ;;
|
||||
--c2-url) C2_URL="$2"; shift 2 ;;
|
||||
--mqtt-broker) MQTT_BROKER="$2"; shift 2 ;;
|
||||
--mqtt-port) MQTT_PORT="$2"; shift 2 ;;
|
||||
--no-tls) MQTT_TLS=false; [ "$MQTT_PORT" = 8883 ] && MQTT_PORT=1883; shift ;;
|
||||
--dashboard-pass) DASHBOARD_PASS="$2"; shift 2 ;;
|
||||
--ref) REF="$2"; shift 2 ;;
|
||||
--track-main) REF="main"; shift ;;
|
||||
--dir) INSTALL_DIR="$2"; shift 2 ;;
|
||||
--build) DO_BUILD=1; shift ;;
|
||||
--no-start) DO_START=0; shift ;;
|
||||
--wait-approval) ENROLL_WAIT="$2"; shift 2 ;;
|
||||
-y|--yes) ASSUME_YES=1; shift ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) die "unknown option: $1 (try --help)" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Prompts must come from the terminal, not from the `curl |` pipe on stdin.
|
||||
ask() { # ask VAR "prompt" "default"
|
||||
local __v="$1" __p="$2" __d="${3:-}" __r=""
|
||||
if [ "$ASSUME_YES" = 1 ] || [ ! -r /dev/tty ]; then
|
||||
[ -n "$__d" ] || die "$__p is required (non-interactive: pass the flag or env var)"
|
||||
printf -v "$__v" '%s' "$__d"; return
|
||||
fi
|
||||
read -rp "$__p${__d:+ [$__d]}: " __r </dev/tty
|
||||
printf -v "$__v" '%s' "${__r:-$__d}"
|
||||
}
|
||||
ask_secret() {
|
||||
local __v="$1" __p="$2" __r=""
|
||||
if [ "$ASSUME_YES" = 1 ] || [ ! -r /dev/tty ]; then printf -v "$__v" '%s' ''; return; fi
|
||||
read -rsp "$__p: " __r </dev/tty; echo >/dev/tty
|
||||
printf -v "$__v" '%s' "$__r"
|
||||
}
|
||||
genpw() { head -c 24 /dev/urandom | base64 | tr -d '\n=' ; }
|
||||
|
||||
# ── 1. Preflight ────────────────────────────────────────────────────────────
|
||||
say "Preflight"
|
||||
[ "$(id -u)" -eq 0 ] || die "run as root: curl -fsSL <url> | sudo bash -s -- ..."
|
||||
command -v apt-get >/dev/null || die "apt-get not found — this script targets Raspberry Pi OS / Debian"
|
||||
|
||||
ARCH="$(dpkg --print-architecture)"
|
||||
case "$ARCH" in
|
||||
arm64|aarch64) ok "arch $ARCH" ;;
|
||||
*) warn "arch is $ARCH — CI only builds linux/arm64 images. Prebuilt pull will fail; use --build." ;;
|
||||
esac
|
||||
ok "running as root"
|
||||
|
||||
# Not fatal: the dongle can be plugged in after install.
|
||||
if command -v lsusb >/dev/null 2>&1 && lsusb | grep -qiE 'rtl2838|realtek.*283[28]|sdr'; then
|
||||
ok "SDR dongle detected on USB"
|
||||
else
|
||||
warn "no RTL-SDR dongle detected on USB — plug one in before expecting audio"
|
||||
fi
|
||||
|
||||
# ── 2. Dependencies ─────────────────────────────────────────────────────────
|
||||
say "Installing dependencies"
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update -qq
|
||||
apt-get install -y -qq git curl ca-certificates jq usbutils openssl >/dev/null
|
||||
ok "git curl jq openssl"
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
say "Installing Docker (get.docker.com)"
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
fi
|
||||
docker --version >/dev/null || die "docker install failed"
|
||||
ok "$(docker --version)"
|
||||
|
||||
if ! docker compose version >/dev/null 2>&1; then
|
||||
apt-get install -y -qq docker-compose-plugin >/dev/null
|
||||
fi
|
||||
docker compose version >/dev/null 2>&1 || die "docker compose plugin missing"
|
||||
ok "$(docker compose version --short 2>/dev/null || echo 'compose plugin')"
|
||||
|
||||
systemctl enable --now docker >/dev/null 2>&1 || true
|
||||
|
||||
# The docker group only matters for the human who logs in LATER — this script
|
||||
# is already root, so nothing below needs a re-login. setup.sh's bug (add the
|
||||
# group, then immediately run compose in the same unprivileged shell) does not
|
||||
# apply here.
|
||||
TARGET_USER="${SUDO_USER:-}"
|
||||
if [ -n "$TARGET_USER" ] && [ "$TARGET_USER" != root ]; then
|
||||
usermod -aG docker "$TARGET_USER" || true
|
||||
ok "added '$TARGET_USER' to the docker group (takes effect at their next login)"
|
||||
fi
|
||||
|
||||
# ── 3. Fetch the repo at a pinned ref ───────────────────────────────────────
|
||||
say "Fetching node-26 @ ${REF}"
|
||||
mkdir -p "$(dirname "$INSTALL_DIR")"
|
||||
if [ -d "$INSTALL_DIR/.git" ]; then
|
||||
ok "existing install at $INSTALL_DIR — updating in place (.env is preserved)"
|
||||
git -C "$INSTALL_DIR" remote set-url origin "$REPO_URL"
|
||||
git -C "$INSTALL_DIR" fetch --tags --prune origin
|
||||
else
|
||||
git clone --no-checkout "$REPO_URL" "$INSTALL_DIR"
|
||||
fi
|
||||
git -C "$INSTALL_DIR" -c advice.detachedHead=false checkout --force "$REF"
|
||||
RESOLVED_SHA="$(git -C "$INSTALL_DIR" rev-parse HEAD)"
|
||||
ok "checked out $REF ($RESOLVED_SHA)"
|
||||
[ "$REF" = main ] && warn "tracking main — two nodes installed on different days run different software"
|
||||
|
||||
cd "$INSTALL_DIR"
|
||||
mkdir -p configs recordings
|
||||
chmod 700 configs
|
||||
|
||||
# ── 4. Configuration ────────────────────────────────────────────────────────
|
||||
say "Configuring"
|
||||
if [ -f .env ]; then
|
||||
ok ".env already present — keeping it (delete it to reconfigure)"
|
||||
# Re-read the three values section 5 needs. Not `source .env` — that would
|
||||
# execute whatever is in the file.
|
||||
envget() { grep -E "^$1=" .env | head -1 | cut -d= -f2- | tr -d '"'; }
|
||||
NODE_ID="$(envget NODE_ID)"
|
||||
C2_URL="${C2_URL:-$(envget C2_URL)}"; C2_URL="${C2_URL%/}"
|
||||
NODE_NAME="${NODE_NAME:-$(envget NODE_NAME)}"
|
||||
NODE_LAT="${NODE_LAT:-$(envget NODE_LAT)}"
|
||||
NODE_LON="${NODE_LON:-$(envget NODE_LON)}"
|
||||
DASHBOARD_USER="$(envget DASHBOARD_USERNAME)"
|
||||
[ -n "$NODE_ID" ] || die ".env exists but has no NODE_ID — fix or delete it"
|
||||
else
|
||||
[ -n "$NODE_ID" ] || ask NODE_ID "Node ID (e.g. node-003)"
|
||||
[[ "$NODE_ID" =~ ^[A-Za-z0-9_-]+$ ]] || die "NODE_ID must be letters/numbers/dash/underscore only"
|
||||
[ -n "$NODE_NAME" ] || ask NODE_NAME "Display name" "$NODE_ID"
|
||||
[ -n "$NODE_LAT" ] || ask NODE_LAT "Latitude" "0.0"
|
||||
[ -n "$NODE_LON" ] || ask NODE_LON "Longitude" "0.0"
|
||||
[ -n "$C2_URL" ] || ask C2_URL "C2 API base URL (https://api.<domain>)"
|
||||
C2_URL="${C2_URL%/}"
|
||||
[ -n "$MQTT_BROKER" ] || ask MQTT_BROKER "MQTT broker host (mqtt.<domain>)"
|
||||
|
||||
if [ -z "$DASHBOARD_PASS" ]; then
|
||||
ask_secret DASHBOARD_PASS "Local dashboard password (Enter to generate)"
|
||||
[ -n "$DASHBOARD_PASS" ] || { DASHBOARD_PASS="$(genpw)"; GENERATED_DASH=1; }
|
||||
fi
|
||||
ICE_SRC="$(genpw)"; ICE_ADM="$(genpw)"
|
||||
|
||||
umask 077
|
||||
cat > .env <<EOF
|
||||
# Written by install.sh on $(date -Is) from ref ${RESOLVED_SHA}
|
||||
NODE_ID=${NODE_ID}
|
||||
NODE_NAME="${NODE_NAME}"
|
||||
NODE_LAT=${NODE_LAT}
|
||||
NODE_LON=${NODE_LON}
|
||||
|
||||
# MQTT — post-cutover auth. There is NO shared node login: the node
|
||||
# authenticates as username=NODE_ID, password=<its C2-issued api_key>, which
|
||||
# section 5 below fetches into configs/credentials.json. Deliberately no
|
||||
# MQTT_USER/MQTT_PASS here; a dynsec broker rejects them.
|
||||
MQTT_BROKER=${MQTT_BROKER}
|
||||
MQTT_PORT=${MQTT_PORT}
|
||||
MQTT_TLS=${MQTT_TLS}
|
||||
|
||||
C2_URL=${C2_URL}
|
||||
|
||||
ICECAST_SOURCE_PASSWORD=${ICE_SRC}
|
||||
ICECAST_ADMIN_PASSWORD=${ICE_ADM}
|
||||
ICECAST_HOST=localhost
|
||||
ICECAST_PORT=8000
|
||||
ICECAST_MOUNT=/radio
|
||||
|
||||
DASHBOARD_USERNAME=${DASHBOARD_USER}
|
||||
DASHBOARD_PASSWORD=${DASHBOARD_PASS}
|
||||
|
||||
PULSE_SOURCE=drb_sink.monitor
|
||||
OP25_API_URL=http://localhost:8001
|
||||
OP25_TERMINAL_URL=http://localhost:8081
|
||||
OP25_DEBUG_EXPOSE=false
|
||||
|
||||
IMAGE_REGISTRY=${REGISTRY}
|
||||
DOCKER_ORG=${DOCKER_ORG}
|
||||
DOCKER_REPO=${DOCKER_REPO}
|
||||
EOF
|
||||
umask 022
|
||||
chmod 600 .env
|
||||
[ -n "$TARGET_USER" ] && chown "$TARGET_USER" .env 2>/dev/null || true
|
||||
ok ".env written for '$NODE_ID'"
|
||||
fi
|
||||
|
||||
# ── 5. Enrollment ───────────────────────────────────────────────────────────
|
||||
# Client half of Server/drb-c2-core/app/routers/enrollment.py. It does NOT
|
||||
# exist in the edge-node app today (mqtt_manager.py:73-85 says so explicitly),
|
||||
# so without this section a fresh node can never obtain an api_key against a
|
||||
# dynsec broker: MQTT needs the key, and the legacy key-over-MQTT delivery
|
||||
# needs MQTT. Doing it here breaks that loop.
|
||||
#
|
||||
# Two server endpoints, and the exact response shapes verified against
|
||||
# enrollment.py @ v1:
|
||||
#
|
||||
# POST /nodes/enroll (X-Enrollment-Token)
|
||||
# 200 -> {node_id, pickup_secret, approval_status}
|
||||
# 403 -> node_id is ALREADY APPROVED. The CRITICAL GUARD in enrollment.py
|
||||
# refuses to mint a fresh pickup_secret off the shared fleet token.
|
||||
# So we must only ever POST this for a node we have not enrolled
|
||||
# from this machine before — i.e. when configs/pickup_secret is
|
||||
# absent. Re-running the installer must NOT re-POST here.
|
||||
# 401 bad/revoked token · 400 missing node_id · 429 rate limited
|
||||
#
|
||||
# GET /nodes/{id}/credentials (X-Pickup-Secret)
|
||||
# Always HTTP 200 with {approval_status, api_key} unless the secret or
|
||||
# node is bad. api_key is null until an admin approves the node in the UI
|
||||
# (nodes.py approve_node() mints node_keys/{id}.api_key synchronously in
|
||||
# the same call — approve is enough; assigning a system is independent and
|
||||
# NOT required for a key). This endpoint has NO already-approved guard, so
|
||||
# it is the correct — and only working — re-run path after approval.
|
||||
# 401 -> missing/invalid/rotated pickup secret
|
||||
# 404 -> node unknown to C2 (deleted server-side, or never enrolled)
|
||||
CREDS="$INSTALL_DIR/configs/credentials.json"
|
||||
PICKUP_FILE="$INSTALL_DIR/configs/pickup_secret"
|
||||
|
||||
# GET /nodes/{id}/credentials. Sets CRED_HTTP + CRED_BODY (no -f: we need the
|
||||
# body and status on a 4xx). One implementation so first-run and re-run agree.
|
||||
creds_pickup() { # creds_pickup PICKUP_SECRET
|
||||
local _tmp; _tmp="$(mktemp)"
|
||||
CRED_HTTP="$(curl -sS -o "$_tmp" -w '%{http_code}' \
|
||||
"$C2_URL/nodes/$NODE_ID/credentials" -H "X-Pickup-Secret: $1" 2>/dev/null || echo 000)"
|
||||
CRED_BODY="$(cat "$_tmp" 2>/dev/null || true)"
|
||||
rm -f "$_tmp"
|
||||
}
|
||||
cred_field() { printf '%s' "${CRED_BODY:-}" | jq -r "$1 // empty" 2>/dev/null || true; }
|
||||
|
||||
write_creds() { # write_creds API_KEY
|
||||
umask 077; jq -n --arg k "$1" '{api_key:$k}' > "$CREDS"; umask 022
|
||||
ok "api_key received and written to configs/credentials.json"
|
||||
}
|
||||
|
||||
say_pending() { # say_pending APPROVAL_STATUS — not an error: node is enrolled, key not minted yet
|
||||
warn "not approved yet — C2 reports approval_status=${1:-pending}, no api_key minted."
|
||||
warn "an admin must, at <app-url>/settings/nodes : Approve '$NODE_ID' (assigning a system is separate)."
|
||||
warn "then re-run this installer — it reuses configs/pickup_secret — or fetch it directly:"
|
||||
warn " curl -fsS $C2_URL/nodes/$NODE_ID/credentials -H \"X-Pickup-Secret: \$(cat $PICKUP_FILE)\" | jq -r .api_key"
|
||||
}
|
||||
|
||||
# Poll creds_pickup for up to ENROLL_WAIT seconds while still pending. Result
|
||||
# left in CRED_HTTP/CRED_BODY. --wait-approval is what would have avoided the
|
||||
# original prod bug; the default (0) does not block, so the re-run path below
|
||||
# must stand on its own.
|
||||
wait_for_key() { # wait_for_key PICKUP_SECRET
|
||||
[ "${ENROLL_WAIT:-0}" -gt 0 ] || return 0
|
||||
local _end; _end=$(( $(date +%s) + ENROLL_WAIT ))
|
||||
say "Waiting up to ${ENROLL_WAIT}s for an admin to approve '$NODE_ID'"
|
||||
while [ "$(date +%s)" -lt "$_end" ]; do
|
||||
sleep 10
|
||||
creds_pickup "$1"
|
||||
[ "$CRED_HTTP" = 200 ] || return 0
|
||||
[ -z "$(cred_field '.api_key')" ] || return 0
|
||||
done
|
||||
}
|
||||
|
||||
do_fresh_enroll() {
|
||||
say "Enrolling '$NODE_ID' with $C2_URL"
|
||||
[ -n "$ENROLLMENT_TOKEN" ] || ask_secret ENROLLMENT_TOKEN "Enrollment token"
|
||||
[ -n "$ENROLLMENT_TOKEN" ] || die "no enrollment token — mint one at Settings -> Nodes, then re-run with --token"
|
||||
|
||||
local BODY RESP PICKUP STATUS KEY
|
||||
BODY="$(jq -nc --arg id "$NODE_ID" --arg n "${NODE_NAME:-$NODE_ID}" \
|
||||
--argjson lat "${NODE_LAT:-0}" --argjson lon "${NODE_LON:-0}" \
|
||||
'{node_id:$id,name:$n,lat:$lat,lon:$lon}')"
|
||||
# Token goes in a header from a shell variable — never on a process command
|
||||
# line, never echoed.
|
||||
if ! RESP="$(curl -fsS -X POST "$C2_URL/nodes/enroll" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "X-Enrollment-Token: $ENROLLMENT_TOKEN" \
|
||||
--data "$BODY" 2>&1)"; then
|
||||
case "$RESP" in
|
||||
*403*) die "enroll refused (403): node '$NODE_ID' is already approved on C2, and
|
||||
this machine has no configs/pickup_secret to collect its key with. A token
|
||||
alone cannot re-issue an approved node's key (enrollment.py CRITICAL GUARD).
|
||||
Recover by restoring this node's original configs/pickup_secret and re-running,
|
||||
or have an admin Reissue key (Settings -> Nodes) and write the key into
|
||||
$CREDS by hand (see node-26#6)." ;;
|
||||
*401*) die "enroll refused (401): enrollment token missing/invalid/revoked —
|
||||
mint a fresh one at Settings -> Nodes and re-run with --token." ;;
|
||||
*429*) die "enroll refused (429): rate limited. Wait ~1 minute, then re-run." ;;
|
||||
*) die "enroll failed: $RESP" ;;
|
||||
esac
|
||||
fi
|
||||
PICKUP="$(printf '%s' "$RESP" | jq -r '.pickup_secret')"
|
||||
STATUS="$(printf '%s' "$RESP" | jq -r '.approval_status')"
|
||||
[ -n "$PICKUP" ] && [ "$PICKUP" != null ] || die "enroll returned no pickup_secret: $RESP"
|
||||
|
||||
umask 077; printf '%s' "$PICKUP" > "$PICKUP_FILE"; umask 022
|
||||
ok "enrolled — approval_status=$STATUS (pickup secret saved to configs/pickup_secret)"
|
||||
|
||||
creds_pickup "$PICKUP"
|
||||
[ "$CRED_HTTP" = 200 ] || die "post-enroll credential fetch failed (HTTP $CRED_HTTP): ${CRED_BODY:-<no body>}"
|
||||
KEY="$(cred_field '.api_key')"
|
||||
if [ -z "$KEY" ]; then
|
||||
wait_for_key "$PICKUP" || true
|
||||
KEY="$(cred_field '.api_key')"
|
||||
fi
|
||||
if [ -n "$KEY" ]; then
|
||||
write_creds "$KEY"
|
||||
else
|
||||
say_pending "$(cred_field '.approval_status')"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -s "$CREDS" ] && jq -e '.api_key // empty' "$CREDS" >/dev/null 2>&1; then
|
||||
say "Enrollment"
|
||||
ok "api_key already on disk — skipping enrollment"
|
||||
elif [ -z "${C2_URL:-}" ]; then
|
||||
say "Enrollment"
|
||||
warn "no C2_URL — skipping enrollment"
|
||||
elif [ -s "$PICKUP_FILE" ]; then
|
||||
# RE-RUN. This node already enrolled from this machine. Do NOT POST
|
||||
# /nodes/enroll again — an approved node_id gets 403 there, and the v1
|
||||
# installer's own "re-run to pick up the key" advice then dead-ends on
|
||||
# "use Reissue key". The pickup endpoint has no such guard: use it.
|
||||
say "Enrollment — collecting credentials for '$NODE_ID' (pickup secret from a previous run)"
|
||||
PICKUP="$(cat "$PICKUP_FILE")"
|
||||
creds_pickup "$PICKUP"
|
||||
case "$CRED_HTTP" in
|
||||
200)
|
||||
API_KEY="$(cred_field '.api_key')"
|
||||
if [ -z "$API_KEY" ]; then
|
||||
wait_for_key "$PICKUP" || true
|
||||
API_KEY="$(cred_field '.api_key')"
|
||||
fi
|
||||
if [ -n "$API_KEY" ]; then
|
||||
write_creds "$API_KEY"
|
||||
else
|
||||
# Still pending. Enrolled and idempotent — next run collects the key.
|
||||
# Clean exit, fall through to start the stack. NOT a failure.
|
||||
say_pending "$(cred_field '.approval_status')"
|
||||
fi
|
||||
;;
|
||||
401)
|
||||
if [ -n "$ENROLLMENT_TOKEN" ]; then
|
||||
warn "saved pickup secret rejected (401) — likely rotated by a re-enroll elsewhere. Re-enrolling with --token."
|
||||
rm -f "$PICKUP_FILE"
|
||||
do_fresh_enroll
|
||||
else
|
||||
die "saved pickup secret is stale (401) and no --token was given. Re-run with
|
||||
--token DRB-… to re-enroll (only works while the node is still pending), or
|
||||
have an admin Reissue key for an approved node and write $CREDS by hand."
|
||||
fi
|
||||
;;
|
||||
404)
|
||||
if [ -n "$ENROLLMENT_TOKEN" ]; then
|
||||
warn "C2 does not know node '$NODE_ID' (404) — deleted server-side or never fully enrolled. Re-enrolling with --token."
|
||||
rm -f "$PICKUP_FILE"
|
||||
do_fresh_enroll
|
||||
else
|
||||
die "C2 does not know node '$NODE_ID' (404) and no --token was given.
|
||||
Re-run with --token DRB-… to enroll it again."
|
||||
fi
|
||||
;;
|
||||
000)
|
||||
die "could not reach $C2_URL/nodes/$NODE_ID/credentials — check --c2-url and connectivity." ;;
|
||||
*)
|
||||
die "credential pickup failed (HTTP $CRED_HTTP): ${CRED_BODY:-<no body>}" ;;
|
||||
esac
|
||||
else
|
||||
say "Enrollment"
|
||||
do_fresh_enroll
|
||||
fi
|
||||
|
||||
# ── 6. Images + start ───────────────────────────────────────────────────────
|
||||
if [ "$DO_START" = 1 ]; then
|
||||
if [ -n "$REGISTRY_USER" ] && [ -n "$REGISTRY_PASS" ]; then
|
||||
printf '%s' "$REGISTRY_PASS" | docker login "$REGISTRY" -u "$REGISTRY_USER" --password-stdin >/dev/null
|
||||
ok "logged in to $REGISTRY"
|
||||
fi
|
||||
|
||||
if [ "$DO_BUILD" = 1 ]; then
|
||||
say "Building images locally — op25 takes roughly an hour on a Pi"
|
||||
docker compose build
|
||||
docker compose up -d
|
||||
else
|
||||
say "Pulling prebuilt images from $REGISTRY/$DOCKER_ORG/$DOCKER_REPO"
|
||||
if ! docker compose pull; then
|
||||
die "pull failed. $REGISTRY is public, so this is most likely a login
|
||||
requirement or a transient network error: re-run with DRB_REGISTRY_USER /
|
||||
DRB_REGISTRY_PASS set, or with --build to compile on the Pi (~1h for op25)."
|
||||
fi
|
||||
docker compose up --no-build -d
|
||||
fi
|
||||
ok "stack started"
|
||||
else
|
||||
say "Skipping start (--no-start). Run: cd $INSTALL_DIR && make up-prebuilt"
|
||||
fi
|
||||
|
||||
# ── 7. What the operator does next ──────────────────────────────────────────
|
||||
IP="$(hostname -I 2>/dev/null | awk '{print $1}')"
|
||||
cat <<EOF
|
||||
|
||||
$(printf "${G}Node '%s' installed at %s${N}" "$NODE_ID" "$INSTALL_DIR")
|
||||
|
||||
ref ${RESOLVED_SHA}
|
||||
images $([ "$DO_BUILD" = 1 ] && echo "built locally" || echo "pulled from $REGISTRY")
|
||||
dashboard http://${IP:-<node-ip>}/ (user: ${DASHBOARD_USER})
|
||||
logs cd $INSTALL_DIR && docker compose logs -f edge-node
|
||||
|
||||
NEXT — an admin must approve this node before it can do anything:
|
||||
|
||||
1. Open <app-url>/settings/nodes
|
||||
2. Approve "$NODE_ID"
|
||||
3. Assign it a radio system
|
||||
|
||||
EOF
|
||||
if [ "${GENERATED_DASH:-0}" = 1 ]; then
|
||||
printf "${Y}Generated dashboard password (shown once): %s${N}\n\n" "$DASHBOARD_PASS"
|
||||
fi
|
||||
if [ ! -s "$CREDS" ]; then
|
||||
if [ -s "$PICKUP_FILE" ]; then
|
||||
printf "${Y}This node has no api_key yet. After an admin approves it, re-run the same\ninstall command — it reuses configs/pickup_secret and will collect the key\n(no --token needed for the re-run).${N}\n\n"
|
||||
else
|
||||
printf "${Y}This node has no api_key and no saved pickup secret, so a plain re-run cannot\nfix it. Re-run with --token DRB-… to enroll; or, if the node is already\napproved, have an admin Reissue key and write it into\n%s by hand.${N}\n\n" "$CREDS"
|
||||
fi
|
||||
fi
|
||||
@@ -1,57 +0,0 @@
|
||||
name: release-tag
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
|
||||
jobs:
|
||||
release-image:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOCKER_LATEST: stable
|
||||
CONTAINER_NAME: drb-client-discord-bot
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker BuildX
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with: # replace it with your local IP
|
||||
config-inline: |
|
||||
[registry."git.vpn.cusano.net"]
|
||||
http = false
|
||||
insecure = false
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.vpn.cusano.net # replace it with your local IP
|
||||
username: ${{ secrets.GIT_REPO_USERNAME }}
|
||||
password: ${{ secrets.GIT_REPO_PASSWORD }}
|
||||
|
||||
- name: Get Meta
|
||||
id: meta
|
||||
run: |
|
||||
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
|
||||
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Validate build configuration
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
call: check
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: |
|
||||
linux/arm64
|
||||
push: true
|
||||
tags: | # replace it with your local IP and tags
|
||||
git.vpn.cusano.net/${{ vars.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}/${{ env.CONTAINER_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}
|
||||
git.vpn.cusano.net/${{ vars.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}/${{ env.CONTAINER_NAME }}:${{ env.DOCKER_LATEST }}
|
||||
@@ -1,60 +0,0 @@
|
||||
name: release-tag
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
release-image:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
env:
|
||||
DOCKER_LATEST: stable
|
||||
CONTAINER_NAME: op25-client
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker BuildX
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
config-inline: |
|
||||
[registry."git.vpn.cusano.net"]
|
||||
http = false
|
||||
insecure = false
|
||||
|
||||
- name: Login to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.vpn.cusano.net
|
||||
username: ${{ gitea.actor }} # Uses the user or bot that triggered the workflow
|
||||
password: ${{ secrets.GITHUB_COM_TOKEN }} # The built-in, temporary token
|
||||
|
||||
- name: Get Meta
|
||||
id: meta
|
||||
run: |
|
||||
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
|
||||
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Validate build configuration
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
call: check
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: |
|
||||
linux/arm64
|
||||
push: true
|
||||
tags: |
|
||||
git.vpn.cusano.net/${{ vars.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}/${{ env.CONTAINER_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}
|
||||
git.vpn.cusano.net/${{ vars.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}/${{ env.CONTAINER_NAME }}:${{ env.DOCKER_LATEST }}
|
||||
@@ -1,30 +0,0 @@
|
||||
name: Lint
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- "*"
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.13'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install flake8
|
||||
|
||||
- name: Run Lint
|
||||
run: |
|
||||
flake8 --max-line-length=88 --ignore=E203,E302,E501 .
|
||||
@@ -1,5 +1,10 @@
|
||||
# OP25 Core Container
|
||||
FROM python:slim-trixie
|
||||
# Pinned to a Python major version deliberately. The bare `slim-trixie` tag
|
||||
# carries no version at all, so a rebuild could move the interpreter across a
|
||||
# major release -- which this repo has already been bitten by once, when
|
||||
# app/models.py only ran because trixie happened to ship 3.14 and PEP 649
|
||||
# defers annotation evaluation. Matches drb-edge-node, which is already 3.14.
|
||||
FROM python:3.14-slim
|
||||
|
||||
# Set environment variables
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
@@ -24,7 +24,7 @@ async def lifespan(app: FastAPI):
|
||||
icecast_host=os.getenv("ICECAST_HOST", "localhost"),
|
||||
icecast_port=int(os.getenv("ICECAST_PORT", "8000")),
|
||||
icecast_mountpoint=os.getenv("ICECAST_MOUNT", "/radio"),
|
||||
icecast_password=os.getenv("ICECAST_SOURCE_PASSWORD", "hackme"),
|
||||
icecast_password=os.getenv("ICECAST_SOURCE_PASSWORD", ""),
|
||||
)
|
||||
generate_liquid_script(config)
|
||||
LOGGER.info("op25.liq generated from environment variables.")
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Interactive first-time setup for a DRB edge node.
|
||||
# Installs system dependencies (Docker, make, curl) then writes .env
|
||||
# and optionally builds + starts the stack.
|
||||
set -e
|
||||
|
||||
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; RED='\033[0;31m'; NC='\033[0m'
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
echo -e "${CYAN}DRB Edge Node Setup${NC}"
|
||||
echo "-------------------"
|
||||
|
||||
# ── Dependency installation ──────────────────────────────────────────────────
|
||||
install_deps() {
|
||||
if ! command -v apt-get &>/dev/null; then
|
||||
echo -e "${YELLOW}⚠ apt-get not found — skipping auto-install. Ensure docker, make, and curl are installed.${NC}"
|
||||
return
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo -e "${CYAN}Installing system dependencies…${NC}"
|
||||
sudo apt-get update -qq
|
||||
|
||||
local pkgs=()
|
||||
command -v make &>/dev/null || pkgs+=(make)
|
||||
command -v curl &>/dev/null || pkgs+=(curl)
|
||||
command -v git &>/dev/null || pkgs+=(git)
|
||||
|
||||
if [ ${#pkgs[@]} -gt 0 ]; then
|
||||
echo " Installing: ${pkgs[*]}"
|
||||
sudo apt-get install -y -qq "${pkgs[@]}"
|
||||
fi
|
||||
|
||||
# Docker — use get.docker.com if not present
|
||||
if ! command -v docker &>/dev/null; then
|
||||
echo " Installing Docker via get.docker.com…"
|
||||
curl -fsSL https://get.docker.com | sudo sh
|
||||
# Allow current user to run docker without sudo
|
||||
sudo usermod -aG docker "$USER"
|
||||
echo -e "${YELLOW} ⚠ Docker group added. You may need to log out and back in for it to take effect.${NC}"
|
||||
echo -e "${YELLOW} If 'docker compose' fails below, run: newgrp docker${NC}"
|
||||
else
|
||||
echo -e "${GREEN} ✓ docker$(docker --version | grep -oP ' \d+\.\d+\.\d+' | head -1)${NC}"
|
||||
fi
|
||||
|
||||
# Docker Compose plugin check (comes with Docker Engine ≥ 20.10)
|
||||
if ! docker compose version &>/dev/null 2>&1; then
|
||||
echo -e "${RED} docker compose plugin not found. Installing…${NC}"
|
||||
sudo apt-get install -y -qq docker-compose-plugin
|
||||
else
|
||||
echo -e "${GREEN} ✓ docker compose $(docker compose version --short 2>/dev/null || true)${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✓ Dependencies ready${NC}"
|
||||
}
|
||||
|
||||
install_deps
|
||||
|
||||
if [ -f .env ]; then
|
||||
echo -e "${YELLOW}Warning: .env already exists.${NC}"
|
||||
read -rp "Overwrite? [y/N] " yn
|
||||
[[ "$yn" =~ ^[Yy]$ ]] || { echo "Aborted."; exit 0; }
|
||||
fi
|
||||
|
||||
# --- Node identity ---
|
||||
echo ""
|
||||
echo "Unique node ID — no spaces (e.g. node-ossining, node-002)"
|
||||
read -rp "NODE_ID: " NODE_ID
|
||||
while [[ ! "$NODE_ID" =~ ^[a-zA-Z0-9_-]+$ ]]; do
|
||||
echo " Use letters, numbers, dashes, underscores only."
|
||||
read -rp "NODE_ID: " NODE_ID
|
||||
done
|
||||
|
||||
echo ""
|
||||
read -rp "Node display name [$NODE_ID]: " NODE_NAME
|
||||
NODE_NAME="${NODE_NAME:-$NODE_ID}"
|
||||
|
||||
# --- GPS ---
|
||||
echo ""
|
||||
echo "GPS coordinates (decimal degrees — used for the map)"
|
||||
read -rp "Latitude [0.0]: " NODE_LAT; NODE_LAT="${NODE_LAT:-0.0}"
|
||||
read -rp "Longitude [0.0]: " NODE_LON; NODE_LON="${NODE_LON:-0.0}"
|
||||
|
||||
# --- C2 server ---
|
||||
echo ""
|
||||
echo "C2 server — hostname or IP of the machine running the server stack"
|
||||
read -rp "C2 server host: " C2_HOST; C2_HOST="${C2_HOST:-localhost}"
|
||||
read -rp "C2 API port [8888]: " C2_PORT; C2_PORT="${C2_PORT:-8888}"
|
||||
|
||||
# --- MQTT ---
|
||||
echo ""
|
||||
echo "MQTT credentials (must match MQTT_NODE_USER/PASS in the server .env)"
|
||||
read -rp "MQTT port [1883]: " MQTT_PORT; MQTT_PORT="${MQTT_PORT:-1883}"
|
||||
read -rp "MQTT username [drb-node]: " MQTT_USER; MQTT_USER="${MQTT_USER:-drb-node}"
|
||||
read -rsp "MQTT password: " MQTT_PASS; echo ""; MQTT_PASS="${MQTT_PASS:-change-me-node}"
|
||||
|
||||
# --- Icecast ---
|
||||
echo ""
|
||||
echo "Icecast passwords (local container)"
|
||||
read -rsp "Source password [hackme]: " ICECAST_SOURCE; echo ""; ICECAST_SOURCE="${ICECAST_SOURCE:-hackme}"
|
||||
read -rsp "Admin password [admin]: " ICECAST_ADMIN; echo ""; ICECAST_ADMIN="${ICECAST_ADMIN:-admin}"
|
||||
|
||||
# --- Write .env ---
|
||||
cat > .env <<EOF
|
||||
# Node Identity
|
||||
NODE_ID=${NODE_ID}
|
||||
NODE_NAME="${NODE_NAME}"
|
||||
NODE_LAT=${NODE_LAT}
|
||||
NODE_LON=${NODE_LON}
|
||||
|
||||
# MQTT — point to your C2 server
|
||||
MQTT_BROKER=${C2_HOST}
|
||||
MQTT_PORT=${MQTT_PORT}
|
||||
MQTT_USER=${MQTT_USER}
|
||||
MQTT_PASS=${MQTT_PASS}
|
||||
|
||||
# C2 server for audio upload
|
||||
C2_URL=http://${C2_HOST}:${C2_PORT}
|
||||
# API key is provisioned automatically via MQTT after admin approves the node
|
||||
|
||||
# Icecast (local container — usually no need to change)
|
||||
ICECAST_SOURCE_PASSWORD=${ICECAST_SOURCE}
|
||||
ICECAST_ADMIN_PASSWORD=${ICECAST_ADMIN}
|
||||
ICECAST_HOST=localhost
|
||||
ICECAST_PORT=8000
|
||||
ICECAST_MOUNT=/radio
|
||||
|
||||
# OP25 container (usually no need to change)
|
||||
OP25_API_URL=http://localhost:8001
|
||||
OP25_TERMINAL_URL=http://localhost:8081
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}✓ .env written for node '${NODE_ID}'${NC}"
|
||||
echo ""
|
||||
|
||||
read -rp "Build and start now? [Y/n] " start
|
||||
if [[ ! "$start" =~ ^[Nn]$ ]]; then
|
||||
echo ""
|
||||
echo "Building images (op25 takes ~10 min on first run)…"
|
||||
docker compose build
|
||||
docker compose up -d
|
||||
echo ""
|
||||
echo -e "${GREEN}✓ Node '${NODE_ID}' started.${NC}"
|
||||
echo " → Check the dashboard — it will appear as pending approval."
|
||||
else
|
||||
echo "Run 'make up' when ready."
|
||||
fi
|
||||
Reference in New Issue
Block a user