Skip to content

Commit 516b713

Browse files
committed
Refactor copy_iso_network_config()
1 parent eda9ee3 commit 516b713

1 file changed

Lines changed: 31 additions & 32 deletions

File tree

archinstall/lib/installer.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import glob
21
import os
32
import platform
43
import re
@@ -763,46 +762,46 @@ def configure_nic(self, nic: Nic) -> None:
763762

764763
def copy_iso_network_config(self, enable_services: bool = False) -> bool:
765764
# 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:
787782
self.enable_service('iwd')
788783

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')
791790

792791
# Enable systemd-resolved by (forcefully) setting a symlink
793792
# 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')
798796

799797
# 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)
803802

804803
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)
806805

807806
if enable_services:
808807
# If we haven't installed the base yet (function called pre-maturely)

0 commit comments

Comments
 (0)