]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Look for $USER for the username before reading /etc/passwd
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 29 Jul 2024 15:47:47 +0000 (17:47 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 29 Jul 2024 16:43:57 +0000 (18:43 +0200)
Let's take $USER into account if set before reading /etc/passwd
for the username. This gives a way out for environments where the
uid of the user does not have an entry in /etc/passwd.

mkosi/user.py

index 4a0ec833973c176a82d2cd224ab76900fae38fe0..6dc72eaa43ce49b5f703a4f1be9dc089c39924b5 100644 (file)
@@ -39,7 +39,7 @@ class INVOKING_USER:
     @classmethod
     @functools.lru_cache(maxsize=1)
     def name(cls) -> str:
-        return pwd.getpwuid(cls.uid).pw_name
+        return os.getenv("USER", pwd.getpwuid(cls.uid).pw_name)
 
     @classmethod
     @functools.lru_cache(maxsize=1)