mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-22 21:25:43 -05:00
chroot: add chroot.get_uid(user: str), use in chroot.mount_{ccache,rust} to apply correct ownership
This commit is contained in:
parent
ba58aa1a29
commit
6c26260001
2 changed files with 16 additions and 2 deletions
|
@ -346,6 +346,18 @@ class Chroot(AbstractChroot):
|
|||
if result.returncode != 0:
|
||||
raise Exception(f'Failed to setup user {user} in self.name')
|
||||
|
||||
def get_uid(self, user: Union[str, int]) -> int:
|
||||
if isinstance(user, int):
|
||||
return user
|
||||
if user == 'root':
|
||||
return 0
|
||||
res = self.run_cmd(['id', '-u', user], capture_output=True)
|
||||
assert isinstance(res, subprocess.CompletedProcess)
|
||||
if res.returncode or not res.stdout:
|
||||
raise Exception(f"chroot {self.name}: Couldnt detect uid for user {user}: {repr(res.stdout)}")
|
||||
uid = res.stdout.decode()
|
||||
return int(uid)
|
||||
|
||||
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!")
|
||||
|
|
|
@ -135,7 +135,8 @@ class BuildChroot(Chroot):
|
|||
def mount_ccache(self, user: str = 'kupfer', fail_if_mounted: bool = False):
|
||||
mount_source = os.path.join(config.file.paths.ccache, self.arch)
|
||||
mount_dest = os.path.join(f'/home/{user}' if user != 'root' else '/root', '.ccache')
|
||||
makedir(mount_source)
|
||||
uid = self.get_uid(user)
|
||||
makedir(mount_source, user=uid)
|
||||
return self.mount(
|
||||
absolute_source=mount_source,
|
||||
relative_destination=mount_dest,
|
||||
|
@ -144,11 +145,12 @@ class BuildChroot(Chroot):
|
|||
|
||||
def mount_rust(self, user: str = 'kupfer', fail_if_mounted: bool = False) -> list[str]:
|
||||
results = []
|
||||
uid = self.get_uid(user)
|
||||
mount_source_base = config.file.paths.rust # apparently arch-agnostic
|
||||
for rust_dir in ['cargo', 'rustup']:
|
||||
mount_source = os.path.join(mount_source_base, rust_dir)
|
||||
mount_dest = os.path.join(f'/home/{user}' if user != 'root' else '/root', f'.{rust_dir}')
|
||||
makedir(mount_source)
|
||||
makedir(mount_source, user=uid)
|
||||
results.append(self.mount(
|
||||
absolute_source=mount_source,
|
||||
relative_destination=mount_dest,
|
||||
|
|
Loading…
Add table
Reference in a new issue