]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Set GPGTTY when calling gpg
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 9 Aug 2023 07:53:07 +0000 (09:53 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 9 Aug 2023 10:12:15 +0000 (11:12 +0100)
Fixes #351

mkosi/__init__.py

index 4f2c56b40876adb5db4ac57fce7cb65e92309fdf..98e10e4d80634e4ba1c1af97e8e3367ef2f1e5a7 100644 (file)
@@ -859,20 +859,18 @@ def calculate_signature(state: MkosiState) -> None:
             state.staging / state.config.output_checksum,
         ]
 
+        # Set the path of the keyring to use based on the environment if possible and fallback to the default
+        # path. Without this the keyring for the root user will instead be used which will fail for a
+        # non-root build.
+        env = dict(GNUPGHOME=os.environ.get("GNUPGHOME", os.fspath(((Path(os.environ["HOME"]) / ".gnupg")))))
+        if sys.stderr.isatty():
+            env |= dict(GPGTTY=os.ttyname(sys.stderr.fileno()))
+
         run(
             cmdline,
             # Do not output warnings about keyring permissions
             stderr=subprocess.DEVNULL,
-            env={
-                # Set the path of the keyring to use based on the environment
-                # if possible and fallback to the default path. Without this the
-                # keyring for the root user will instead be used which will fail
-                # for a non-root build.
-                "GNUPGHOME": os.environ.get(
-                    "GNUPGHOME",
-                    os.fspath(((Path(os.environ["HOME"]) / ".gnupg"))),
-                )
-            },
+            env=env,
         )