Skip to content

Commit

Permalink
[WIP] feat: with-qubesdb runs a command with each -k/--key read from …
Browse files Browse the repository at this point in the history
…QubesDB and set as an environment variable
  • Loading branch information
cfm committed Mar 8, 2024
1 parent 2e0ae4c commit 44cd324
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions with-qubesdb
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
import argparse
import subprocess

from qubesdb import QubesDB

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Use -k/--key one or more times to read the specified key from QubesDB. All subsequent arguments will be interpreted as the command to be invoked with those keys set as environment variables.")
parser.add_argument("-k", "--key", action="append")
args = parser.parse_known_args()

env = {}
db = QubesDB()
for key in args[0].key or []:
value = db.read(f"/vm-config/{key}")
env[key] = value or ''

if len(args[1]) > 0:
cmd = subprocess.Popen(args[1], env=env)
cmd.wait()

0 comments on commit 44cd324

Please sign in to comment.