|
1 | | -import glob |
2 | 1 | import os |
3 | 2 | import platform |
4 | 3 | import re |
@@ -763,46 +762,46 @@ def configure_nic(self, nic: Nic) -> None: |
763 | 762 |
|
764 | 763 | def copy_iso_network_config(self, enable_services: bool = False) -> bool: |
765 | 764 | # Copy (if any) iwd password and config files |
766 | | - if os.path.isdir('/var/lib/iwd/'): |
767 | | - if psk_files := glob.glob('/var/lib/iwd/*.psk'): |
768 | | - if not os.path.isdir(f'{self.target}/var/lib/iwd'): |
769 | | - os.makedirs(f'{self.target}/var/lib/iwd') |
770 | | - |
771 | | - if enable_services: |
772 | | - # If we haven't installed the base yet (function called pre-maturely) |
773 | | - if self._helper_flags.get('base', False) is False: |
774 | | - self._base_packages.append('iwd') |
775 | | - |
776 | | - # This function will be called after minimal_installation() |
777 | | - # as a hook for post-installs. This hook is only needed if |
778 | | - # base is not installed yet. |
779 | | - def post_install_enable_iwd_service(*args: str, **kwargs: str) -> None: |
780 | | - self.enable_service('iwd') |
781 | | - |
782 | | - self.post_base_install.append(post_install_enable_iwd_service) |
783 | | - # Otherwise, we can go ahead and add the required package |
784 | | - # and enable it's service: |
785 | | - else: |
786 | | - self.pacman.strap('iwd') |
| 765 | + iwd_dir = LPath('/var/lib/iwd') |
| 766 | + if any(psk_files := iwd_dir.glob('*.psk')): |
| 767 | + iwd_target = self.target / iwd_dir.relative_to_root() |
| 768 | + iwd_target.mkdir(parents=True, exist_ok=True) |
| 769 | + |
| 770 | + for psk in psk_files: |
| 771 | + psk.copy(iwd_target / psk.name, preserve_metadata=True) |
| 772 | + |
| 773 | + if enable_services: |
| 774 | + # If we haven't installed the base yet (function called pre-maturely) |
| 775 | + if self._helper_flags.get('base', False) is False: |
| 776 | + self._base_packages.append('iwd') |
| 777 | + |
| 778 | + # This function will be called after minimal_installation() |
| 779 | + # as a hook for post-installs. This hook is only needed if |
| 780 | + # base is not installed yet. |
| 781 | + def post_install_enable_iwd_service(*args: str, **kwargs: str) -> None: |
787 | 782 | self.enable_service('iwd') |
788 | 783 |
|
789 | | - for psk in psk_files: |
790 | | - shutil.copy2(psk, f'{self.target}/var/lib/iwd/{os.path.basename(psk)}') |
| 784 | + self.post_base_install.append(post_install_enable_iwd_service) |
| 785 | + # Otherwise, we can go ahead and add the required package |
| 786 | + # and enable it's service: |
| 787 | + else: |
| 788 | + self.pacman.strap('iwd') |
| 789 | + self.enable_service('iwd') |
791 | 790 |
|
792 | 791 | # Enable systemd-resolved by (forcefully) setting a symlink |
793 | 792 | # For further details see https://wiki.archlinux.org/title/Systemd-resolved#DNS |
794 | | - resolv_config_path = Path(f'{self.target}/etc/resolv.conf') |
795 | | - if resolv_config_path.exists(): |
796 | | - os.unlink(resolv_config_path) |
797 | | - os.symlink('/run/systemd/resolve/stub-resolv.conf', resolv_config_path) |
| 793 | + resolv_config_path = self.target / '/etc/resolv.conf' |
| 794 | + resolv_config_path.unlink(missing_ok=True) |
| 795 | + resolv_config_path.symlink_to('/run/systemd/resolve/stub-resolv.conf') |
798 | 796 |
|
799 | 797 | # Copy (if any) systemd-networkd config files |
800 | | - if netconfigurations := glob.glob('/etc/systemd/network/*'): |
801 | | - if not os.path.isdir(f'{self.target}/etc/systemd/network/'): |
802 | | - os.makedirs(f'{self.target}/etc/systemd/network/') |
| 798 | + network_dir = LPath('/etc/systemd/network') |
| 799 | + if any(netconfigurations := network_dir.glob('*')): |
| 800 | + network_target = self.target / network_dir.relative_to_root() |
| 801 | + network_target.mkdir(parents=True, exist_ok=True) |
803 | 802 |
|
804 | 803 | for netconf_file in netconfigurations: |
805 | | - shutil.copy2(netconf_file, f'{self.target}/etc/systemd/network/{os.path.basename(netconf_file)}') |
| 804 | + netconf_file.copy(network_target / netconf_file.name, preserve_metadata=True) |
806 | 805 |
|
807 | 806 | if enable_services: |
808 | 807 | # If we haven't installed the base yet (function called pre-maturely) |
|
0 commit comments