aboutsummaryrefslogtreecommitdiff
path: root/scripts/p7s
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/p7s')
-rw-r--r--scripts/p7s/appdirs.py11
-rw-r--r--scripts/p7s/bitwarden.py37
-rw-r--r--scripts/p7s/mail/__init__.py4
-rw-r--r--scripts/p7s/newsboat.py8
-rw-r--r--scripts/p7s/zfs.py6
5 files changed, 9 insertions, 57 deletions
diff --git a/scripts/p7s/appdirs.py b/scripts/p7s/appdirs.py
deleted file mode 100644
index 9ff0ca80..00000000
--- a/scripts/p7s/appdirs.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import appdirs
-import pathlib
-
-
-APPDIRS = appdirs.AppDirs("p7s", "alex@pdp7.net")
-
-
-def user_cache_dir():
- r = pathlib.Path(APPDIRS.user_cache_dir)
- r.mkdir(parents=True, exist_ok=True)
- return r
diff --git a/scripts/p7s/bitwarden.py b/scripts/p7s/bitwarden.py
index f3f26dd1..ab6cc4f2 100644
--- a/scripts/p7s/bitwarden.py
+++ b/scripts/p7s/bitwarden.py
@@ -1,35 +1,13 @@
import contextlib
-import io
import json
import os
import subprocess
-import zipfile
-
-import httpx
-
-from p7s import appdirs
class Bitwarden():
- def download(self, check_version=False):
- self.bw_command = appdirs.user_cache_dir() / "bw"
- if self.bw_command.exists() and not check_version:
- return self.bw_command
- r = httpx.get("https://vault.bitwarden.com/download/?app=cli&platform=linux")
- location = r.headers["location"]
- version = location.split("/")[7]
- bw_versioned_command = appdirs.user_cache_dir() / f"bw-{version}"
- if not bw_versioned_command.exists():
- with zipfile.ZipFile(io.BytesIO(httpx.get(location, follow_redirects=True).content)) as zip:
- with zip.open("bw") as zip_bw:
- bw_versioned_command.write_bytes(zip_bw.read())
- bw_versioned_command.chmod(0o755)
- self.bw_command.unlink(missing_ok=True)
- self.bw_command.symlink_to(bw_versioned_command)
-
@contextlib.contextmanager
def login(self, server, email):
- subprocess.run([self.bw_command, "config", "server", server], check=True)
+ subprocess.run(["bw", "config", "server", server], check=True)
status = self.status()["status"]
if status == "unauthenticated":
command = ["login", email]
@@ -37,29 +15,28 @@ class Bitwarden():
command = ["unlock"]
else:
assert False, f"unexpected status {status}"
- command = subprocess.run([self.bw_command] + command, check=True, stdout=subprocess.PIPE, encoding="UTF8")
+ command = subprocess.run(["bw"] + command, check=True, stdout=subprocess.PIPE, encoding="UTF8")
export_line = command.stdout.splitlines()[3]
session = export_line.split('"')[1]
os.environ["BW_SESSION"] = session
try:
- yield self.bw_command
- subprocess.run([self.bw_command, "lock"], check=True)
+ yield
+ subprocess.run(["bw", "logout"], check=True)
finally:
del os.environ["BW_SESSION"]
def sync(self):
- subprocess.run([self.bw_command, "sync"], check=True)
+ subprocess.run(["bw", "sync"], check=True)
def status(self):
- return json.loads(subprocess.run([self.bw_command, "status"], check=True, stdout=subprocess.PIPE).stdout)
+ return json.loads(subprocess.run(["bw", "status"], check=True, stdout=subprocess.PIPE).stdout)
def get_item(self, uuid):
- return json.loads(subprocess.run([self.bw_command, "get", "item", uuid], check=True, stdout=subprocess.PIPE).stdout)
+ return json.loads(subprocess.run(["bw", "get", "item", uuid], check=True, stdout=subprocess.PIPE).stdout)
def get_item(server, email, uuid):
b = Bitwarden()
- b.download()
with b.login(server, email):
b.sync()
return b.get_item(uuid)
diff --git a/scripts/p7s/mail/__init__.py b/scripts/p7s/mail/__init__.py
index 0bcbf33c..0300e80a 100644
--- a/scripts/p7s/mail/__init__.py
+++ b/scripts/p7s/mail/__init__.py
@@ -7,8 +7,8 @@ from p7s.mail import mbsync
def generate_config():
- gmail = bitwarden.get_item("https://bitwarden.pdp7.net", "alex@corcoles.net", "cad137b0-cfd5-4d5c-b167-98a9e792f4cc")["login"]
- yahoo = bitwarden.get_item("https://bitwarden.pdp7.net", "alex@corcoles.net", "e24727e7-c0ef-4c97-afd0-8497d547304c")["login"]
+ gmail = bitwarden.get_item("https://vaultwarden.pdp7.net", "alex@corcoles.net", "f9bba940-769d-430a-82f4-5da10990e8fd")["login"]
+ yahoo = bitwarden.get_item("https://vaultwarden.pdp7.net", "alex@corcoles.net", "5c4d9e3b-121d-45f5-bab6-03b42d291326")["login"]
(pathlib.Path.home() / (".mbsyncrc")).write_text(
mbsync.mbsync_gmail(gmail["username"], gmail["password"], "~/Mail") +
"\n" +
diff --git a/scripts/p7s/newsboat.py b/scripts/p7s/newsboat.py
deleted file mode 100644
index ac88ae1d..00000000
--- a/scripts/p7s/newsboat.py
+++ /dev/null
@@ -1,8 +0,0 @@
-import os
-import sys
-
-
-def main():
- env = os.environ.copy()
- env["LOCALE_ARCHIVE"] = "/usr/lib/locale/locale-archive"
- os.execve("/home/alex/.local/bin/nix-portable", ("nix-portable", "nix", "shell", "nixpkgs#newsboat", "-c", "newsboat"), env)
diff --git a/scripts/p7s/zfs.py b/scripts/p7s/zfs.py
deleted file mode 100644
index d51ff17c..00000000
--- a/scripts/p7s/zfs.py
+++ /dev/null
@@ -1,6 +0,0 @@
-import subprocess
-
-
-def update_zfs():
- version = subprocess.run(["rpm", "-q", "zfs-dkms", '--queryformat=%{VERSION}'], check=True, stdout=subprocess.PIPE, encoding="utf8").stdout
- subprocess.run(["sudo", "dkms", "install", f"zfs/{version}"], check=True)