Refactor copy_iso_network_config() (#4394)

This commit is contained in:
codefiles 2026-04-08 02:13:14 -04:00 committed by GitHub
parent a92cd50aec
commit 3ef0848ffe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 28 additions and 29 deletions

View File

@ -1,4 +1,3 @@
import glob
import os import os
import platform import platform
import re import re
@ -763,46 +762,46 @@ class Installer:
def copy_iso_network_config(self, enable_services: bool = False) -> bool: def copy_iso_network_config(self, enable_services: bool = False) -> bool:
# Copy (if any) iwd password and config files # Copy (if any) iwd password and config files
if os.path.isdir('/var/lib/iwd/'): iwd_dir = LPath('/var/lib/iwd')
if psk_files := glob.glob('/var/lib/iwd/*.psk'): if psk_files := list(iwd_dir.glob('*.psk')):
if not os.path.isdir(f'{self.target}/var/lib/iwd'): iwd_target = self.target / iwd_dir.relative_to_root()
os.makedirs(f'{self.target}/var/lib/iwd') iwd_target.mkdir(parents=True, exist_ok=True)
if enable_services: for psk in psk_files:
# If we haven't installed the base yet (function called pre-maturely) psk.copy(iwd_target / psk.name, preserve_metadata=True)
if self._helper_flags.get('base', False) is False:
self._base_packages.append('iwd')
# This function will be called after minimal_installation() if enable_services:
# as a hook for post-installs. This hook is only needed if # If we haven't installed the base yet (function called pre-maturely)
# base is not installed yet. if self._helper_flags.get('base', False) is False:
def post_install_enable_iwd_service(*args: str, **kwargs: str) -> None: self._base_packages.append('iwd')
self.enable_service('iwd')
self.post_base_install.append(post_install_enable_iwd_service) # This function will be called after minimal_installation()
# Otherwise, we can go ahead and add the required package # as a hook for post-installs. This hook is only needed if
# and enable it's service: # base is not installed yet.
else: def post_install_enable_iwd_service(*args: str, **kwargs: str) -> None:
self.pacman.strap('iwd')
self.enable_service('iwd') self.enable_service('iwd')
for psk in psk_files: self.post_base_install.append(post_install_enable_iwd_service)
shutil.copy2(psk, f'{self.target}/var/lib/iwd/{os.path.basename(psk)}') # Otherwise, we can go ahead and add the required package
# and enable it's service:
else:
self.pacman.strap('iwd')
self.enable_service('iwd')
# Enable systemd-resolved by (forcefully) setting a symlink # Enable systemd-resolved by (forcefully) setting a symlink
# For further details see https://wiki.archlinux.org/title/Systemd-resolved#DNS # For further details see https://wiki.archlinux.org/title/Systemd-resolved#DNS
resolv_config_path = Path(f'{self.target}/etc/resolv.conf') resolv_config_path = self.target / 'etc/resolv.conf'
if resolv_config_path.exists(): resolv_config_path.unlink(missing_ok=True)
os.unlink(resolv_config_path) resolv_config_path.symlink_to('/run/systemd/resolve/stub-resolv.conf')
os.symlink('/run/systemd/resolve/stub-resolv.conf', resolv_config_path)
# Copy (if any) systemd-networkd config files # Copy (if any) systemd-networkd config files
if netconfigurations := glob.glob('/etc/systemd/network/*'): network_dir = LPath('/etc/systemd/network')
if not os.path.isdir(f'{self.target}/etc/systemd/network/'): if netconfigurations := list(network_dir.glob('*')):
os.makedirs(f'{self.target}/etc/systemd/network/') network_target = self.target / network_dir.relative_to_root()
network_target.mkdir(parents=True, exist_ok=True)
for netconf_file in netconfigurations: for netconf_file in netconfigurations:
shutil.copy2(netconf_file, f'{self.target}/etc/systemd/network/{os.path.basename(netconf_file)}') netconf_file.copy(network_target / netconf_file.name, preserve_metadata=True)
if enable_services: if enable_services:
# If we haven't installed the base yet (function called pre-maturely) # If we haven't installed the base yet (function called pre-maturely)