Add sessions-ctl and systemd units for the dev box
sessions-ctl creates, starts, stops and lists Claude Code sessions. Each one is a checkout in ~/sessions/<name>, a state file and a systemd user unit that runs claude with Remote Control in its own tmux server. Sessions are restarted if they crash, come back at boot (linger), and resume the same conversation by a pinned session UUID. Over SSH it runs as a forced command: only list/repos/status/create/start/ stop/health are accepted, arguments are validated, and nothing reaches a shell or Claude as a prompt. refresh-access keeps the key's from= restriction in sync with the IP of reudy.net (hourly timer). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
1816f6f863
7 changed files with 754 additions and 0 deletions
46
dev/install.sh
Executable file
46
dev/install.sh
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
#!/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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue