-
-
Notifications
You must be signed in to change notification settings - Fork 690
Move script entry point #4151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
svartkanin
merged 1 commit into
archlinux:master
from
codefiles:move-script-entry-point
Jan 21, 2026
Merged
Move script entry point #4151
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,150 +1,3 @@ | ||
| """Arch Linux installer - guided, templates etc.""" | ||
| from .lib.plugins import plugin | ||
|
|
||
| import importlib | ||
| import os | ||
| import sys | ||
| import time | ||
| import traceback | ||
|
|
||
| from archinstall.lib.args import arch_config_handler | ||
| from archinstall.lib.disk.utils import disk_layouts | ||
| from archinstall.lib.general import running_from_host | ||
| from archinstall.lib.network.wifi_handler import wifi_handler | ||
| from archinstall.lib.networking import ping | ||
| from archinstall.lib.packages.packages import check_version_upgrade | ||
|
|
||
| from .lib.hardware import SysInfo | ||
| from .lib.output import FormattedOutput, debug, error, info, log, warn | ||
| from .lib.pacman import Pacman | ||
| from .lib.plugins import load_plugin, plugins | ||
| from .lib.translationhandler import Language, tr, translation_handler | ||
|
|
||
|
|
||
| # @archinstall.plugin decorator hook to programmatically add | ||
| # plugins in runtime. Useful in profiles_bck and other things. | ||
| def plugin(f, *args, **kwargs) -> None: # type: ignore[no-untyped-def] | ||
| plugins[f.__name__] = f | ||
|
|
||
|
|
||
| def _log_sys_info() -> None: | ||
| # Log various information about hardware before starting the installation. This might assist in troubleshooting | ||
| debug(f'Hardware model detected: {SysInfo.sys_vendor()} {SysInfo.product_name()}; UEFI mode: {SysInfo.has_uefi()}') | ||
| debug(f'Processor model detected: {SysInfo.cpu_model()}') | ||
| debug(f'Memory statistics: {SysInfo.mem_available()} available out of {SysInfo.mem_total()} total installed') | ||
| debug(f'Virtualization detected: {SysInfo.virtualization()}; is VM: {SysInfo.is_vm()}') | ||
| debug(f'Graphics devices detected: {SysInfo._graphics_devices().keys()}') | ||
|
|
||
| # For support reasons, we'll log the disk layout pre installation to match against post-installation layout | ||
| debug(f'Disk states before installing:\n{disk_layouts()}') | ||
|
|
||
|
|
||
| def _check_online() -> None: | ||
| try: | ||
| ping('1.1.1.1') | ||
| except OSError as ex: | ||
| if 'Network is unreachable' in str(ex): | ||
| if not arch_config_handler.args.skip_wifi_check: | ||
| success = not wifi_handler.setup() | ||
| if not success: | ||
| sys.exit(0) | ||
|
|
||
|
|
||
| def _fetch_arch_db() -> None: | ||
| info('Fetching Arch Linux package database...') | ||
| try: | ||
| Pacman.run('-Sy') | ||
| except Exception as e: | ||
| error('Failed to sync Arch Linux package database.') | ||
| if 'could not resolve host' in str(e).lower(): | ||
| error('Most likely due to a missing network connection or DNS issue.') | ||
|
|
||
| error('Run archinstall --debug and check /var/log/archinstall/install.log for details.') | ||
|
|
||
| debug(f'Failed to sync Arch Linux package database: {e}') | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def main() -> int: | ||
| """ | ||
| This can either be run as the compiled and installed application: python setup.py install | ||
| 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 | ||
| """ | ||
| if '--help' in sys.argv or '-h' in sys.argv: | ||
| arch_config_handler.print_help() | ||
| return 0 | ||
|
|
||
| if os.getuid() != 0: | ||
| print(tr('Archinstall requires root privileges to run. See --help for more.')) | ||
| return 1 | ||
|
|
||
| _log_sys_info() | ||
|
|
||
| if not arch_config_handler.args.offline: | ||
| _check_online() | ||
| _fetch_arch_db() | ||
|
|
||
| if not arch_config_handler.args.skip_version_check: | ||
| upgrade = check_version_upgrade() | ||
|
|
||
| if upgrade: | ||
| text = tr('New version available') + f': {upgrade}' | ||
| info(text) | ||
| time.sleep(3) | ||
|
|
||
| if running_from_host(): | ||
| # log which mode we are using | ||
| debug('Running from Host (H2T Mode)...') | ||
| else: | ||
| debug('Running from ISO (Live Mode)...') | ||
|
|
||
| script = arch_config_handler.get_script() | ||
|
|
||
| mod_name = f'archinstall.scripts.{script}' | ||
| # by loading the module we'll automatically run the script | ||
| importlib.import_module(mod_name) | ||
|
|
||
| return 0 | ||
|
|
||
|
|
||
| def run_as_a_module() -> None: | ||
| rc = 0 | ||
| exc = None | ||
|
|
||
| try: | ||
| rc = main() | ||
| except Exception as e: | ||
| exc = e | ||
| finally: | ||
| if exc: | ||
| err = ''.join(traceback.format_exception(exc)) | ||
| error(err) | ||
|
|
||
| text = ( | ||
| 'Archinstall experienced the above error. If you think this is a bug, please report it to\n' | ||
| 'https://github.com/archlinux/archinstall and include the log file "/var/log/archinstall/install.log".\n\n' | ||
| "Hint: To extract the log from a live ISO \ncurl -F 'file=@/var/log/archinstall/install.log' https://0x0.st\n" | ||
| ) | ||
|
|
||
| warn(text) | ||
| rc = 1 | ||
|
|
||
| sys.exit(rc) | ||
|
|
||
|
|
||
| __all__ = [ | ||
| 'FormattedOutput', | ||
| 'Language', | ||
| 'Pacman', | ||
| 'SysInfo', | ||
| 'arch_config_handler', | ||
| 'debug', | ||
| 'disk_layouts', | ||
| 'error', | ||
| 'info', | ||
| 'load_plugin', | ||
| 'log', | ||
| 'plugin', | ||
| 'translation_handler', | ||
| 'warn', | ||
| ] | ||
| __all__ = ['plugin'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import archinstall | ||
| from archinstall.main import main | ||
|
|
||
| if __name__ == '__main__': | ||
| archinstall.run_as_a_module() | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| """Arch Linux installer - guided, templates etc.""" | ||
|
|
||
| import importlib | ||
| import os | ||
| import sys | ||
| import time | ||
| import traceback | ||
|
|
||
| from archinstall.lib.args import arch_config_handler | ||
| from archinstall.lib.disk.utils import disk_layouts | ||
| from archinstall.lib.general import running_from_host | ||
| from archinstall.lib.network.wifi_handler import wifi_handler | ||
| from archinstall.lib.networking import ping | ||
| from archinstall.lib.packages.packages import check_version_upgrade | ||
|
|
||
| from .lib.hardware import SysInfo | ||
| from .lib.output import debug, error, info, warn | ||
| from .lib.pacman import Pacman | ||
| from .lib.translationhandler import tr | ||
|
|
||
|
|
||
| def _log_sys_info() -> None: | ||
| # Log various information about hardware before starting the installation. This might assist in troubleshooting | ||
| debug(f'Hardware model detected: {SysInfo.sys_vendor()} {SysInfo.product_name()}; UEFI mode: {SysInfo.has_uefi()}') | ||
| debug(f'Processor model detected: {SysInfo.cpu_model()}') | ||
| debug(f'Memory statistics: {SysInfo.mem_available()} available out of {SysInfo.mem_total()} total installed') | ||
| debug(f'Virtualization detected: {SysInfo.virtualization()}; is VM: {SysInfo.is_vm()}') | ||
| debug(f'Graphics devices detected: {SysInfo._graphics_devices().keys()}') | ||
|
|
||
| # For support reasons, we'll log the disk layout pre installation to match against post-installation layout | ||
| debug(f'Disk states before installing:\n{disk_layouts()}') | ||
|
|
||
|
|
||
| def _check_online() -> None: | ||
| try: | ||
| ping('1.1.1.1') | ||
| except OSError as ex: | ||
| if 'Network is unreachable' in str(ex): | ||
| if not arch_config_handler.args.skip_wifi_check: | ||
| success = not wifi_handler.setup() | ||
| if not success: | ||
| sys.exit(0) | ||
|
|
||
|
|
||
| def _fetch_arch_db() -> None: | ||
| info('Fetching Arch Linux package database...') | ||
| try: | ||
| Pacman.run('-Sy') | ||
| except Exception as e: | ||
| error('Failed to sync Arch Linux package database.') | ||
| if 'could not resolve host' in str(e).lower(): | ||
| error('Most likely due to a missing network connection or DNS issue.') | ||
|
|
||
| error('Run archinstall --debug and check /var/log/archinstall/install.log for details.') | ||
|
|
||
| debug(f'Failed to sync Arch Linux package database: {e}') | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def run() -> int: | ||
| """ | ||
| This can either be run as the compiled and installed application: python setup.py install | ||
| 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 | ||
| """ | ||
| if '--help' in sys.argv or '-h' in sys.argv: | ||
| arch_config_handler.print_help() | ||
| return 0 | ||
|
|
||
| if os.getuid() != 0: | ||
| print(tr('Archinstall requires root privileges to run. See --help for more.')) | ||
| return 1 | ||
|
|
||
| _log_sys_info() | ||
|
|
||
| if not arch_config_handler.args.offline: | ||
| _check_online() | ||
| _fetch_arch_db() | ||
|
|
||
| if not arch_config_handler.args.skip_version_check: | ||
| upgrade = check_version_upgrade() | ||
|
|
||
| if upgrade: | ||
| text = tr('New version available') + f': {upgrade}' | ||
| info(text) | ||
| time.sleep(3) | ||
|
|
||
| if running_from_host(): | ||
| # log which mode we are using | ||
| debug('Running from Host (H2T Mode)...') | ||
| else: | ||
| debug('Running from ISO (Live Mode)...') | ||
|
|
||
| script = arch_config_handler.get_script() | ||
|
|
||
| mod_name = f'archinstall.scripts.{script}' | ||
| # by loading the module we'll automatically run the script | ||
| importlib.import_module(mod_name) | ||
|
|
||
| return 0 | ||
|
|
||
|
|
||
| def main() -> int: | ||
| rc = 0 | ||
| exc = None | ||
|
|
||
| try: | ||
| rc = run() | ||
| except Exception as e: | ||
| exc = e | ||
| finally: | ||
| if exc: | ||
| err = ''.join(traceback.format_exception(exc)) | ||
| error(err) | ||
|
|
||
| text = ( | ||
| 'Archinstall experienced the above error. If you think this is a bug, please report it to\n' | ||
| 'https://github.com/archlinux/archinstall and include the log file "/var/log/archinstall/install.log".\n\n' | ||
| "Hint: To extract the log from a live ISO \ncurl -F 'file=@/var/log/archinstall/install.log' https://0x0.st\n" | ||
| ) | ||
|
|
||
| warn(text) | ||
| rc = 1 | ||
|
|
||
| sys.exit(rc) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shoulnd't these also be returns if they are received by
rc?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a code move, not a refactor. It is best to keep a pull request focused on one thing and as small as possible that way it is easier to review amongst other benefits.
There is plenty that can be refactored here but that is irrelevant to this pull request.