mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 13:45:45 -05:00
chroot: add chroot.add_sudo_config()
This commit is contained in:
parent
5329f7a5b0
commit
1cac36b73a
2 changed files with 9 additions and 1 deletions
|
@ -337,6 +337,14 @@ class Chroot(AbstractChroot):
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
raise Exception(f'Failed to setup user {user} in self.name')
|
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(
|
def try_install_packages(
|
||||||
self,
|
self,
|
||||||
packages: list[str],
|
packages: list[str],
|
||||||
|
|
2
image.py
2
image.py
|
@ -319,6 +319,7 @@ def install_rootfs(
|
||||||
user=user,
|
user=user,
|
||||||
password=profile['password'],
|
password=profile['password'],
|
||||||
)
|
)
|
||||||
|
chroot.add_sudo_config(config_name='wheel', privilegee='%wheel', password_required=True)
|
||||||
copy_ssh_keys(
|
copy_ssh_keys(
|
||||||
chroot.path,
|
chroot.path,
|
||||||
user=user,
|
user=user,
|
||||||
|
@ -329,7 +330,6 @@ def install_rootfs(
|
||||||
extra_repos=get_kupfer_https(arch).repos,
|
extra_repos=get_kupfer_https(arch).repos,
|
||||||
in_chroot=True,
|
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'],
|
'etc/hostname': profile['hostname'],
|
||||||
}
|
}
|
||||||
for target, content in files.items():
|
for target, content in files.items():
|
||||||
|
|
Loading…
Add table
Reference in a new issue