Skip to content

Commit 937ce1e

Browse files
committed
fix(start.sh): persist devstack env to ~/.devstack-env for --shell/--ssh shells
start.sh computes LPB_* vars and bare-name aliases (e.g. EXA_API_KEY) but only in its own process. SSH login shells and 'podman exec bash' reattachments start fresh and miss them, so EXA_API_KEY was empty in --ssh/--shell sessions. Add persist_devstack_env() to write the resolved, non-empty env set to ~/.devstack-env (chmod 600) and idempotently source it from ~/.bashrc and ~/.profile. Covers SSH login (interactive + non-interactive) and interactive exec shells.
1 parent ff39c10 commit 937ce1e

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎support/start.sh‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,40 @@ if command -v sudo >/dev/null 2>&1 && sudo -n true 2>/dev/null; then
315315
done
316316
fi
317317

318+
# ─── 4c. PERSIST DEVSTACK ENV FOR ALL SHELLS (--shell / --ssh) ─────────────
319+
# start.sh loads .env and computes the LPB_* vars + bare-name aliases, but those
320+
# only exist in this process. Interactive --shell bash inherits them (via exec),
321+
# but --ssh login shells and `podman exec bash` reattachments start fresh and
322+
# would miss them. Persist the resolved set to ~/.devstack-env and source it from
323+
# .bashrc and .profile so every shell (SSH, exec, interactive) gets the
324+
# preconfigured env vars (e.g. EXA_API_KEY).
325+
persist_devstack_env() {
326+
local env_file="${HOME_DIR}/.devstack-env"
327+
local bare_names="EXA_API_KEY LEMONADE_BASE_URL OPENROUTER_BASE_URL ED_PORT HOST CONNECTION_TOKEN DEVCONTAINER_WORKSPACE_DIR MAX_TOKENS_CONTEXT_RATIO"
328+
local name q
329+
: > "${env_file}"
330+
# Dump all LPB_*/PI_* vars plus the aliased bare names (non-empty only).
331+
while IFS= read -r name; do
332+
[[ -n "$name" ]] || continue
333+
local val="${!name}"
334+
[[ -n "$val" ]] || continue
335+
printf -v q '%q' "$val"
336+
printf 'export %s=%s\n' "$name" "$q" >> "${env_file}"
337+
done < <(env | cut -d= -f1 | grep -E '^(LPB_|PI_)'; for n in $bare_names; do [[ -n "${!n:-}" ]] && echo "$n"; done)
338+
chmod 600 "${env_file}" 2>/dev/null || true
339+
# Source it from .bashrc and .profile, idempotently.
340+
local src_marker='# LocalPibox devstack environment (managed)'
341+
local src_line='[ -f "${HOME}/.devstack-env" ] && . "${HOME}/.devstack-env"'
342+
local rc
343+
for rc in "${HOME_DIR}/.bashrc" "${HOME_DIR}/.profile"; do
344+
[[ -f "$rc" ]] || continue
345+
if ! grep -qF "$src_marker" "$rc" 2>/dev/null; then
346+
printf '\n%s\n%s\n' "$src_marker" "$src_line" >> "$rc"
347+
fi
348+
done
349+
}
350+
persist_devstack_env
351+
318352
# ─── 5. POST-INIT: NATIVE MODULES ────────────────────────────────────────────
319353
320354
debug "Checking native modules..."

0 commit comments

Comments
 (0)