util: added get_pass function
This commit is contained in:
parent
390b8ae683
commit
3f24eb05bd
3
lib/pyinfra-util/pyinfra_util.egg-info/PKG-INFO
Normal file
3
lib/pyinfra-util/pyinfra_util.egg-info/PKG-INFO
Normal file
|
@ -0,0 +1,3 @@
|
|||
Metadata-Version: 2.1
|
||||
Name: pyinfra-util
|
||||
Version: 0.1
|
7
lib/pyinfra-util/pyinfra_util.egg-info/SOURCES.txt
Normal file
7
lib/pyinfra-util/pyinfra_util.egg-info/SOURCES.txt
Normal 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
|
|
@ -0,0 +1 @@
|
|||
|
1
lib/pyinfra-util/pyinfra_util.egg-info/top_level.txt
Normal file
1
lib/pyinfra-util/pyinfra_util.egg-info/top_level.txt
Normal file
|
@ -0,0 +1 @@
|
|||
pyinfra_util
|
1
lib/pyinfra-util/pyinfra_util/__init__.py
Normal file
1
lib/pyinfra-util/pyinfra_util/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from .util import get_pass, deploy_tmux
|
Binary file not shown.
BIN
lib/pyinfra-util/pyinfra_util/__pycache__/util.cpython-310.pyc
Normal file
BIN
lib/pyinfra-util/pyinfra_util/__pycache__/util.cpython-310.pyc
Normal file
Binary file not shown.
56
lib/pyinfra-util/pyinfra_util/util.py
Normal file
56
lib/pyinfra-util/pyinfra_util/util.py
Normal 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,
|
||||
)
|
7
lib/pyinfra-util/pyproject.toml
Normal file
7
lib/pyinfra-util/pyproject.toml
Normal file
|
@ -0,0 +1,7 @@
|
|||
[build-system]
|
||||
requires = ["setuptools>=45"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "pyinfra-util"
|
||||
version = "0.1"
|
Loading…
Reference in a new issue