|
1 | | -"""Arch Linux installer - guided, templates etc.""" |
| 1 | +from .lib.plugins import plugin |
2 | 2 |
|
3 | | -import importlib |
4 | | -import os |
5 | | -import sys |
6 | | -import time |
7 | | -import traceback |
8 | | - |
9 | | -from archinstall.lib.args import arch_config_handler |
10 | | -from archinstall.lib.disk.utils import disk_layouts |
11 | | -from archinstall.lib.general import running_from_host |
12 | | -from archinstall.lib.network.wifi_handler import wifi_handler |
13 | | -from archinstall.lib.networking import ping |
14 | | -from archinstall.lib.packages.packages import check_version_upgrade |
15 | | - |
16 | | -from .lib.hardware import SysInfo |
17 | | -from .lib.output import FormattedOutput, debug, error, info, log, warn |
18 | | -from .lib.pacman import Pacman |
19 | | -from .lib.plugins import load_plugin, plugins |
20 | | -from .lib.translationhandler import Language, tr, translation_handler |
21 | | - |
22 | | - |
23 | | -# @archinstall.plugin decorator hook to programmatically add |
24 | | -# plugins in runtime. Useful in profiles_bck and other things. |
25 | | -def plugin(f, *args, **kwargs) -> None: # type: ignore[no-untyped-def] |
26 | | - plugins[f.__name__] = f |
27 | | - |
28 | | - |
29 | | -def _log_sys_info() -> None: |
30 | | - # Log various information about hardware before starting the installation. This might assist in troubleshooting |
31 | | - debug(f'Hardware model detected: {SysInfo.sys_vendor()} {SysInfo.product_name()}; UEFI mode: {SysInfo.has_uefi()}') |
32 | | - debug(f'Processor model detected: {SysInfo.cpu_model()}') |
33 | | - debug(f'Memory statistics: {SysInfo.mem_available()} available out of {SysInfo.mem_total()} total installed') |
34 | | - debug(f'Virtualization detected: {SysInfo.virtualization()}; is VM: {SysInfo.is_vm()}') |
35 | | - debug(f'Graphics devices detected: {SysInfo._graphics_devices().keys()}') |
36 | | - |
37 | | - # For support reasons, we'll log the disk layout pre installation to match against post-installation layout |
38 | | - debug(f'Disk states before installing:\n{disk_layouts()}') |
39 | | - |
40 | | - |
41 | | -def _check_online() -> None: |
42 | | - try: |
43 | | - ping('1.1.1.1') |
44 | | - except OSError as ex: |
45 | | - if 'Network is unreachable' in str(ex): |
46 | | - if not arch_config_handler.args.skip_wifi_check: |
47 | | - success = not wifi_handler.setup() |
48 | | - if not success: |
49 | | - sys.exit(0) |
50 | | - |
51 | | - |
52 | | -def _fetch_arch_db() -> None: |
53 | | - info('Fetching Arch Linux package database...') |
54 | | - try: |
55 | | - Pacman.run('-Sy') |
56 | | - except Exception as e: |
57 | | - error('Failed to sync Arch Linux package database.') |
58 | | - if 'could not resolve host' in str(e).lower(): |
59 | | - error('Most likely due to a missing network connection or DNS issue.') |
60 | | - |
61 | | - error('Run archinstall --debug and check /var/log/archinstall/install.log for details.') |
62 | | - |
63 | | - debug(f'Failed to sync Arch Linux package database: {e}') |
64 | | - sys.exit(1) |
65 | | - |
66 | | - |
67 | | -def main() -> int: |
68 | | - """ |
69 | | - This can either be run as the compiled and installed application: python setup.py install |
70 | | - OR straight as a module: python -m archinstall |
71 | | - In any case we will be attempting to load the provided script to be run from the scripts/ folder |
72 | | - """ |
73 | | - if '--help' in sys.argv or '-h' in sys.argv: |
74 | | - arch_config_handler.print_help() |
75 | | - return 0 |
76 | | - |
77 | | - if os.getuid() != 0: |
78 | | - print(tr('Archinstall requires root privileges to run. See --help for more.')) |
79 | | - return 1 |
80 | | - |
81 | | - _log_sys_info() |
82 | | - |
83 | | - if not arch_config_handler.args.offline: |
84 | | - _check_online() |
85 | | - _fetch_arch_db() |
86 | | - |
87 | | - if not arch_config_handler.args.skip_version_check: |
88 | | - upgrade = check_version_upgrade() |
89 | | - |
90 | | - if upgrade: |
91 | | - text = tr('New version available') + f': {upgrade}' |
92 | | - info(text) |
93 | | - time.sleep(3) |
94 | | - |
95 | | - if running_from_host(): |
96 | | - # log which mode we are using |
97 | | - debug('Running from Host (H2T Mode)...') |
98 | | - else: |
99 | | - debug('Running from ISO (Live Mode)...') |
100 | | - |
101 | | - script = arch_config_handler.get_script() |
102 | | - |
103 | | - mod_name = f'archinstall.scripts.{script}' |
104 | | - # by loading the module we'll automatically run the script |
105 | | - importlib.import_module(mod_name) |
106 | | - |
107 | | - return 0 |
108 | | - |
109 | | - |
110 | | -def run_as_a_module() -> None: |
111 | | - rc = 0 |
112 | | - exc = None |
113 | | - |
114 | | - try: |
115 | | - rc = main() |
116 | | - except Exception as e: |
117 | | - exc = e |
118 | | - finally: |
119 | | - if exc: |
120 | | - err = ''.join(traceback.format_exception(exc)) |
121 | | - error(err) |
122 | | - |
123 | | - text = ( |
124 | | - 'Archinstall experienced the above error. If you think this is a bug, please report it to\n' |
125 | | - 'https://github.com/archlinux/archinstall and include the log file "/var/log/archinstall/install.log".\n\n' |
126 | | - "Hint: To extract the log from a live ISO \ncurl -F 'file=@/var/log/archinstall/install.log' https://0x0.st\n" |
127 | | - ) |
128 | | - |
129 | | - warn(text) |
130 | | - rc = 1 |
131 | | - |
132 | | - sys.exit(rc) |
133 | | - |
134 | | - |
135 | | -__all__ = [ |
136 | | - 'FormattedOutput', |
137 | | - 'Language', |
138 | | - 'Pacman', |
139 | | - 'SysInfo', |
140 | | - 'arch_config_handler', |
141 | | - 'debug', |
142 | | - 'disk_layouts', |
143 | | - 'error', |
144 | | - 'info', |
145 | | - 'load_plugin', |
146 | | - 'log', |
147 | | - 'plugin', |
148 | | - 'translation_handler', |
149 | | - 'warn', |
150 | | -] |
| 3 | +__all__ = ['plugin'] |
0 commit comments