-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tmux configuration when snac mode is enabled
* Set lock time to 15 minutes of inactivity * Switch shell to tmux on login so inactivity lock can be used Signed-off-by: Mark Silva <[email protected]>
- Loading branch information
1 parent
093a687
commit 72dfad9
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import argparse | ||
import subprocess | ||
import textwrap | ||
|
||
from nilrt_snac._configs._base_config import _BaseConfig | ||
from nilrt_snac._configs._config_file import _ConfigFile | ||
|
||
from nilrt_snac import logger, SNAC_DATA_DIR | ||
from nilrt_snac.OpkgHelper import opkg_helper | ||
|
||
|
||
class _TmuxConfig(_BaseConfig): | ||
def __init__(self): | ||
self._opkg_helper = opkg_helper | ||
|
||
def configure(self, args: argparse.Namespace) -> None: | ||
print("Configuring tmux...") | ||
snac_config_file = _ConfigFile("/usr/share/tmux/conf.d/snac.conf") | ||
profile_file = _ConfigFile("/etc/profile.d/tmux.sh") | ||
dry_run: bool = args.dry_run | ||
self._opkg_helper.install("tmux") | ||
|
||
if not snac_config_file.exists(): | ||
snac_config_file.add( | ||
textwrap.dedent( | ||
""" | ||
# NILRT SNAC configuration tmux-snac.conf. Do not hand-edit. | ||
set -g lock-after-time 900 | ||
""" | ||
) | ||
) | ||
|
||
if not profile_file.exists(): | ||
profile_file.add( | ||
textwrap.dedent( | ||
""" | ||
# NILRT SNAC configuration tmux.sh. Do not hand-edit. | ||
if [ "$PS1" ]; then | ||
parent=$(ps -o ppid= -p $$) | ||
name=$(ps -o comm= -p $parent) | ||
case "$name" in (sshd|login) exec tmux ;; esac | ||
fi | ||
""" | ||
) | ||
) | ||
|
||
snac_config_file.save(dry_run) | ||
profile_file.save(dry_run) | ||
|
||
def verify(self, args: argparse.Namespace) -> bool: | ||
print("Verifying tmux configuration...") | ||
snac_config_file = _ConfigFile("/usr/share/tmux/conf.d/snac.conf") | ||
profile_file = _ConfigFile("/etc/profile.d/tmux.sh") | ||
valid = True | ||
if not self._opkg_helper.is_installed("tmux"): | ||
valid = False | ||
logger.error("MISSING: tmux not installed") | ||
if not snac_config_file.exists(): | ||
valid = False | ||
logger.error(f"MISSING: {snac_config_file.path} not found") | ||
if not snac_config_file.contains("set -g lock-after-time"): | ||
valid = False | ||
logger.error("MISSING: commands to inactivity lock") | ||
if not profile_file.exists(): | ||
valid = False | ||
logger.error(f"MISSING: {profile_file.path} not found") | ||
if not profile_file.contains("exec tmux"): | ||
valid = False | ||
logger.error("MISSING: command to replace shell with tmux") | ||
return valid |