#!/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 re-run." 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 "ssh_access.public_key not set yet — skipping authorized_keys." fi echo "installed. try: sessions-ctl health"