Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib
diff options
context:
space:
mode:
authorDaniel Girtler <girtler.daniel@gmail.com>2024-03-08 00:43:16 +1100
committerGitHub <noreply@github.com>2024-03-07 14:43:16 +0100
commitf927fb6e6a17123c05c6595bbdb45ed771596ab9 (patch)
tree9f858daed9ff66e1790b87bb3449a12ffa57d560 /archinstall/lib
parent21dd295259e26580faa259dfe32d8e9554ae8933 (diff)
Fix 2307 - Custom mirrors (#2350)
* Fix 2307 - Custom mirrors * Update
Diffstat (limited to 'archinstall/lib')
-rw-r--r--archinstall/lib/installer.py41
-rw-r--r--archinstall/lib/mirrors.py51
2 files changed, 57 insertions, 35 deletions
diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py
index 443e2b90..8a2dde5f 100644
--- a/archinstall/lib/installer.py
+++ b/archinstall/lib/installer.py
@@ -15,7 +15,7 @@ from .hardware import SysInfo
from .locale import LocaleConfiguration
from .locale import verify_keyboard_layout, verify_x11_keyboard_layout
from .luks import Luks2
-from .mirrors import use_mirrors, MirrorConfiguration, add_custom_mirrors
+from .mirrors import MirrorConfiguration
from .models.bootloader import Bootloader
from .models.network_configuration import Nic
from .models.users import User
@@ -318,17 +318,44 @@ class Installer:
def post_install_check(self, *args: str, **kwargs: str) -> List[str]:
return [step for step, flag in self.helper_flags.items() if flag is False]
- def set_mirrors(self, mirror_config: MirrorConfiguration):
+ def set_mirrors(self, mirror_config: MirrorConfiguration, on_target: bool = False):
+ """
+ Set the mirror configuration for the installation.
+
+ :param mirror_config: The mirror configuration to use.
+ :type mirror_config: MirrorConfiguration
+
+ :on_target: Whether to set the mirrors on the target system or the live system.
+ :param on_target: bool
+ """
+ debug('Setting mirrors')
+
for plugin in plugins.values():
if hasattr(plugin, 'on_mirrors'):
if result := plugin.on_mirrors(mirror_config):
mirror_config = result
- destination = f'{self.target}/etc/pacman.d/mirrorlist'
- if mirror_config.mirror_regions:
- use_mirrors(mirror_config.mirror_regions, destination)
- if mirror_config.custom_mirrors:
- add_custom_mirrors(mirror_config.custom_mirrors)
+ if on_target:
+ local_pacman_conf = Path(f'{self.target}/etc/pacman.conf')
+ local_mirrorlist_conf = Path(f'{self.target}/etc/pacman.d/mirrorlist')
+ else:
+ local_pacman_conf = Path('/etc/pacman.conf')
+ local_mirrorlist_conf = Path('/etc/pacman.d/mirrorlist')
+
+ mirrorlist_config = mirror_config.mirrorlist_config()
+ pacman_config = mirror_config.pacman_config()
+
+ if pacman_config:
+ debug(f'Pacman config: {pacman_config}')
+
+ with local_pacman_conf.open('a') as fp:
+ fp.write(pacman_config)
+
+ if mirrorlist_config:
+ debug(f'Mirrorlist: {mirrorlist_config}')
+
+ with local_mirrorlist_conf.open('a') as fp:
+ fp.write(mirrorlist_config)
def genfstab(self, flags: str = '-pU'):
fstab_path = self.target / "etc" / "fstab"
diff --git a/archinstall/lib/mirrors.py b/archinstall/lib/mirrors.py
index 74cdd0aa..61f3c568 100644
--- a/archinstall/lib/mirrors.py
+++ b/archinstall/lib/mirrors.py
@@ -5,7 +5,7 @@ from typing import Dict, Any, List, Optional, TYPE_CHECKING
from .menu import AbstractSubMenu, Selector, MenuSelectionType, Menu, ListManager, TextInput
from .networking import fetch_data_from_url
-from .output import info, warn, FormattedOutput
+from .output import warn, FormattedOutput
from .storage import storage
if TYPE_CHECKING:
@@ -77,6 +77,28 @@ class MirrorConfiguration:
'custom_mirrors': [c.json() for c in self.custom_mirrors]
}
+ def mirrorlist_config(self) -> str:
+ config = ''
+
+ for region, mirrors in self.mirror_regions.items():
+ for mirror in mirrors:
+ config += f'\n\n## {region}\nServer = {mirror}\n'
+
+ for cm in self.custom_mirrors:
+ config += f'\n\n## {cm.name}\nServer = {cm.url}\n'
+
+ return config
+
+ def pacman_config(self) -> str:
+ config = ''
+
+ for mirror in self.custom_mirrors:
+ config += f'\n\n[{mirror.name}]\n'
+ config += f'SigLevel = {mirror.sign_check.value} {mirror.sign_option.value}\n'
+ config += f'Server = {mirror.url}\n'
+
+ return config
+
@classmethod
def parse_args(cls, args: Dict[str, Any]) -> 'MirrorConfiguration':
config = MirrorConfiguration()
@@ -273,33 +295,6 @@ def select_custom_mirror(prompt: str = '', preset: List[CustomMirror] = []):
return custom_mirrors
-def add_custom_mirrors(mirrors: List[CustomMirror]):
- """
- This will append custom mirror definitions in pacman.conf
-
- :param mirrors: A list of custom mirrors
- :type mirrors: List[CustomMirror]
- """
- with open('/etc/pacman.conf', 'a') as pacman:
- for mirror in mirrors:
- pacman.write(f"\n\n[{mirror.name}]\n")
- pacman.write(f"SigLevel = {mirror.sign_check.value} {mirror.sign_option.value}\n")
- pacman.write(f"Server = {mirror.url}\n")
-
-
-def use_mirrors(
- regions: Dict[str, List[str]],
- destination: str = '/etc/pacman.d/mirrorlist'
-):
- with open(destination, 'w') as fp:
- for region, mirrors in regions.items():
- for mirror in mirrors:
- fp.write(f'## {region}\n')
- fp.write(f'Server = {mirror}\n')
-
- info(f'A new package mirror-list has been created: {destination}')
-
-
def _parse_mirror_list(mirrorlist: str) -> Dict[str, List[str]]:
file_content = mirrorlist.split('\n')
file_content = list(filter(lambda x: x, file_content)) # filter out empty lines