mirror of https://git.48k.eu/ogclient
utils: add set_linux_hostname
Add set_linux_hostname function to redefine the hostname of a Linux install by overwriting the contents of /etc/hostnamemaster
parent
adbf02d170
commit
210a70fc73
|
|
@ -66,6 +66,25 @@ def set_windows_hostname(disk, partition, name):
|
||||||
umount(mountpoint)
|
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):
|
def configure_os_custom(disk, partition):
|
||||||
if not shutil.which('configureOsCustom'):
|
if not shutil.which('configureOsCustom'):
|
||||||
raise OgError('configureOsCustom not found')
|
raise OgError('configureOsCustom not found')
|
||||||
|
|
@ -149,6 +168,9 @@ def install_grub(disk, partition):
|
||||||
|
|
||||||
|
|
||||||
def configure_os_linux(disk, partition):
|
def configure_os_linux(disk, partition):
|
||||||
|
hostname = gethostname()
|
||||||
|
set_linux_hostname(disk, partition, hostname)
|
||||||
|
|
||||||
configure_fstab(disk, partition)
|
configure_fstab(disk, partition)
|
||||||
|
|
||||||
if is_uefi_supported():
|
if is_uefi_supported():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue