Files
BT411/tools/park_relay.cmd
T
arcattackandClaude Opus 5 6b0402badc park_relay.cmd: resolve a real interpreter -- a second admin account has NO working python
Setting up remote access exposed this: 'python' works for the operator's own
account only.  It resolves through pyenv SHIMS driven by PYENV/PYENV_HOME/
PYENV_ROOT, and all three are USER-scoped to that account; the single
machine-wide PATH entry points at a Python39-32 folder that no longer exists.
So a dedicated remote-admin login (the account just created for SSH/RDP) gets
NO python at all -- parking the relay from the road would have failed with
'python is not recognized', at night, with players waiting.

park_relay.cmd now resolves an interpreter explicitly and prints which one:
BT_PYTHON override -> the project's pyenv 3.11.4 (calling account's profile,
then the operator's -- Administrators can read it) -> the machine-wide py
launcher -> whatever is on PATH -> a clear error naming the fix.  Verified both
as the operator and with a simulated second-account environment (machine PATH
only, PYENV cleared): both resolve 3.11.4.

Also dropped a delayed-expansion bug in the first cut (!CAND! without
EnableDelayedExpansion would have silently evaluated to nothing).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-26 19:34:50 -05:00

65 lines
2.5 KiB
Batchfile

@echo off
REM ===================================================================
REM Park the BattleTech relay on this machine and keep it alive.
REM
REM Double-click to run it now, or put a SHORTCUT to this file in the
REM Startup folder (Win+R -> shell:startup) so the relay comes back by
REM itself after a reboot. No admin rights needed either way.
REM
REM The window stays open: it is the supervisor. Closing it (or Ctrl-C)
REM stops the relay for good.
REM
REM WHY THIS HUNTS FOR AN INTERPRETER INSTEAD OF JUST SAYING "python"
REM (2026-07-26): on the operator's machine `python` resolves through
REM pyenv SHIMS that need PYENV/PYENV_HOME/PYENV_ROOT -- and those are
REM USER-scoped to the operator's own account. A second account (e.g. a
REM dedicated remote-admin login over SSH/RDP) gets NO working python at
REM all: the one machine-wide PATH entry points at a Python39-32 folder
REM that no longer exists. Parking the relay would then fail with
REM "python is not recognized" -- from the road, at night, with players
REM waiting. So: resolve a real interpreter explicitly, and say which.
REM ===================================================================
setlocal
title BattleTech relay (parked)
cd /d "%~dp0.."
set "BTPY="
REM 1. explicit override always wins
if defined BT_PYTHON if exist "%BT_PYTHON%" set "BTPY=%BT_PYTHON%"
REM 2. the interpreter this project is developed against (has PySide6).
REM Check the CALLING account's profile first, then the operator's --
REM a second admin account can read it (Administrators has access).
if not defined BTPY if exist "%USERPROFILE%\.pyenv\pyenv-win\versions\3.11.4\python.exe" set "BTPY=%USERPROFILE%\.pyenv\pyenv-win\versions\3.11.4\python.exe"
if not defined BTPY if exist "C:\Users\epilectrik\.pyenv\pyenv-win\versions\3.11.4\python.exe" set "BTPY=C:\Users\epilectrik\.pyenv\pyenv-win\versions\3.11.4\python.exe"
REM 3. the machine-wide launcher (works for ANY account)
if not defined BTPY (
if exist "C:\Windows\py.exe" set "BTPY=C:\Windows\py.exe -3"
)
REM 4. whatever is on PATH, if anything
if not defined BTPY (
for /f "delims=" %%P in ('where python 2^>nul') do (
if not defined BTPY set "BTPY=%%P"
)
)
if not defined BTPY (
echo.
echo ERROR: no Python interpreter found.
echo.
echo Set BT_PYTHON to a python.exe and run this again, e.g.:
echo set "BT_PYTHON=C:\Users\epilectrik\.pyenv\pyenv-win\versions\3.11.4\python.exe"
echo.
pause
exit /b 1
)
echo Using interpreter: %BTPY%
%BTPY% "tools\btrelay_park.py" %*
echo.
echo The parked relay has stopped.
pause