util: added get_pass function

This commit is contained in:
missytake 2024-11-30 21:30:46 +01:00
parent 390b8ae683
commit 3f24eb05bd
Signed by: missytake
GPG key ID: 04CC6658320518DF
9 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,3 @@
Metadata-Version: 2.1
Name: pyinfra-util
Version: 0.1

View file

@ -0,0 +1,7 @@
pyproject.toml
pyinfra_util/__init__.py
pyinfra_util/util.py
pyinfra_util.egg-info/PKG-INFO
pyinfra_util.egg-info/SOURCES.txt
pyinfra_util.egg-info/dependency_links.txt
pyinfra_util.egg-info/top_level.txt

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@
pyinfra_util

View file

@ -0,0 +1 @@
from .util import get_pass, deploy_tmux

View file

@ -0,0 +1,56 @@
"""
nginx deploy
"""
import subprocess
from pyinfra.operations import files, apt
def get_pass(filename: str) -> str:
"""Get the data from the password manager."""
try:
r = subprocess.run(["pass", "show", filename], capture_output=True)
except FileNotFoundError:
readme_url = "https://git.0x90.space/deltachat/secrets"
print(f"Please install pass and pull the latest version of our pass secrets from {readme_url}")
exit()
return r.stdout.decode('utf-8')
def deploy_tmux(home_dir="/root", escape_key="C-b", additional_config=[]):
apt.packages(
name="apt install tmux",
packages=["tmux"],
)
config = [
f"set-option -g prefix {escape_key}",
"set-option -g aggressive-resize on",
"set-option -g mouse on",
"set-option -g set-titles on",
"set-option -g set-titles-string '#I:#W - \"#H\"'",
"unbind-key C-b",
"bind-key ` send-prefix",
"bind-key a last-window",
"bind-key k kill-session",
]
for item in additional_config:
config.append(item)
for line in config:
files.line(
path=f"{home_dir}/.tmux.conf",
line=line,
)
dot_profile_add = """
# autostart tmux
if [ -t 0 -a -z "$TMUX" ]
then
test -z "$(tmux list-sessions)" && exec tmux new -s "$USER" || exec tmux new -A -s $(tty | tail -c +6) -t "$USER"
fi
"""
files.block(
name="connect to tmux session on login",
path=f"{home_dir}/.profile",
content=dot_profile_add,
try_prevent_shell_expansion=True,
)

View file

@ -0,0 +1,7 @@
[build-system]
requires = ["setuptools>=45"]
build-backend = "setuptools.build_meta"
[project]
name = "pyinfra-util"
version = "0.1"