diff options
author | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-07-25 16:37:06 +0200 |
---|---|---|
committer | Alejandro Sirgo Rica <asirgo@soleta.eu> | 2024-07-29 15:07:22 +0200 |
commit | 210a70fc73ff5a1ef21da914eee320d969a95b06 (patch) | |
tree | 3af776a39a1c54d266db19babf1de7723f7d055d /src | |
parent | adbf02d170701d418ea47b73b442183bb2131099 (diff) |
utils: add set_linux_hostname
Add set_linux_hostname function to redefine the hostname of a
Linux install by overwriting the contents of /etc/hostname
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/postinstall.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/utils/postinstall.py b/src/utils/postinstall.py index 7fef437..374a1cd 100644 --- a/src/utils/postinstall.py +++ b/src/utils/postinstall.py @@ -66,6 +66,25 @@ def set_windows_hostname(disk, partition, name): umount(mountpoint) +def set_linux_hostname(disk, partition, name): + logging.info(f'Configuring hostname') + + device = get_partition_device(disk, partition) + mountpoint = device.replace('dev', 'mnt') + + if not mount_mkdir(device, mountpoint): + raise OgError(f'Unable to mount {device} into {mountpoint}') + + try: + hostname_path = f'{mountpoint}/etc/hostname' + with open(hostname_path, 'w') as f: + f.write(name) + except OSError as e: + raise OgError(f'Unable to configure Linux hostname: {e}') from e + finally: + umount(mountpoint) + + def configure_os_custom(disk, partition): if not shutil.which('configureOsCustom'): raise OgError('configureOsCustom not found') @@ -149,6 +168,9 @@ def install_grub(disk, partition): def configure_os_linux(disk, partition): + hostname = gethostname() + set_linux_hostname(disk, partition, hostname) + configure_fstab(disk, partition) if is_uefi_supported(): |