Added more offline functionality, such as skipping package search (#1296)

* Added more offline functionality, such as skipping package search

* Disabled list_mirrors() from going online if --offline is given. Defaults to /etc/pacman.d/mirrorlist instead.

* Forgot import of pathlib

* Made list_mirrors() open /etc/pacman.d/mirrorlist in byte mode to better emulate the result of urllib response reading.

* Forgot variable declaration

* Made list_mirrors include activated server definitions
This commit is contained in:
Anton Hvornum 2022-06-02 13:32:42 +02:00 committed by GitHub
parent c2be07e7dc
commit 7943dd8236
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 25 deletions

View File

@ -81,6 +81,8 @@ def define_arguments():
parser.add_argument("--script", default="guided", nargs="?", help="Script to run for installation", type=str) parser.add_argument("--script", default="guided", nargs="?", help="Script to run for installation", type=str)
parser.add_argument("--mount-point","--mount_point", nargs="?", type=str, help="Define an alternate mount point for installation") parser.add_argument("--mount-point","--mount_point", nargs="?", type=str, help="Define an alternate mount point for installation")
parser.add_argument("--debug", action="store_true", default=False, help="Adds debug info into the log") parser.add_argument("--debug", action="store_true", default=False, help="Adds debug info into the log")
parser.add_argument("--offline", action="store_true", default=False, help="Disabled online upstream services such as package search and key-ring auto update.")
parser.add_argument("--no-pkg-lookups", action="store_true", default=False, help="Disabled package validation specifically prior to starting installation.")
parser.add_argument("--plugin", nargs="?", type=str) parser.add_argument("--plugin", nargs="?", type=str)
def parse_unspecified_argument_list(unknowns :list, multiple :bool = False, error :bool = False) -> dict: def parse_unspecified_argument_list(unknowns :list, multiple :bool = False, error :bool = False) -> dict:
@ -172,6 +174,7 @@ def get_arguments() -> Dict[str, Any]:
# avoiding a compatibility issue # avoiding a compatibility issue
if 'dry-run' in config: if 'dry-run' in config:
del config['dry-run'] del config['dry-run']
return config return config
def load_config(): def load_config():

View File

@ -1,10 +1,12 @@
import logging import logging
import pathlib
import urllib.error import urllib.error
import urllib.request import urllib.request
from typing import Union, Mapping, Iterable, Dict, Any, List from typing import Union, Mapping, Iterable, Dict, Any, List
from .general import SysCommand from .general import SysCommand
from .output import log from .output import log
from .storage import storage
def sort_mirrorlist(raw_data :bytes, sort_order=["https", "http"]) -> bytes: def sort_mirrorlist(raw_data :bytes, sort_order=["https", "http"]) -> bytes:
""" """
@ -144,16 +146,22 @@ def re_rank_mirrors(
def list_mirrors(sort_order :List[str] = ["https", "http"]) -> Dict[str, Any]: def list_mirrors(sort_order :List[str] = ["https", "http"]) -> Dict[str, Any]:
url = "https://archlinux.org/mirrorlist/?protocol=https&protocol=http&ip_version=4&ip_version=6&use_mirror_status=on"
regions = {} regions = {}
try: if storage['arguments']['offline']:
response = urllib.request.urlopen(url) with pathlib.Path('/etc/pacman.d/mirrorlist').open('rb') as fh:
except urllib.error.URLError as err: mirrorlist = fh.read()
log(f'Could not fetch an active mirror-list: {err}', level=logging.WARNING, fg="orange") else:
return regions url = "https://archlinux.org/mirrorlist/?protocol=https&protocol=http&ip_version=4&ip_version=6&use_mirror_status=on"
try:
response = urllib.request.urlopen(url)
except urllib.error.URLError as err:
log(f'Could not fetch an active mirror-list: {err}', level=logging.WARNING, fg="orange")
return regions
mirrorlist = response.read()
mirrorlist = response.read()
if sort_order: if sort_order:
mirrorlist = sort_mirrorlist(mirrorlist, sort_order=sort_order) mirrorlist = sort_mirrorlist(mirrorlist, sort_order=sort_order)
@ -170,5 +178,10 @@ def list_mirrors(sort_order :List[str] = ["https", "http"]) -> Dict[str, Any]:
url = line.lstrip('#Server = ') url = line.lstrip('#Server = ')
regions[region][url] = True regions[region][url] = True
elif line.startswith('Server = '):
regions.setdefault(region, {})
url = line.lstrip('Server = ')
regions[region][url] = True
return regions return regions

View File

@ -3,8 +3,6 @@ from __future__ import annotations
import logging import logging
from typing import List, Any, Optional, Dict, TYPE_CHECKING from typing import List, Any, Optional, Dict, TYPE_CHECKING
import archinstall
from ..menu.menu import MenuSelectionType from ..menu.menu import MenuSelectionType
from ..menu.text_input import TextInput from ..menu.text_input import TextInput
@ -17,6 +15,8 @@ from ..mirrors import list_mirrors
from ..translation import Translation from ..translation import Translation
from ..packages.packages import validate_package_list from ..packages.packages import validate_package_list
from ..storage import storage
if TYPE_CHECKING: if TYPE_CHECKING:
_: Any _: Any
@ -155,11 +155,11 @@ def select_profile(preset) -> Optional[Profile]:
case MenuSelectionType.Selection: case MenuSelectionType.Selection:
return options[selection.value] if selection.value is not None else None return options[selection.value] if selection.value is not None else None
case MenuSelectionType.Ctrl_c: case MenuSelectionType.Ctrl_c:
archinstall.storage['profile_minimal'] = False storage['profile_minimal'] = False
archinstall.storage['_selected_servers'] = [] storage['_selected_servers'] = []
archinstall.storage['_desktop_profile'] = None storage['_desktop_profile'] = None
archinstall.arguments['desktop-environment'] = None storage['arguments']['desktop-environment'] = None
archinstall.arguments['gfx_driver_packages'] = None storage['arguments']['gfx_driver_packages'] = None
return None return None
case MenuSelectionType.Esc: case MenuSelectionType.Esc:
return None return None
@ -178,17 +178,18 @@ def ask_additional_packages_to_install(pre_set_packages: List[str] = []) -> List
pre_set_packages = pre_set_packages if pre_set_packages else [] pre_set_packages = pre_set_packages if pre_set_packages else []
packages = read_packages(pre_set_packages) packages = read_packages(pre_set_packages)
while True: if not storage['arguments']['offline'] and not storage['arguments']['no_pkg_lookups']:
if len(packages): while True:
# Verify packages that were given if len(packages):
print(_("Verifying that additional packages exist (this might take a few seconds)")) # Verify packages that were given
valid, invalid = validate_package_list(packages) print(_("Verifying that additional packages exist (this might take a few seconds)"))
valid, invalid = validate_package_list(packages)
if invalid: if invalid:
log(f"Some packages could not be found in the repository: {invalid}", level=logging.WARNING, fg='red') log(f"Some packages could not be found in the repository: {invalid}", level=logging.WARNING, fg='red')
packages = read_packages(valid) packages = read_packages(valid)
continue continue
break break
return packages return packages

View File

@ -274,7 +274,7 @@ if not (archinstall.check_mirror_reachable() or archinstall.arguments.get('skip-
archinstall.log(f"Arch Linux mirrors are not reachable. Please check your internet connection and the log file '{log_file}'.", level=logging.INFO, fg="red") archinstall.log(f"Arch Linux mirrors are not reachable. Please check your internet connection and the log file '{log_file}'.", level=logging.INFO, fg="red")
exit(1) exit(1)
if not archinstall.arguments.get('offline', False): if not archinstall.arguments['offline']:
latest_version_archlinux_keyring = max([k.pkg_version for k in archinstall.find_package('archlinux-keyring')]) latest_version_archlinux_keyring = max([k.pkg_version for k in archinstall.find_package('archlinux-keyring')])
# If we want to check for keyring updates # If we want to check for keyring updates