From 23199f5526db9be1d43a900dc8b8674a7babb966 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 5 Dec 2026 22:09:29 +0100 Subject: WIP Somewhat blocked by https://bugzilla.redhat.com/show_bug.cgi?id=2521543 --- scripts/.gitignore | 1 + scripts/p7s/bitwarden.py | 8 ++++++++ scripts/p7s/ssh.py | 7 +++++++ scripts/p7s/ubpkg.py | 3 +++ scripts/pyproject.toml | 1 + workstation/README.md | 3 +++ workstation/root-setup.py | 12 ++++++++++++ workstation/test.py | 41 +++++++++++++++++++++++++++++++++++++++++ workstation/user-setup.py | 18 ++++++++++++++++++ 9 files changed, 94 insertions(+) create mode 100644 scripts/p7s/ssh.py create mode 100644 workstation/README.md create mode 100755 workstation/root-setup.py create mode 100755 workstation/test.py create mode 100755 workstation/user-setup.py 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..6d17d3b1 100644 --- a/scripts/p7s/bitwarden.py +++ b/scripts/p7s/bitwarden.py @@ -40,3 +40,11 @@ def get_item(server, email, uuid): 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 diff --git a/scripts/p7s/ssh.py b/scripts/p7s/ssh.py new file mode 100644 index 00000000..aac25d8e --- /dev/null +++ b/scripts/p7s/ssh.py @@ -0,0 +1,7 @@ +from p7s import bitwarden + + +def setup_ssh(): + with bitwarden.default() as b: + pass + diff --git a/scripts/p7s/ubpkg.py b/scripts/p7s/ubpkg.py index 3a333254..0784ea71 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,5 @@ 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) + + subprocess.run([ubpkg, "bitwarden-cli", "deltachat-rpc-server", "hatch", "kubectl", "nix-portable", "ressh", "talosctl", "typst"], check=True) diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml index 36bf52c2..291176ca 100644 --- a/scripts/pyproject.toml +++ b/scripts/pyproject.toml @@ -14,6 +14,7 @@ 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' diff --git a/workstation/README.md b/workstation/README.md new file mode 100644 index 00000000..6a13bd3a --- /dev/null +++ b/workstation/README.md @@ -0,0 +1,3 @@ +# workstation + +Yet another attempt to automate workstation configuration because I am stubborn and I do not want to lock myself into any Linux distro. diff --git a/workstation/root-setup.py b/workstation/root-setup.py new file mode 100755 index 00000000..4d764a50 --- /dev/null +++ b/workstation/root-setup.py @@ -0,0 +1,12 @@ +#!/usr/bin/python3 +import subprocess + + +def _(*args): + subprocess.run(args, check=True) + + +_("apt", "update") +_("apt", "install", "-y", "git", "tasksel", "pipx") +_("tasksel", "install", "desktop") +_("systemctl", "start", "gdm3") diff --git a/workstation/test.py b/workstation/test.py new file mode 100755 index 00000000..92aeb0c7 --- /dev/null +++ b/workstation/test.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 +import os +import pathlib +import subprocess + + +INSTANCE_NAME="workstation-test" +USER="alex" + +THIS_REPO = pathlib.Path(__file__).parent.parent +THIS_UID = os.getuid() + + +def _(*args, check=True, input=None): + return subprocess.run(args, check=check, input=input, text=True) + + +# _("incus", "launch", +# "images:debian/13", +# INSTANCE_NAME, +# "--ephemeral", +# "--vm", +# "-c", "limits.cpu=4", +# "-c", "limits.memory=6GiB", +# "-d", "root,size=50GiB") + +# while _("incus", "exec", INSTANCE_NAME, "uptime", check=False).returncode != 0: +# print("waiting...") +# time.sleep(1) + +# _("incus", "config", "device", "add", INSTANCE_NAME, "here", "disk", f"source={THIS_REPO}", "path=/here") +# _("incus", "exec", INSTANCE_NAME, "--", "apt", "full-upgrade", "-U") +# _("incus", "exec", INSTANCE_NAME, "--", "apt", "install", "-y", "python3") +# _("incus", "exec", INSTANCE_NAME, "--", "/here/workstation/root-setup.py") +# _("incus", "exec", INSTANCE_NAME, "--", "adduser", USER, "--disabled-password", "--comment", "") +# _("incus", "exec", INSTANCE_NAME, "--", "passwd", USER, "--stdin", input=USER) + +# Comment out to test with real repo +_("incus", "exec", INSTANCE_NAME, "--", "mount", "/here/", f"/home/{USER}/git/alexpdp7/", "-o", f"bind,X-mount.idmap={THIS_UID}:1000:1") + +_("incus", "exec", INSTANCE_NAME, "--", "sudo", "-u", USER, "/here/workstation/user-setup.py") diff --git a/workstation/user-setup.py b/workstation/user-setup.py new file mode 100755 index 00000000..535aa968 --- /dev/null +++ b/workstation/user-setup.py @@ -0,0 +1,18 @@ +#!/usr/bin/python3 +import pathlib +import subprocess + + +def _(*args): + subprocess.run(args, check=True) + +HOME = pathlib.Path.home() +BIN = HOME / ".local" / "bin" +GIT = HOME / "git" +ALEXPDP7_REPO = GIT / "alexpdp7" + +if not ALEXPDP7_REPO.exists(): + _("git", "clone", "https://github.com/alexpdp7/alexpdp7.git", ALEXPDP7_REPO) + +_("pipx", "install", "-e", ALEXPDP7_REPO / "scripts", "--force") +_(BIN / "setup-ubpkg") -- cgit v1.2.3