Skip to content

Commit

Permalink
Fixes for prev PR (archlinux#2175)
Browse files Browse the repository at this point in the history
* Fixes for prev PR

* Update

---------

Co-authored-by: Daniel Girtler <[email protected]>
  • Loading branch information
svartkanin and svartkanin authored Oct 18, 2023
1 parent 8117c0e commit ce9828c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 56 deletions.
21 changes: 18 additions & 3 deletions archinstall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def define_arguments():
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("--skip-version-check", action="store_true",
help="Skip the version check when running archinstall")


def parse_unspecified_argument_list(unknowns: list, multiple: bool = False, err: bool = False) -> dict:
Expand Down Expand Up @@ -280,8 +282,20 @@ def plugin(f, *args, **kwargs):

def _check_new_version():
info("Checking version...")
Pacman.run("-Sy")
upgrade = Pacman.run("-Qu archinstall").decode()

try:
Pacman.run("-Sy")
except Exception as e:
debug(f'Failed to perform version check: {e}')
info(f'Arch Linux mirrors are not reachable. Please check your internet connection')
exit(1)

upgrade = None

try:
upgrade = Pacman.run("-Qu archinstall").decode()
except Exception as e:
debug(f'Failed determine pacman version: {e}')

if upgrade:
text = f'New version available: {upgrade}'
Expand All @@ -295,7 +309,8 @@ def main():
OR straight as a module: python -m archinstall
In any case we will be attempting to load the provided script to be run from the scripts/ folder
"""
_check_new_version()
if not arguments.get('skip_version_check', False):
_check_new_version()

script = arguments.get('script', None)

Expand Down
16 changes: 8 additions & 8 deletions archinstall/lib/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@
from .general import SysCommandWorker


class RequirementError(BaseException):
class RequirementError(Exception):
pass


class DiskError(BaseException):
class DiskError(Exception):
pass


class UnknownFilesystemFormat(BaseException):
class UnknownFilesystemFormat(Exception):
pass


class SysCallError(BaseException):
class SysCallError(Exception):
def __init__(self, message :str, exit_code :Optional[int] = None, worker :Optional['SysCommandWorker'] = None) -> None:
super(SysCallError, self).__init__(message)
self.message = message
self.exit_code = exit_code
self.worker = worker


class HardwareIncompatibilityError(BaseException):
class HardwareIncompatibilityError(Exception):
pass


class ServiceException(BaseException):
class ServiceException(Exception):
pass


class PackageError(BaseException):
class PackageError(Exception):
pass


class Deprecated(BaseException):
class Deprecated(Exception):
pass
15 changes: 1 addition & 14 deletions archinstall/lib/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from urllib.request import urlopen

from .exceptions import SysCallError
from .output import error, info, debug
from .output import error, info
from .pacman import Pacman


Expand All @@ -32,19 +32,6 @@ def list_interfaces(skip_loopback :bool = True) -> Dict[str, str]:
return interfaces


def check_mirror_reachable() -> bool:
info("Testing connectivity to the Arch Linux mirrors...")
try:
Pacman.run("-Sy")
return True
except SysCallError as err:
if os.geteuid() != 0:
error("check_mirror_reachable() uses 'pacman -Sy' which requires root.")
debug(f'exit_code: {err.exit_code}, Error: {err.message}')

return False


def update_keyring() -> bool:
info("Updating archlinux-keyring ...")
try:
Expand Down
7 changes: 0 additions & 7 deletions archinstall/scripts/guided.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from pathlib import Path
from typing import Any, TYPE_CHECKING, Optional

Expand All @@ -15,7 +14,6 @@
from archinstall.lib.models import AudioConfiguration
from archinstall.lib.models.bootloader import Bootloader
from archinstall.lib.models.network_configuration import NetworkConfiguration
from archinstall.lib.networking import check_mirror_reachable
from archinstall.lib.profile.profiles_handler import profile_handler

if TYPE_CHECKING:
Expand Down Expand Up @@ -232,11 +230,6 @@ def perform_installation(mountpoint: Path):
debug(f"Disk states after installing: {disk.disk_layouts()}")


if archinstall.arguments.get('skip-mirror-check', False) is False and check_mirror_reachable() is False:
log_file = os.path.join(archinstall.storage.get('LOG_PATH', None), archinstall.storage.get('LOG_FILE', None))
info(f"Arch Linux mirrors are not reachable. Please check your internet connection and the log file '{log_file}'.")
exit(1)

if not archinstall.arguments.get('silent'):
ask_user_questions()

Expand Down
13 changes: 1 addition & 12 deletions archinstall/scripts/only_hd.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import os
from pathlib import Path

import archinstall
from archinstall import info, debug
from archinstall import debug
from archinstall.lib.installer import Installer
from archinstall.lib.configuration import ConfigurationOutput
from archinstall.lib import disk
from archinstall.lib.networking import check_mirror_reachable

if archinstall.arguments.get('help'):
print("See `man archinstall` for help.")
exit(0)


def ask_user_questions():
Expand Down Expand Up @@ -58,11 +52,6 @@ def perform_installation(mountpoint: Path):
debug(f"Disk states after installing: {disk.disk_layouts()}")


if archinstall.arguments.get('skip-mirror-check', False) is False and check_mirror_reachable() is False:
log_file = os.path.join(archinstall.storage.get('LOG_PATH', None), archinstall.storage.get('LOG_FILE', None))
info(f"Arch Linux mirrors are not reachable. Please check your internet connection and the log file '{log_file}'")
exit(1)

if not archinstall.arguments.get('silent'):
ask_user_questions()

Expand Down
12 changes: 0 additions & 12 deletions archinstall/scripts/swiss.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from enum import Enum
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, Optional
Expand All @@ -10,7 +9,6 @@
from archinstall.lib import disk
from archinstall.lib import locale
from archinstall.lib.models import AudioConfiguration
from archinstall.lib.networking import check_mirror_reachable
from archinstall.lib.profile.profiles_handler import profile_handler
from archinstall.lib import menu
from archinstall.lib.global_menu import GlobalMenu
Expand All @@ -21,11 +19,6 @@
_: Any


if archinstall.arguments.get('help'):
print("See `man archinstall` for help.")
exit(0)


class ExecutionMode(Enum):
Full = 'full'
Lineal = 'lineal'
Expand Down Expand Up @@ -290,11 +283,6 @@ def perform_installation(mountpoint: Path, exec_mode: ExecutionMode):
debug(f"Disk states after installing: {disk.disk_layouts()}")


if not check_mirror_reachable():
log_file = os.path.join(archinstall.storage.get('LOG_PATH', None), archinstall.storage.get('LOG_FILE', None))
info(f"Arch Linux mirrors are not reachable. Please check your internet connection and the log file '{log_file}'")
exit(1)

param_mode = archinstall.arguments.get('mode', ExecutionMode.Full.value).lower()

try:
Expand Down

0 comments on commit ce9828c

Please sign in to comment.