From 1c80a893acfb97859dd6c0f61a2cf74c03958595 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 25 Jan 2021 15:34:35 +0100 Subject: Adding copy mode for #95 (#82). I wouldn't say this is a hacky way of doing it, but using a string as identifier is the only way I can think of currently in guided.py. When user is prompted to select a interface to configure for networking, there's now a zero-option to copy existing ISO configuration to the install medium. This enables advance configuration prior to running the installer - and simply copy it straight over to the install medium. Two requirements: 1: That iwd is used for wifi configuration and config for passwords etc are stored in /var/lib/iwd 2: That systemd-networkd is used to configure networking/IP/DHCP as anything under /etc/systemd/networkd/* is copied over. --- archinstall/lib/installer.py | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 8c22b51f..51540060 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1,4 +1,4 @@ -import os, stat, time +import os, stat, time, shutil from .exceptions import * from .disk import * @@ -48,6 +48,7 @@ class Installer(): } self.base_packages = base_packages.split(' ') + self.post_base_install = [] storage['session'] = self self.partition = partition @@ -182,6 +183,40 @@ class Installer(): with open(f"{self.mountpoint}/etc/systemd/network/10-{nic}.network", "a") as netconf: netconf.write(str(conf)) + def copy_network_config(self, enable_services=False): + # Copy (if any) iwd password and config files + if os.path.isdir('/var/lib/iwd/'): + if (psk_files := glob.glob('/var/lib/iwd/*.psk')): + if not os.path.isdir(f"{self.mountpoint}/var/lib/iwd"): + os.makedirs(f"{self.mountpoint}/var/lib/iwd") + + self.base_packages.append('iwd') + + + if enable_services and self.helper_flags.get('base', False) is False: + # This function will be called after minimal_installation() + # as a hook for post-installs. This hook is only needed if + # base is not installed yet. + def post_install_enable_iwd_service(*args, **kwargs): + self.enable_service('iwd') + + self.post_base_install.append(post_install_enable_iwd_service) + elif enable_services and self.helper_flags.get('base', False) is True: + self.enable_service('iwd') + + for psk in psk_files: + shutil.copy2(psk, f"{self.mountpoint}/var/lib/iwd/{os.path.basename(psk)}") + + # Copy (if any) systemd-networkd config files + if (netconfigurations := glob.glob('/etc/systemd/network/*')): + if not os.path.isdir(f"{self.mountpoint}/etc/systemd/network/"): + os.makedirs(f"{self.mountpoint}/etc/systemd/network/") + + for netconf_file in netconfigurations: + shutil.copy2(netconf_file, f"{self.mountpoint}/etc/systemd/network/{os.path.basename(netconf_file)}") + + return True + def minimal_installation(self): ## Add nessecary packages if encrypting the drive ## (encrypted partitions default to btrfs for now, so we need btrfs-progs) @@ -220,6 +255,12 @@ class Installer(): sys_command(f'/usr/bin/arch-chroot {self.mountpoint} mkinitcpio -p linux') self.helper_flags['base'] = True + + # Run registered post-install hooks + for function in self.post_base_install: + self.log(f"Running post-installation hook: {function}", level=LOG_LEVELS.Info) + function(self) + return True def add_bootloader(self, bootloader='systemd-bootctl'): -- cgit v1.2.3-70-g09d2