Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
svartkanin committed Jan 28, 2024
1 parent b7ba7e2 commit 25d3907
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 26 deletions.
41 changes: 29 additions & 12 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,27 +318,44 @@ def add_swapfile(self, size='4G', enable_resume=True, file='/swapfile'):
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_local_mirrors(self, mirror_config: MirrorConfiguration):
local_pacman_conf = Path('/etc/pacman.conf')
def set_mirrors(self, mirror_config: MirrorConfiguration, on_target: bool = False):
"""
Set the mirror configuration for the installation.
if mirror_config.custom_mirrors:
config = mirror_config.custom_mirrors_to_config()
:param mirror_config: The mirror configuration to use.
:type mirror_config: MirrorConfiguration
with local_pacman_conf.open('a') as fp:
fp.write(config)
:on_target: Whether to set the mirrors on the target system or the live system.
:param on_target: bool
"""
debug('Setting mirrors')

def set_target_mirrors(self, mirror_config: MirrorConfiguration):
for plugin in plugins.values():
if hasattr(plugin, 'on_mirrors'):
if result := plugin.on_mirrors(mirror_config):
mirror_config = result

target_mirror_conf = Path(f'{self.target}/etc/pacman.d/mirrorlist')
mirror_list_config = mirror_config.mirror_list_config()
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}')

if mirror_list_config:
with target_mirror_conf.open('a') as fp:
fp.write(mirror_list_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"
Expand Down
13 changes: 5 additions & 8 deletions archinstall/lib/mirrors.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,25 @@ def json(self) -> Dict[str, Any]:
'custom_mirrors': [c.json() for c in self.custom_mirrors]
}

def _server_config(self, name: str, url: str) -> str:
return f'\n\n## {name}\nServer = {url}'

def mirror_list_config(self) -> str:
def mirrorlist_config(self) -> str:
config = ''

for region, mirrors in self.mirror_regions.items():
for mirror in mirrors:
config += self._server_config(region, mirror)
config += f'\n\n## {region}\nServer = {mirror}\n'

for cm in self.custom_mirrors:
config += self._server_config(cm.name, cm.url)
config += f'\n\n## {cm.name}\nServer = {cm.url}\n'

return config

def custom_mirrors_to_config(self) -> str:
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}'
config += f'Server = {mirror.url}\n'

return config

Expand Down
4 changes: 2 additions & 2 deletions archinstall/scripts/guided.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def perform_installation(mountpoint: Path):
installation.generate_key_files()

if mirror_config := archinstall.arguments.get('mirror_config', None):
installation.set_local_mirrors(mirror_config)
installation.set_mirrors(mirror_config, on_target=False)

installation.minimal_installation(
testing=enable_testing,
Expand All @@ -143,7 +143,7 @@ def perform_installation(mountpoint: Path):
)

if mirror_config := archinstall.arguments.get('mirror_config', None):
installation.set_target_mirrors(mirror_config)
installation.set_mirrors(mirror_config, on_target=True)

if archinstall.arguments.get('swap'):
installation.setup_swap('zram')
Expand Down
4 changes: 2 additions & 2 deletions archinstall/scripts/swiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def perform_installation(mountpoint: Path, exec_mode: ExecutionMode):
installation.generate_key_files()

if mirror_config := archinstall.arguments.get('mirror_config', None):
installation.set_local_mirrors(mirror_config)
installation.set_mirrors(mirror_config)

installation.minimal_installation(
testing=enable_testing,
Expand All @@ -198,7 +198,7 @@ def perform_installation(mountpoint: Path, exec_mode: ExecutionMode):
)

if mirror_config := archinstall.arguments.get('mirror_config', None):
installation.set_target_mirrors(mirror_config)
installation.set_mirrors(mirror_config, on_target=True)

if archinstall.arguments.get('swap'):
installation.setup_swap('zram')
Expand Down
4 changes: 2 additions & 2 deletions examples/interactive_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def perform_installation(mountpoint: Path):
installation.generate_key_files()

if mirror_config := archinstall.arguments.get('mirror_config', None):
installation.set_local_mirrors(mirror_config)
installation.set_mirrors(mirror_config)

installation.minimal_installation(
testing=enable_testing,
Expand All @@ -119,7 +119,7 @@ def perform_installation(mountpoint: Path):
)

if mirror_config := archinstall.arguments.get('mirror_config', None):
installation.set_target_mirrors(mirror_config)
installation.set_mirrors(mirror_config, on_target=True)

if archinstall.arguments.get('swap'):
installation.setup_swap('zram')
Expand Down

0 comments on commit 25d3907

Please sign in to comment.