From 1cac36b73a37d489c4ef4b04eaace108be0cbe90 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Sun, 28 Aug 2022 01:48:53 +0200 Subject: [PATCH] chroot: add chroot.add_sudo_config() --- chroot/abstract.py | 8 ++++++++ image.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/chroot/abstract.py b/chroot/abstract.py index 12e542e..84b506c 100644 --- a/chroot/abstract.py +++ b/chroot/abstract.py @@ -337,6 +337,14 @@ class Chroot(AbstractChroot): if result.returncode != 0: raise Exception(f'Failed to setup user {user} in self.name') + def add_sudo_config(self, config_name: str = 'wheel', privilegee: str = '%wheel', password_required: bool = True): + if '.' in config_name: + raise Exception(f"won't create sudoers.d file {config_name} since it will be ignored by sudo because it contains a dot!") + comment = ('# allow ' + (f'members of group {privilegee.strip("%")}' if privilegee.startswith('%') else f'user {privilegee}') + + 'to run any program as root' + ('' if password_required else ' without a password')) + line = privilegee + (' ALL=(ALL:ALL) ALL' if password_required else ' ALL=(ALL) NOPASSWD: ALL') + root_write_file(self.get_path(f'/etc/sudoers.d/{config_name}'), f'{comment}\n{line}') + def try_install_packages( self, packages: list[str], diff --git a/image.py b/image.py index 6ca0391..47430d2 100644 --- a/image.py +++ b/image.py @@ -319,6 +319,7 @@ def install_rootfs( user=user, password=profile['password'], ) + chroot.add_sudo_config(config_name='wheel', privilegee='%wheel', password_required=True) copy_ssh_keys( chroot.path, user=user, @@ -329,7 +330,6 @@ def install_rootfs( extra_repos=get_kupfer_https(arch).repos, in_chroot=True, ), - 'etc/sudoers.d/wheel': "# allow members of group wheel to execute any command\n%wheel ALL=(ALL:ALL) ALL\n", 'etc/hostname': profile['hostname'], } for target, content in files.items():