keygen generates an ed25519 pair in RAM, writes the public half to config.toml and authorized_keys (replacing the previous sessions-manager line) and prints the web app's environment - dev host, port, user, pinned host key and the private key as one base64 line - then deletes the private key, so the pasted copy is the only one. Refuses to replace an existing key without --rotate. Local only, never reachable over SSH. Also make load_config() read CONFIG_PATH at call time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KKYfRST9cTJYae3f7Jf3ac
46 lines
1.9 KiB
Bash
Executable file
46 lines
1.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Install / update the dev-box side of the session manager for the current user.
|
|
# Idempotent: safe to re-run after every pull. Never overwrites config.toml.
|
|
set -euo pipefail
|
|
|
|
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
bin="$HOME/.local/bin"
|
|
units="$HOME/.config/systemd/user"
|
|
cfg_dir="$HOME/.config/sessions"
|
|
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
|
|
|
|
for cmd in python3 tmux git systemctl claude; do
|
|
command -v "$cmd" >/dev/null || PATH="$bin:$PATH" command -v "$cmd" >/dev/null \
|
|
|| { echo "missing dependency: $cmd" >&2; exit 1; }
|
|
done
|
|
python3 -c 'import sys; sys.exit(sys.version_info < (3, 11))' \
|
|
|| { echo "python3 >= 3.11 required (tomllib)" >&2; exit 1; }
|
|
|
|
install -D -m 755 "$here/sessions_ctl.py" "$bin/sessions-ctl"
|
|
install -d -m 700 "$cfg_dir" "$HOME/.local/state/sessions"
|
|
for f in "$here"/systemd/*; do
|
|
install -D -m 644 "$f" "$units/$(basename "$f")"
|
|
done
|
|
|
|
if [[ ! -e "$cfg_dir/config.toml" ]]; then
|
|
install -m 600 "$here/config.example.toml" "$cfg_dir/config.toml"
|
|
echo "created $cfg_dir/config.toml — edit [repos] and [ssh_access], then run: sessions-ctl keygen"
|
|
fi
|
|
chmod 600 "$cfg_dir/config.toml"
|
|
|
|
systemctl --user daemon-reload
|
|
systemctl --user enable --now sessions-access-refresh.timer >/dev/null
|
|
|
|
# Without linger, user units stop at logout and never start at boot.
|
|
if [[ "$(loginctl show-user "$USER" -p Linger --value 2>/dev/null)" != "yes" ]]; then
|
|
echo "WARNING: linger is off — sessions will not survive a reboot."
|
|
echo " run: sudo loginctl enable-linger $USER"
|
|
fi
|
|
|
|
# Write/refresh prod's authorized_keys line if the config has a real key.
|
|
if grep -Eq '^public_key = "ssh-[a-z0-9-]+ AAAA[A-Za-z0-9+/=]{20,}' "$cfg_dir/config.toml"; then
|
|
"$bin/sessions-ctl" refresh-access
|
|
else
|
|
echo "no key for prod yet — run: sessions-ctl keygen"
|
|
fi
|
|
echo "installed. try: sessions-ctl health"
|