diff --git a/satellite/README.md b/satellite/README.md index df5f8ef..6d2450e 100644 --- a/satellite/README.md +++ b/satellite/README.md @@ -33,13 +33,16 @@ docker compose logs -f # "Netz: primary_ip=192.168.177.x" + "[scan] N G `network_mode: host` (schon gesetzt) gibt hier echtes LAN + Multicast. **B) Nativ als Python-Prozess** (für Mac/Windows-Test oder ohne Docker) — läuft direkt -auf einer Maschine im Ziel-LAN: +auf einer Maschine im Ziel-LAN. Das Script lädt die `.env` **selbst** (muss im +`satellite/`-Ordner liegen): ```bash cd satellite +cp .env.example .env # RVS-Zugang + SATELLITE_LOCATION eintragen pip install -r requirements.txt -export RVS_HOST=... RVS_TOKEN=... SATELLITE_LOCATION="Wohnung" CONTROL_ENABLED=true -python satellite.py +python satellite.py # liest .env automatisch ``` +(Echte Umgebungsvariablen haben Vorrang — `export RVS_TOKEN=...` überschreibt die +`.env`, falls du das lieber magst.) `RVS_HOST/PORT/TLS/TOKEN` **identisch** zum Haupt-Stack (gleicher Raum, damit ARIA den Satelliten erreicht). `SATELLITE_LOCATION` ist der Name, über den ARIA das Netz diff --git a/satellite/satellite.py b/satellite/satellite.py index de9955e..ebd5c23 100644 --- a/satellite/satellite.py +++ b/satellite/satellite.py @@ -46,6 +46,38 @@ logging.basicConfig( logger = logging.getLogger("satellite") +def _load_dotenv() -> None: + """Laedt eine .env neben dem Script (oder im CWD) in os.environ — fuer den + NATIVEN Start (`python satellite.py`). In Docker sind die Variablen via + env_file schon gesetzt; bereits gesetzte Werte gewinnen (werden NICHT + ueberschrieben). Kein python-dotenv noetig.""" + here = os.path.dirname(os.path.abspath(__file__)) + for path in (os.path.join(here, ".env"), os.path.join(os.getcwd(), ".env")): + if not os.path.isfile(path): + continue + try: + with open(path, "r", encoding="utf-8") as f: + for line in f: + line = line.strip() + if not line or line.startswith("#") or "=" not in line: + continue + key, _, val = line.partition("=") + key = key.strip() + if key.startswith("export "): + key = key[len("export "):].strip() + val = val.strip() + if len(val) >= 2 and val[0] == val[-1] and val[0] in ("'", '"'): + val = val[1:-1] + if key and key not in os.environ: + os.environ[key] = val + except Exception as exc: + logging.getLogger("satellite").warning(".env laden fehlgeschlagen (%s): %s", path, exc) + break # erste gefundene .env gewinnt + + +_load_dotenv() + + # ─── Konfiguration ────────────────────────────────────────────────── def _env_bool(name: str, default: bool) -> bool: