diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/.gitignore | 1 | ||||
| -rw-r--r-- | scripts/p7s/bitwarden.py | 39 | ||||
| -rw-r--r-- | scripts/p7s/ssh.py | 8 | ||||
| -rw-r--r-- | scripts/p7s/ubpkg.py | 4 | ||||
| -rw-r--r-- | scripts/pyproject.toml | 2 |
5 files changed, 53 insertions, 1 deletions
diff --git a/scripts/.gitignore b/scripts/.gitignore index bee8a64b..76e51dbb 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -1 +1,2 @@ __pycache__ +p7s.egg-info diff --git a/scripts/p7s/bitwarden.py b/scripts/p7s/bitwarden.py index ab6cc4f2..7818b26a 100644 --- a/scripts/p7s/bitwarden.py +++ b/scripts/p7s/bitwarden.py @@ -1,13 +1,19 @@ +import argparse import contextlib import json import os +import pathlib import subprocess +import tempfile +import urllib.request +import zipfile class Bitwarden(): @contextlib.contextmanager def login(self, server, email): - subprocess.run(["bw", "config", "server", server], check=True) + if subprocess.run(["bw", "config", "server"], check=True, text=True, stdout=subprocess.PIPE).stdout.strip() != server: + subprocess.run(["bw", "config", "server", server], check=True) status = self.status()["status"] if status == "unauthenticated": command = ["login", email] @@ -34,9 +40,40 @@ class Bitwarden(): def get_item(self, uuid): return json.loads(subprocess.run(["bw", "get", "item", uuid], check=True, stdout=subprocess.PIPE).stdout) + def get_attachment(self, attachment_id, item_id, destination): + subprocess.run(["bw", "get", "attachment", attachment_id, "--itemid", item_id, "--output", destination], check=True) def get_item(server, email, uuid): b = Bitwarden() with b.login(server, email): b.sync() return b.get_item(uuid) + + +@contextlib.contextmanager +def default(): + b = Bitwarden() + with b.login("https://vaultwarden.pdp7.net", "alex@corcoles.net"): + b.sync() + yield b + + +def install_cli(version): + with tempfile.TemporaryDirectory() as tempdir: + tempdir = pathlib.Path(tempdir) + zip = tempdir / "zip" + with urllib.request.urlopen(f"https://github.com/bitwarden/clients/releases/download/cli-v{version}/bw-oss-linux-{version}.zip") as urlopen: + zip.write_bytes(urlopen.read()) + with zipfile.ZipFile(zip) as zip: + with zip.open("bw") as bw: + bw_path = pathlib.Path.home() / ".local" / "bin" / "bw" + bw_path.unlink() + bw_path.write_bytes(bw.read()) + bw_path.chmod(0o555) + + +def install_cli_main(): + parser = argparse.ArgumentParser() + parser.add_argument("version") + args = parser.parse_args() + install_cli(args.version) diff --git a/scripts/p7s/ssh.py b/scripts/p7s/ssh.py new file mode 100644 index 00000000..f53cad33 --- /dev/null +++ b/scripts/p7s/ssh.py @@ -0,0 +1,8 @@ +import pathlib + +from p7s import bitwarden + + +def setup_ssh(): + with bitwarden.default() as b: + b.get_attachment("06ba85e9172775f8f320", "e1d1a559-feaa-4834-b192-a688708bdba3", pathlib.Path.home() / ".ssh" / "id_rsa") diff --git a/scripts/p7s/ubpkg.py b/scripts/p7s/ubpkg.py index 3a333254..4249c3e0 100644 --- a/scripts/p7s/ubpkg.py +++ b/scripts/p7s/ubpkg.py @@ -1,6 +1,7 @@ import os import pathlib import platform +import subprocess import urllib.request @@ -9,3 +10,6 @@ def setup_ubpkg(): with urllib.request.urlopen(f"https://github.com/alexpdp7/ubpkg/releases/latest/download/ubpkg-linux-{platform.machine()}") as urlopen: ubpkg.write_bytes(urlopen.read()) os.chmod(ubpkg, 0o700) + + # Currently Vaultwarden in EPEL is not compatible with latest Bitwarden CLI https://github.com/dani-garcia/vaultwarden/issues/7820 + subprocess.run([ubpkg, "deltachat-rpc-server", "hatch", "kubectl", "nix-portable", "ressh", "talosctl", "typst"], check=True) diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml index 36bf52c2..85ced5c4 100644 --- a/scripts/pyproject.toml +++ b/scripts/pyproject.toml @@ -14,10 +14,12 @@ setup-imapfilter = 'p7s.mail:setup_imapfilter' setup-soju = 'p7s.soju:setup_soju' setup-ubpkg = 'p7s.ubpkg:setup_ubpkg' setup-x12 = 'p7s.x12:setup_x12' +setup-ssh = 'p7s.ssh:setup_ssh' senpai = 'p7s.senpai:main' ledger = 'p7s.ledger:main' google-meet-toggle-mute = 'p7s.google_meet:toggle_mute' google-meet-install-stream-deck-wsbroad-server = 'p7s.google_meet:install_stream_deck_google_meet_wsbroad_server' +install-bitwarden-cli = 'p7s.bitwarden:install_cli_main' [tool.uv] package = true |
