From 7e7d11c520a810241ad1bfc4672ef84693ef484e Mon Sep 17 00:00:00 2001 From: Fuxino Date: Thu, 8 Oct 2026 17:43:28 +0200 Subject: [PATCH] Detect the invoking user when running with doas User detection only checked SUDO_USER, so with doas the user's config file was not found unless -u was given. Fall back to DOAS_USER, as already done for notifications. --- simple_backup/simple_backup.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index 3d9420e..4f4c199 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -644,14 +644,15 @@ class Backup: return 0 +def _detect_user() -> Optional[str]: + if os.geteuid() == 0: + return os.getenv('SUDO_USER') or os.getenv('DOAS_USER') + + return os.getenv('USER') + + def _parse_arguments() -> argparse.Namespace: - euid = os.geteuid() - - if euid == 0: - user = os.getenv('SUDO_USER') - else: - user = os.getenv('USER') - + user = _detect_user() homedir = os.path.expanduser(f'~{user}') parser = argparse.ArgumentParser(prog='simple_backup', @@ -874,7 +875,7 @@ def simple_backup() -> int: euid = os.geteuid() if euid == 0: - user = os.getenv('SUDO_USER') + user = _detect_user() if user is not None: homedir = os.path.expanduser(f'~{user}')