Files
2026-07-20 16:43:05 +08:00

43 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""Load DobotAI's local .env without shell evaluation, then exec the binary."""
import os
from pathlib import Path
ROOT = Path("/home/zheromiku/dobotai-platform")
ENV_FILE = ROOT / ".env"
BINARY = ROOT / "bin" / "dobotai"
def load_env(path: Path) -> dict[str, str]:
env = os.environ.copy()
for raw in path.read_text().splitlines():
line = raw.strip()
if not line or line.startswith("#") or "=" not in line:
continue
key, value = line.split("=", 1)
env[key.strip()] = value.strip()
# WeKnora is local and DingTalk is directly reachable in China. Do not make
# the service depend on a desktop proxy that may be absent during boot.
for key in (
"HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY",
"http_proxy", "https_proxy", "all_proxy",
):
env.pop(key, None)
env["NO_PROXY"] = "localhost,127.0.0.1"
env["no_proxy"] = env["NO_PROXY"]
return env
def main() -> None:
if not ENV_FILE.is_file():
raise SystemExit(f"missing environment file: {ENV_FILE}")
if not BINARY.is_file():
raise SystemExit(f"missing DobotAI binary: {BINARY}")
os.chdir(ROOT)
os.execve(BINARY, [str(BINARY)], load_env(ENV_FILE))
if __name__ == "__main__":
main()