diff --git a/bin/box b/bin/box index 5613ded..607f770 100755 --- a/bin/box +++ b/bin/box @@ -14,6 +14,24 @@ die() { echo "box: $*" >&2; exit 1; } # 1 = it went wrong usage_error() { echo "box: $*" >&2; echo "try 'box help'." >&2; exit 2; } # 2 = you asked wrong version() { echo "box $(cat "$root/VERSION" 2>/dev/null || echo unknown) ($root)"; } +# Which tier is THIS PROCESS? Decided from live credentials (argless 'id -nG': +# what the kernel will present when incus opens the socket), never from the +# group database — the two disagree for exactly as long as a re-login is +# pending, and that window is where every wrong answer lives. +# UID 0 / incus-admin -> admin (the full daemon socket) +# incus (only) -> restricted (incus-user: your own project, nothing else) +# neither -> none (no socket at all) +# host/setup-host.sh carries a byte-identical copy (it runs before any install +# tree exists); test/cli.sh diffs the two so they cannot drift. +box_tier() { + [ "$(id -u)" -eq 0 ] && { printf 'admin\n'; return; } + local groups; groups="$(id -nG 2>/dev/null | tr ' ' '\n')" + if printf '%s\n' "$groups" | grep -qx incus-admin; then printf 'admin\n' + elif printf '%s\n' "$groups" | grep -qx incus; then printf 'restricted\n' + else printf 'none\n' + fi +} + # --------------------------------------------------------------------------- # The command table. # @@ -46,7 +64,7 @@ CMDS=( "exec^ -- ^box^Run a command inside a box^fn:cmd_exec^" "tmux^ []^box^Attach or create a tmux session in a box — survives disconnects^fn:cmd_tmux^" "snapshot^ [