diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-09-04 14:33:33 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-09-04 14:33:33 +0200 |
| commit | c2eade6db582966fa7fc3dd037f952baf3ae1cb5 (patch) | |
| tree | bac7089118c44c748593c20a7c36c3bba74ddbcd /packaging/win | |
| parent | 40abf0979f93771ccfb58eecb8a6fcc5863ec604 (diff) | |
| download | meshbay-c2eade6db582966fa7fc3dd037f952baf3ae1cb5.tar.gz | |
fix(packaging): actually ship the TMDB token, on Linux and Windows
default.env was empty in every build, for three independent reasons:
1. build-node.sh read QE/node.env, which does not exist. Even pointed at the
real file it would have failed: its `grep MESHBAY_TMDB_DEFAULT_TOKEN=`
cannot match QE/tmdb.txt, which is a free-form note, not KEY=VALUE.
2. Nothing consumed default.env. packaging/README.md and build-node.sh both
claimed `meshbay-node init` copies it to <config>/node.env; grep found the
name in exactly two places, the README and the script that writes it. No
code implemented the copy, and `EnvironmentFile=-` hid the absence.
3. build-win.ps1 had no env handling at all, so Windows was empty for a
different reason than Linux.
Now: the build extracts the v4 read token -- tmdb.py sends `Authorization:
Bearer`, so it is the JWT, not the 32-char v3 key beside it in the same file --
matching KEY=VALUE first and then by shape, from MESHBAY_TMDB_TOKEN,
MESHBAY_TMDB_TOKEN_FILE, QE/node.env, QE/tmdb.txt. It writes default.env 0600
and *fails the build* if no token resolves; MESHBAY_ALLOW_NO_TMDB=1 opts out.
An empty default.env is invisible until a user opens Videos and finds no
metadata, which is how this shipped empty on two platforms at once.
platform.py gains packaged_default_env()/install_node_env()/load_node_env().
init copies the packaged file once, never overwriting an existing node.env,
and the daemon loads node.env itself at startup: systemd does this on Linux
via EnvironmentFile, but Windows autostart is a Startup-folder .vbs with no
equivalent. Already-set variables always win.
Also fixes an UnboundLocalError in main(): `config_dir` was assigned at the
top of the init branch, which made it function-local for all of main(), while
the reset branch calls `config_dir()` as the imported function. init returns
before that line, so `meshbay-node reset` could only ever raise. The local is
now cfg_dir.
Verified end to end on Linux: token baked (239 chars), init writes
<config>/node.env 0600 with it. The PowerShell half is written but unrun --
no pwsh on this machine.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtfG7z6wHWj8RKHCvxQtY1
Diffstat (limited to 'packaging/win')
| -rw-r--r-- | packaging/win/build-node-runtime.ps1 | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/packaging/win/build-node-runtime.ps1 b/packaging/win/build-node-runtime.ps1 index c432e01..5097b37 100644 --- a/packaging/win/build-node-runtime.ps1 +++ b/packaging/win/build-node-runtime.ps1 @@ -117,14 +117,62 @@ else { Write-Host " ffmpeg not bundled -- the node will look for it on PATH" -ForegroundColor Yellow } -# --- 5. publish ---------------------------------------------------- +# --- 5. default.env (shared TMDB token) ------------------------------ +# Beside the exe, where platform.packaged_default_env() looks for it, and the +# same placement ffmpeg gets above. `meshbay-node init` copies it to +# %LOCALAPPDATA%\meshbay\node.env, and the daemon loads that file itself: +# Windows autostart is a Startup-folder .vbs, with no systemd EnvironmentFile. +function Get-TmdbToken([string]$File) { + if (-not $File -or -not (Test-Path -LiteralPath $File)) { return "" } + $lines = Get-Content -LiteralPath $File + foreach ($line in $lines) { + if ($line -match '^\s*MESHBAY_TMDB_DEFAULT_TOKEN\s*=\s*(.+)$') { + return $Matches[1].Trim().Trim('"').Trim("'") + } + } + # QE\tmdb.txt is free-form prose: match the v4 read token by shape. The + # 32-char v3 API key in the same file is NOT what tmdb.py sends (Bearer). + foreach ($line in $lines) { + if ($line -match '^(eyJ[A-Za-z0-9._-]{40,})\s*$') { return $Matches[1] } + } + return "" +} + +$tmdb = $env:MESHBAY_TMDB_TOKEN +if (-not $tmdb) { $tmdb = Get-TmdbToken $env:MESHBAY_TMDB_TOKEN_FILE } +if (-not $tmdb) { $tmdb = Get-TmdbToken (Join-Path $Repo "QE\node.env") } +if (-not $tmdb) { $tmdb = Get-TmdbToken (Join-Path $Repo "QE\tmdb.txt") } + +$envFile = Join-Path $frozen "default.env" +$noBom = New-Object System.Text.UTF8Encoding $false # a BOM would break parsing +if ($tmdb) { + $body = @( + "# Default environment for meshbay-node.", + "# Copied to <config>\node.env by 'meshbay-node init' if it does not exist.", + "", + "# TMDB API token for the Videos app (read-only, shared across installations)", + "MESHBAY_TMDB_DEFAULT_TOKEN=$tmdb" + ) -join "`n" + [System.IO.File]::WriteAllText($envFile, $body + "`n", $noBom) + Step ("TMDB token baked into default.env ({0} chars)" -f $tmdb.Length) +} +elseif ($env:MESHBAY_ALLOW_NO_TMDB -eq "1") { + [System.IO.File]::WriteAllText($envFile, "", $noBom) + Write-Host " !! no TMDB token; default.env left empty (MESHBAY_ALLOW_NO_TMDB=1)" -ForegroundColor Yellow +} +else { + throw ("TMDB token not found (MESHBAY_TMDB_TOKEN, MESHBAY_TMDB_TOKEN_FILE, " + + "QE\node.env, QE\tmdb.txt). Set MESHBAY_ALLOW_NO_TMDB=1 to build without it.") +} + +# --- 6. publish ---------------------------------------------------- Move-Item $frozen $OutDir Remove-Item -Recurse -Force $pyiWork, $pyiDist -ErrorAction SilentlyContinue if ($createdVenv -and -not $KeepBuildVenv) { Remove-Item -Recurse -Force $BuildVenv -ErrorAction SilentlyContinue } -# --- 6. smoke test ----------------------------------------------- +# --- 7. smoke test ----------------------------------------------- # Capture, do NOT pipe to Select-Object -First: that stops the native process # mid-write and reports a spurious non-zero exit. Step "smoke test: meshbay-node --help" |