#!/bin/bash # @file pane-launch.sh # @description Server mode, one Linux user per account (S3): installed as # /opt/agenthub/libexec/pane-launch. A member's pane starts as # `pane-launch `: the dashboard creates the session AS the member # through sudo, and sudo logs its whole command line — so the pane's # environment (a pane token, a pool account's token) and its argv (the prompt) # are not in that command line but in the launch file, which `write-as` # wrote as the member (0600) from stdin. This reads it, deletes it, exports # the environment and execs the command; no shell ever parses a value. # # The file is NUL-separated: the number of environment entries, the # NAME=value entries, then the argv (none = a login shell). # @author Nguyễn Ngọc Trí Vĩ set -eu f=${1:?usage: pane-launch } mapfile -d '' -t parts <"$f" rm -f -- "$f" n=${parts[0]} [[ "$n" =~ ^[0-9]+$ ]] || { echo "pane-launch: malformed launch file" >&2; exit 2; } for kv in "${parts[@]:1:n}"; do [[ "$kv" =~ ^[A-Za-z_][A-Za-z0-9_]*= ]] || { echo "pane-launch: bad variable" >&2; exit 2; } export "$kv" done argv=("${parts[@]:n+1}") if [ ${#argv[@]} -eq 0 ]; then exec -l "${SHELL:-/bin/bash}"; fi exec "${argv[@]}"