mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
88 lines
3.3 KiB
Bash
Executable File
88 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Prints shell lines that bring the current shell up to date with this session's cloud env (secrets
|
|
# saved after the shell started): eval "$(orca-env)" or, in fish: orca-env --fish | source
|
|
# Reads /dev/shm/orca-env-<uid>/session.env (written by orca-sandbox-env, `NAME=<base64>` lines) and
|
|
# prints an export for each name, plus an unset for each name in $ORCA_SESSION_ENV_NAMES that is gone.
|
|
# Never writes a file. Values are single-quoted, so quotes, newlines and $ in them stay literal.
|
|
set -euo pipefail
|
|
fish=''
|
|
case "${1-}" in
|
|
'') ;;
|
|
--fish) fish=1 ;;
|
|
-h | --help)
|
|
printf 'usage: eval "$(orca-env)" (fish: orca-env --fish | source)\n'
|
|
exit 0
|
|
;;
|
|
*)
|
|
printf 'orca-env: unknown option %s\n' "$1" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
# ORCA_SESSION_ENV_FILE is for tests; secrets can't set ORCA_* names.
|
|
file="${ORCA_SESSION_ENV_FILE:-/dev/shm/orca-env-$(id -u)/session.env}"
|
|
set -f # names are split below, never globbed
|
|
# Not written yet (or not a cloud VM): nothing to change, like the shell hook.
|
|
[ -r "$file" ] || exit 0
|
|
|
|
# 'it'\''s' for POSIX shells; fish single quotes escape only \ and '.
|
|
quote() {
|
|
local v="$1"
|
|
if [ -n "$fish" ]; then
|
|
v="${v//\\/\\\\}"
|
|
v="${v//\'/\\\'}"
|
|
printf "'%s'" "$v"
|
|
else
|
|
printf "'%s'" "${v//\'/\'\\\'\'}"
|
|
fi
|
|
}
|
|
|
|
# The control plane's reserved names and prefixes (cloud/apps/sandbox-control/src/secrets.ts; a test
|
|
# keeps this in sync): a session file never sets what would hijack the shell or Orca's own processes.
|
|
skip_name() {
|
|
case "$1" in
|
|
'' | *[!A-Z0-9_]* | [0-9]*) return 0 ;;
|
|
LD_* | DYLD_* | ORCA_* | VERCEL_* | BASH_FUNC_* | GIT_CONFIG*) return 0 ;;
|
|
PATH | HOME | USER | LOGNAME | SHELL | PWD | OLDPWD | LANG | TERM | TMPDIR | IFS | ENV | \
|
|
BASH_ENV | PS4 | PROMPT_COMMAND | SHELLOPTS | BASHOPTS | NODE_OPTIONS | NODE_PATH | \
|
|
NODE_EXTRA_CA_CERTS | NODE_TLS_REJECT_UNAUTHORIZED | SSL_CERT_FILE | SSL_CERT_DIR | \
|
|
CURL_CA_BUNDLE | REQUESTS_CA_BUNDLE | HTTP_PROXY | HTTPS_PROXY | ALL_PROXY | NO_PROXY | \
|
|
PYTHONPATH | PYTHONSTARTUP | PERL5OPT | RUBYOPT | JAVA_TOOL_OPTIONS | GIT_SSH | \
|
|
GIT_SSH_COMMAND | GIT_ASKPASS | GIT_EXEC_PATH | GIT_PROXY_COMMAND | SSH_AUTH_SOCK | \
|
|
GH_TOKEN | GITHUB_TOKEN) return 0 ;;
|
|
# CLAUDE_CODE_OAUTH_TOKEN is reserved for users but set by the control plane itself: only ever the
|
|
# Orca-account placeholder (contract D10), never a stored value.
|
|
esac
|
|
return 1
|
|
}
|
|
|
|
names=' '
|
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
name="${line%%=*}"
|
|
skip_name "$name" && continue
|
|
# $(...) drops trailing newlines; the x keeps them.
|
|
value="$(printf '%s' "${line#*=}" | base64 -d 2>/dev/null; printf x)"
|
|
value="${value%x}"
|
|
if [ -n "$fish" ]; then
|
|
printf 'set -gx %s %s\n' "$name" "$(quote "$value")"
|
|
else
|
|
printf 'export %s=%s\n' "$name" "$(quote "$value")"
|
|
fi
|
|
names="$names$name "
|
|
done <"$file"
|
|
for name in ${ORCA_SESSION_ENV_NAMES-}; do
|
|
skip_name "$name" && continue
|
|
case "$names" in *" $name "*) continue ;; esac
|
|
if [ -n "$fish" ]; then
|
|
printf 'set -e %s\n' "$name"
|
|
else
|
|
printf 'unset %s\n' "$name"
|
|
fi
|
|
done
|
|
names="${names# }"
|
|
names="${names% }"
|
|
if [ -n "$fish" ]; then
|
|
printf 'set -gx ORCA_SESSION_ENV_NAMES %s\n' "$(quote "$names")"
|
|
else
|
|
printf 'export ORCA_SESSION_ENV_NAMES=%s\n' "$(quote "$names")"
|
|
fi
|