lxc patch 12

This commit is contained in:
2026-04-15 00:41:08 -04:00
parent 52a5ad90e2
commit 63ff58b3dc
3 changed files with 40 additions and 14 deletions
+22 -3
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
# CONTAINER=$(cat "/home/${USER}/.lxc-container" 2>/dev/null)
CONTAINER=$(cat "/home/$(whoami)/.lxc-container" 2>/dev/null)
if [[ -z "$CONTAINER" ]]; then
@@ -10,8 +9,28 @@ fi
# ensure running
lxc-start -n "$CONTAINER" 2>/dev/null || true
# --- build env flags to forward into the container ---
ENV_ARGS=()
ENV_ARGS+=(--keep-env) # start from the SSH session env instead of wiping it
# always override these inside the container
ENV_ARGS+=(-v "HOME=/root")
ENV_ARGS+=(-v "USER=root")
ENV_ARGS+=(-v "SHELL=/bin/bash")
ENV_ARGS+=(-v "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
# forward TERM (fixes color/ncurses)
[[ -n "$TERM" ]] && ENV_ARGS+=(-v "TERM=$TERM")
# forward locale
[[ -n "$LANG" ]] && ENV_ARGS+=(-v "LANG=$LANG")
[[ -n "$LC_ALL" ]] && ENV_ARGS+=(-v "LC_ALL=$LC_ALL")
# forward COLORTERM (used by modern terminals & vscode)
[[ -n "$COLORTERM" ]] && ENV_ARGS+=(-v "COLORTERM=$COLORTERM")
if [[ -n "$SSH_ORIGINAL_COMMAND" ]]; then
exec sudo lxc-attach --clear-env -n "$CONTAINER" -- /bin/bash -c "export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin; $SSH_ORIGINAL_COMMAND"
exec sudo lxc-attach "${ENV_ARGS[@]}" -n "$CONTAINER" -- \
/bin/bash -lc "$SSH_ORIGINAL_COMMAND"
else
exec sudo lxc-attach --clear-env -n "$CONTAINER" -- /bin/login -f root
exec sudo lxc-attach "${ENV_ARGS[@]}" -n "$CONTAINER" -- \
/bin/login -f root
fi