Adds tmux to the ubuntu_lxc and ubuntu_vm profiles and an opt-in
/etc/profile.d snippet that attaches an interactive SSH login to a tmux
session, created with configurable windows when it does not exist.
- system_baseline_tmux_autostart (default false), _session (default main)
and _windows ([{name, command}]); only ubuntu_lxc and ubuntu_vm install
the snippet, pve never does, and false removes it.
- profile.d is read only by an interactive login shell, so scp, sftp,
ssh host command and automation are unaffected. ~/.no-tmux opts a user
out. ForceCommand is not used: it would affect every session type.
- Names and commands are validated and shell-quoted; the script is
root-owned. Commands run as the logging-in user and are world-readable,
so they must hold no secret.
- Molecule converge enables it, verify checks ownership, mode, the attach
line, the quoting and sh -n.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q72rsMEKREGMfB9DH3T9mR
15 lines
1000 B
Django/Jinja
15 lines
1000 B
Django/Jinja
# Managed by Ansible (mortis.kamino.system_baseline, tasks/tmux.yml). Do not edit: the next run overwrites it.
|
|
# Interactive SSH logins only (profile.d is not read by scp, sftp, `ssh host command` or Ansible).
|
|
# Off for one user: touch ~/.no-tmux
|
|
if [ -n "$SSH_CONNECTION" ] && [ -z "$TMUX" ] && [ -t 0 ] && [ ! -e "$HOME/.no-tmux" ] && command -v tmux >/dev/null 2>&1; then
|
|
# new-session -d fails when the session exists, so the windows below are made only when this login creates it (once, even
|
|
# for two logins at the same moment). Windows close when their command exits; window 0 is always a plain shell.
|
|
if tmux new-session -d -s {{ system_baseline_tmux_session | quote }} 2>/dev/null; then
|
|
:
|
|
{% for window in system_baseline_tmux_windows %}
|
|
tmux new-window -d -t {{ ('=' ~ system_baseline_tmux_session ~ ':') | quote }} -n {{ window.name | quote }} {{ window.command | quote }}
|
|
{% endfor %}
|
|
fi
|
|
exec tmux attach-session -t {{ ('=' ~ system_baseline_tmux_session) | quote }}
|
|
fi
|