#!/usr/bin/env python3 """Upload patched Otantik Hub provision (hotspot stays on WiFi, not ether2/3).""" from __future__ import annotations import sys import time from pathlib import Path import paramiko SRC = Path(r"c:\laragon\www\light-otantik-nux\scripts\_tmp_otantik-hub.rsc") DST_LOCAL = Path(r"c:\laragon\www\light-otantik-nux\scripts\_tmp_otantik-hub.patched.rsc") REMOTE_NAME = "wo-otantik.rsc" HOST = "192.168.88.1" USER = "admin" PASSWORD = "" def patch() -> Path: text = SRC.read_text(encoding="utf-8") old = ':local hsIface ""' new = ':local hsIface "bridge-hotspot"' if old not in text: raise SystemExit("ligne hsIface introuvable") DST_LOCAL.write_text(text.replace(old, new, 1), encoding="utf-8") print("PATCHED hsIface -> bridge-hotspot") return DST_LOCAL def wait_prompt(shell, timeout=30) -> str: buf = b"" end = time.time() + timeout while time.time() < end: time.sleep(0.15) if shell.recv_ready(): buf += shell.recv(65535) end = time.time() + 2 if buf.endswith(b"> ") or b"\n[admin@" in buf[-80:]: break return buf.decode("utf-8", "replace") def main() -> None: local = patch() ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect( HOST, username=USER, password=PASSWORD, timeout=20, allow_agent=False, look_for_keys=False, ) print("SSH OK") sftp = ssh.open_sftp() sftp.put(str(local), REMOTE_NAME) sftp.close() print("UPLOADED", REMOTE_NAME) shell = ssh.invoke_shell(width=200, height=80) print(wait_prompt(shell, 15)[-400:]) shell.send("/import file-name=" + REMOTE_NAME + "\r") buf = b"" end = time.time() + 240 last = time.time() while time.time() < end: time.sleep(0.2) if shell.recv_ready(): chunk = shell.recv(65535) buf += chunk last = time.time() sys.stdout.write(chunk.decode("utf-8", "replace")) sys.stdout.flush() low = buf.lower() if b"wifi-otantik completed" in low or b"==== wifi-otantik completed" in low: time.sleep(2) break elif time.time() - last > 45 and b"importing" in buf.lower(): # still running fetches continue elif time.time() - last > 60 and len(buf) > 200: # stalled after some output if b"failure:" in buf.lower() and b"completed" not in buf.lower(): break print("\n---- import wait done ----") ssh.close() if __name__ == "__main__": main()