#!/bin/bash # ============================================================================= # officer-setup — the environment file # ============================================================================= # # Definitions only. # # ── What is NOT here ── # # JWT_SECRET and VAULT_STORE_KEY are not written. They are moving into the SQLite # key store (docs/secret-store.md), and writing them here in the meantime would # mean generating a value that the store then has to be reconciled with — two # origins for one secret, which is the failure the store exists to end. # # The consequence is honest and deliberate: jwt.ts throws at module load without # JWT_SECRET, so an install made by this script does not boot until the store # lands. That sequencing was chosen rather than stumbled into. # # ── Derived, not asked ── # # DATA_PATH, OFFICER_ITEMS_DIR and HOME_DIR are gone too, and this time nothing # replaces them. The platform derives the install root as the parent of its own # working directory, so data/, capabilities/ and dockers/ follow from the layout # on disk, and the owner's home comes from the OS. They were three environment # variables that had to agree with each other and with the directory tree. [[ -n "${OFFICER_SETUP_ENV_LOADED:-}" ]] && return 0 OFFICER_SETUP_ENV_LOADED=1 env_file() { echo "$(platform_dir)/.env"; } env_exists() { [[ -f "$(env_file)" ]]; } # One value out of an existing .env, without sourcing it — the file holds # secrets and arbitrary shell would run as root. env_get() { [[ -r "$(env_file)" ]] || return 0 awk -F= -v k="$1" ' $1 == k { v = substr($0, index($0, "=") + 1) gsub(/^"|"$/, "", v) print v exit }' "$(env_file)" } # Origin checking is OFF unless this is explicitly false — CLAUDE.md is explicit # that the inversion is deliberate and is only defensible because the tailnet is # the perimeter. With no tailnet there is no perimeter, so the default stops # being defensible and the value has to be written the other way. tailnet_present() { ip link show tailscale0 &>/dev/null; } write_env() { local dest dest="$(env_file)" [[ -f "$dest" ]] && cp -a "$dest" "${dest}.before-officer-setup" # Restrictive from the moment it exists rather than chmod'd afterwards, so the # secrets are never briefly world-readable. Restored straight after: umask is # not scoped to a function, and leaving it at 077 would quietly make every file # a later section creates owner-only. local prior_umask prior_umask="$(umask)" umask 077 cat >"$dest" <