Serve installers from the hub; document the private-repo install

The repo is private, so anonymous raw URLs return 404. The hub now serves
/install-probe.sh (and /install.sh) from its own checkout, open even with
UI_PASSWORD, and the Add probe command fetches from there. The installers
still ask for a read-only token to clone. Docs use Gitea's
"Authorization: token" header and give a git-clone fallback for the hub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-04 18:13:19 -08:00
parent 54a765510a
commit efd3836945
10 changed files with 60 additions and 24 deletions

View file

@ -10,7 +10,7 @@ import secrets
from pathlib import Path
from fastapi import APIRouter, FastAPI, HTTPException, Request
from fastapi.responses import FileResponse, JSONResponse, Response
from fastapi.responses import FileResponse, JSONResponse, PlainTextResponse, Response
from fastapi.staticfiles import StaticFiles
from app.hub import adguard, db, dns, health, probes, settings
@ -63,7 +63,7 @@ async def _adguard_error(_req, exc):
return JSONResponse({"detail": str(exc), "code": "adguard_error"}, status_code=502)
OPEN_PATHS = ("/healthz", "/api/probe/report")
OPEN_PATHS = ("/healthz", "/api/probe/report", "/install-probe.sh", "/install.sh")
@app.middleware("http")
@ -106,6 +106,18 @@ api.include_router(dns.router)
app.include_router(api, prefix="/api")
ROOT = Path(__file__).resolve().parent.parent.parent
@app.get("/install-probe.sh", include_in_schema=False)
@app.get("/install.sh", include_in_schema=False)
def installer(request: Request) -> PlainTextResponse:
"""The installers, served from the hub's own checkout so a private repo needs no raw-file
access: curl -fsSL http://<hub>:8000/install-probe.sh | HUB_URL=... PROBE_TOKEN=... bash"""
name = request.url.path.lstrip("/")
return PlainTextResponse((ROOT / name).read_text(), media_type="text/x-shellscript", headers={"Cache-Control": "no-cache"})
@app.get("/healthz", include_in_schema=False)
def healthz() -> dict:
return {"status": "ok", "version": VERSION, "role": "hub"}

View file

@ -4,7 +4,9 @@ import os
from dataclasses import dataclass
from urllib.parse import urlparse
DEFAULT_PROBE_INSTALL_URL = "https://git.neilbantoc.dev/services/network-monitor/raw/branch/main/install-probe.sh"
# Empty: the probe install command fetches install-probe.sh from the hub itself (/install-probe.sh),
# which works for a private repo. Set PROBE_INSTALL_URL to use another location.
DEFAULT_PROBE_INSTALL_URL = ""
def _list(name: str, default: str) -> list[str]:

View file

@ -13,7 +13,8 @@ export function mount(root, ctx) {
function installCommand(info, token) {
const hub = info.hub_url || location.origin;
return `curl -fsSL ${info.install_url} | HUB_URL=${hub} PROBE_TOKEN=${token} bash`;
const url = info.install_url || `${hub}/install-probe.sh`;
return `curl -fsSL ${url} | HUB_URL=${hub} PROBE_TOKEN=${token} bash`;
}
function commandBlock(cmd) {
@ -87,7 +88,7 @@ function list(root, ctx) {
function showInstall(p) {
const cmd = installCommand(info, p.token);
const dlg = modal(`Install “${p.name}”`, el('div', { style: 'display:grid;gap:12px' },
el('p', { style: 'margin:0' }, 'Run this on the machine that will be the probe. It starts on boot and keeps running. On Linux hosts it uses Docker (installed if needed). On macOS and inside Proxmox LXC containers it installs natively as a system service; there, Linux needs root: put sudo env before HUB_URL.'),
el('p', { style: 'margin:0' }, 'Run this on the machine that will be the probe. It starts on boot and keeps running. On Linux hosts it uses Docker (installed if needed). On macOS and inside Proxmox LXC containers it installs natively as a system service; on Linux that needs root, so outside an LXC put sudo env before HUB_URL. If the git repo is private, the installer asks for a read-only token.'),
commandBlock(cmd),
el('p.small.muted', { style: 'margin:0' }, `The probe reports to ${info.hub_url || location.origin}. If that address isn't reachable from the probe, change HUB_URL in the command. The command is also on the probe's page.`),
), { wide: true, footer: [el('a.btn', { href: `/probes/${p.id}`, onclick: () => dlg.close() }, 'Open probe'), el('button.btn.primary', { type: 'button', onclick: () => dlg.close() }, 'Done')] });