diff --git a/owpengram-server.bat b/owpengram-server.bat new file mode 100644 index 00000000..c0db3095 --- /dev/null +++ b/owpengram-server.bat @@ -0,0 +1,69 @@ +@echo off +setlocal enabledelayedexpansion +cd /d "%~dp0" + +rem Checks prerequisites (Go, Python 3, and its packages), then launches the +rem interactive server-panel TUI (tui-panel\server-panel.py). Run this instead +rem of the TUI directly so missing prerequisites get a clear message instead +rem of a Python traceback. + +echo == Checking prerequisites == + +set "PROBLEMS=0" + +rem --- Go --------------------------------------------------------------- +where go >nul 2>&1 +if errorlevel 1 ( + echo [WARN] Go is not installed ^(needed to build owpengram-server / owpengram-admin-panel^) + echo Install it from: https://go.dev/dl/ + set "PROBLEMS=1" +) else ( + for /f "delims=" %%v in ('go version') do echo [ok] Go found: %%v +) + +rem --- Python ------------------------------------------------------------- +set "PYTHON=" +where py >nul 2>&1 +if not errorlevel 1 ( + py -3 --version >nul 2>&1 + if not errorlevel 1 set "PYTHON=py -3" +) +if not defined PYTHON ( + where python >nul 2>&1 + if not errorlevel 1 set "PYTHON=python" +) + +if not defined PYTHON ( + echo [WARN] Python 3 is not installed ^(needed to run the server-panel TUI^) + echo Install it from: https://www.python.org/downloads/ + set "PROBLEMS=1" +) else ( + for /f "delims=" %%v in ('!PYTHON! --version 2^>^&1') do echo [ok] Python found: %%v ^(!PYTHON!^) +) + +rem --- Python dependencies -------------------------------------------------- +if defined PYTHON ( + set "MISSING=" + for /f "delims=" %%m in ('!PYTHON! tui-panel\check_deps.py') do ( + if not defined MISSING (set "MISSING=%%m") else (set "MISSING=!MISSING!, %%m") + ) + if defined MISSING ( + echo [WARN] Missing Python packages: !MISSING! + echo Install them with: !PYTHON! -m pip install -r tui-panel\requirements-panel.txt + set "PROBLEMS=1" + ) else ( + echo [ok] Python dependencies OK ^(textual, psutil, cryptography^) + ) +) + +if "%PROBLEMS%"=="1" ( + echo. + echo [ERROR] missing prerequisites above -- install them and re-run this script + pause + exit /b 1 +) + +echo. +echo [cfg] All prerequisites OK, launching server panel... +echo. +!PYTHON! tui-panel\server-panel.py %* diff --git a/owpengram-server.sh b/owpengram-server.sh new file mode 100644 index 00000000..5c602586 --- /dev/null +++ b/owpengram-server.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# Checks prerequisites (Go, Python 3, and its packages), then launches the +# interactive server-panel TUI (tui-panel/server-panel.py). Run this instead +# of the TUI directly so missing prerequisites get a clear message instead of +# a Python traceback. +set -uo pipefail +cd "$(dirname "$0")" + +ok() { echo "[ok] $*"; } +warn() { echo "[WARN] $*"; } +die() { echo "[ERROR] $*" >&2; exit 1; } + +echo "== Checking prerequisites ==" + +PROBLEMS=0 + +# --- Go ----------------------------------------------------------------- +if command -v go >/dev/null 2>&1; then + ok "Go found: $(go version)" +else + warn "Go is not installed (needed to build owpengram-server / owpengram-admin-panel)" + echo " Install it from: https://go.dev/dl/" + PROBLEMS=1 +fi + +# --- Python --------------------------------------------------------------- +PYTHON="" +for cand in python3 python; do + if command -v "$cand" >/dev/null 2>&1; then + PYTHON="$cand" + break + fi +done + +if [[ -z "$PYTHON" ]]; then + warn "Python 3 is not installed (needed to run the server-panel TUI)" + echo " Install it from: https://www.python.org/downloads/" + PROBLEMS=1 +else + ok "Python found: $("$PYTHON" --version 2>&1) (${PYTHON})" +fi + +# --- Python dependencies ---------------------------------------------------- +if [[ -n "$PYTHON" ]]; then + MISSING="$("$PYTHON" tui-panel/check_deps.py)" + if [[ -n "$MISSING" ]]; then + warn "Missing Python packages: $(echo "$MISSING" | tr '\n' ' ')" + echo " Install them with: $PYTHON -m pip install -r tui-panel/requirements-panel.txt" + PROBLEMS=1 + else + ok "Python dependencies OK (textual, psutil, cryptography)" + fi +fi + +if [[ "$PROBLEMS" -ne 0 ]]; then + echo + die "missing prerequisites above -- install them and re-run this script" +fi + +echo +echo "[cfg] All prerequisites OK, launching server panel..." +echo +exec "$PYTHON" tui-panel/server-panel.py "$@" diff --git a/tui-panel/check_deps.py b/tui-panel/check_deps.py new file mode 100644 index 00000000..4549a69a --- /dev/null +++ b/tui-panel/check_deps.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +"""Reports which Python packages server-panel.py needs are missing. + +Used by owpengram-server.sh / owpengram-server.bat before launching the +panel, so both launchers share one source of truth for the dependency list +instead of duplicating it in shell and batch syntax. + +Prints one missing package's pip install name per line. Exit code is 0 if +everything is already installed, 1 if anything is missing. +""" +import importlib +import sys + +REQUIRED = [ + ("textual", "textual"), + ("psutil", "psutil"), + ("cryptography", "cryptography"), +] + + +def main() -> int: + missing = [] + for module_name, pip_name in REQUIRED: + try: + importlib.import_module(module_name) + except ImportError: + missing.append(pip_name) + + for name in missing: + print(name) + + return 1 if missing else 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/requirements-panel.txt b/tui-panel/requirements-panel.txt similarity index 100% rename from requirements-panel.txt rename to tui-panel/requirements-panel.txt diff --git a/server-panel.py b/tui-panel/server-panel.py similarity index 99% rename from server-panel.py rename to tui-panel/server-panel.py index c36be4df..bc736955 100644 --- a/server-panel.py +++ b/tui-panel/server-panel.py @@ -11,8 +11,9 @@ processes and writes their PIDs to .server_panel.json next to .env; closing the panel (Exit) does NOT stop them -- only the Stop action does. Reopening the panel later picks the same PIDs back up and reports live status. -Requires: pip install textual -Run: python server-panel.py +Requires: pip install -r tui-panel/requirements-panel.txt +Run: owpengram-server.sh (Linux/macOS) or owpengram-server.bat (Windows) from +the repo root -- they check prerequisites first, then launch this. """ from __future__ import annotations @@ -44,7 +45,7 @@ IS_WINDOWS = platform.system() == "Windows" # real reading in the stats timer is already a proper since-last-call delta. psutil.cpu_percent(interval=None) -ROOT = Path(__file__).resolve().parent +ROOT = Path(__file__).resolve().parent.parent DEPLOY_DIR = ROOT / "deploy" BIN_DIR = ROOT / "bin" LOG_DIR = ROOT / "logs"