コード例 #1
0
ファイル: guided.py プロジェクト: kevr/archinstall
def load_config():
    if archinstall.arguments.get('harddrives', None) is not None:
        if type(archinstall.arguments['harddrives']) is str:
            archinstall.arguments['harddrives'] = archinstall.arguments[
                'harddrives'].split(',')
        archinstall.arguments['harddrives'] = [
            archinstall.BlockDevice(BlockDev)
            for BlockDev in archinstall.arguments['harddrives']
        ]
        # Temporarily disabling keep_partitions if config file is loaded
        # Temporary workaround to make Desktop Environments work
    if archinstall.arguments.get('profile', None) is not None:
        if type(archinstall.arguments.get('profile', None)) is dict:
            archinstall.arguments['profile'] = archinstall.Profile(
                None,
                archinstall.arguments.get('profile', None)['path'])
        else:
            archinstall.arguments['profile'] = archinstall.Profile(
                None, archinstall.arguments.get('profile', None))
    archinstall.storage['_desktop_profile'] = archinstall.arguments.get(
        'desktop-environment', None)
    if archinstall.arguments.get('mirror-region', None) is not None:
        if type(archinstall.arguments.get('mirror-region', None)) is dict:
            archinstall.arguments['mirror-region'] = archinstall.arguments.get(
                'mirror-region', None)
        else:
            selected_region = archinstall.arguments.get('mirror-region', None)
            archinstall.arguments['mirror-region'] = {
                selected_region: archinstall.list_mirrors()[selected_region]
            }
    if archinstall.arguments.get('sys-language', None) is not None:
        archinstall.arguments['sys-language'] = archinstall.arguments.get(
            'sys-language', 'en_US')
    if archinstall.arguments.get('sys-encoding', None) is not None:
        archinstall.arguments['sys-encoding'] = archinstall.arguments.get(
            'sys-encoding', 'utf-8')
    if archinstall.arguments.get('gfx_driver', None) is not None:
        archinstall.storage['gfx_driver_packages'] = AVAILABLE_GFX_DRIVERS.get(
            archinstall.arguments.get('gfx_driver', None), None)
    if archinstall.arguments.get('servers', None) is not None:
        archinstall.storage['_selected_servers'] = archinstall.arguments.get(
            'servers', None)
    if archinstall.arguments.get('disk_layouts', None) is not None:
        if (dl_path := pathlib.Path(archinstall.arguments['disk_layouts'])
            ).exists() and str(dl_path).endswith('.json'):
            try:
                with open(dl_path) as fh:
                    archinstall.storage['disk_layouts'] = json.load(fh)
            except Exception as e:
                raise ValueError(
                    f"--disk_layouts does not contain a valid JSON format: {e}"
                )
        else:
            try:
                archinstall.storage['disk_layouts'] = json.loads(
                    archinstall.arguments['disk_layouts'])
            except:
                raise ValueError(
                    "--disk_layouts=<json> needs either a JSON file or a JSON string given with a valid disk layout."
                )
コード例 #2
0
ファイル: only_hd.py プロジェクト: archlinux/archinstall
def load_mirror():
    if archinstall.arguments.get('mirror-region', None) is not None:
        if type(archinstall.arguments.get('mirror-region', None)) is dict:
            archinstall.arguments['mirror-region'] = archinstall.arguments.get(
                'mirror-region', None)
        else:
            selected_region = archinstall.arguments.get('mirror-region', None)
            archinstall.arguments['mirror-region'] = {
                selected_region: archinstall.list_mirrors()[selected_region]
            }
コード例 #3
0
ファイル: guided.py プロジェクト: archlinux/archinstall
def load_config():
    if archinstall.arguments.get('harddrives', None) is not None:
        if type(archinstall.arguments['harddrives']) is str:
            archinstall.arguments['harddrives'] = archinstall.arguments[
                'harddrives'].split(',')
        archinstall.arguments['harddrives'] = [
            archinstall.BlockDevice(BlockDev)
            for BlockDev in archinstall.arguments['harddrives']
        ]
        # Temporarily disabling keep_partitions if config file is loaded
        # Temporary workaround to make Desktop Environments work
    if archinstall.arguments.get('profile', None) is not None:
        if type(archinstall.arguments.get('profile', None)) is dict:
            archinstall.arguments['profile'] = archinstall.Profile(
                None,
                archinstall.arguments.get('profile', None)['path'])
        else:
            archinstall.arguments['profile'] = archinstall.Profile(
                None, archinstall.arguments.get('profile', None))
    archinstall.storage['_desktop_profile'] = archinstall.arguments.get(
        'desktop-environment', None)
    if archinstall.arguments.get('mirror-region', None) is not None:
        if type(archinstall.arguments.get('mirror-region', None)) is dict:
            archinstall.arguments['mirror-region'] = archinstall.arguments.get(
                'mirror-region', None)
        else:
            selected_region = archinstall.arguments.get('mirror-region', None)
            archinstall.arguments['mirror-region'] = {
                selected_region: archinstall.list_mirrors()[selected_region]
            }
    if archinstall.arguments.get('sys-language', None) is not None:
        archinstall.arguments['sys-language'] = archinstall.arguments.get(
            'sys-language', 'en_US')
    if archinstall.arguments.get('sys-encoding', None) is not None:
        archinstall.arguments['sys-encoding'] = archinstall.arguments.get(
            'sys-encoding', 'utf-8')
    if archinstall.arguments.get('gfx_driver', None) is not None:
        archinstall.storage[
            'gfx_driver_packages'] = archinstall.AVAILABLE_GFX_DRIVERS.get(
                archinstall.arguments.get('gfx_driver', None), None)
    if archinstall.arguments.get('servers', None) is not None:
        archinstall.storage['_selected_servers'] = archinstall.arguments.get(
            'servers', None)
コード例 #4
0
ファイル: guided.py プロジェクト: shizonic/archinstall-1
def ask_user_questions():
    """
	  First, we'll ask the user for a bunch of user input.
	  Not until we're satisfied with what we want to install
	  will we continue with the actual installation steps.
	"""
    if not archinstall.arguments.get('keyboard-language', None):
        archinstall.arguments[
            'keyboard-language'] = archinstall.select_language(
                archinstall.list_keyboard_languages()).strip()

    # Before continuing, set the preferred keyboard layout/language in the current terminal.
    # This will just help the user with the next following questions.
    if len(archinstall.arguments['keyboard-language']):
        archinstall.set_keyboard_language(
            archinstall.arguments['keyboard-language'])

    # Set which region to download packages from during the installation
    if not archinstall.arguments.get('mirror-region', None):
        archinstall.arguments[
            'mirror-region'] = archinstall.select_mirror_regions(
                archinstall.list_mirrors())
    else:
        selected_region = archinstall.arguments['mirror-region']
        archinstall.arguments['mirror-region'] = {
            selected_region: archinstall.list_mirrors()[selected_region]
        }

    # Ask which harddrive/block-device we will install to
    if archinstall.arguments.get('harddrive', None):
        archinstall.arguments['harddrive'] = archinstall.BlockDevice(
            archinstall.arguments['harddrive'])
    else:
        archinstall.arguments['harddrive'] = archinstall.select_disk(
            archinstall.all_disks())

    # Perform a quick sanity check on the selected harddrive.
    # 1. Check if it has partitions
    # 3. Check that we support the current partitions
    # 2. If so, ask if we should keep them or wipe everything
    if archinstall.arguments['harddrive'].has_partitions():
        archinstall.log(
            f"{archinstall.arguments['harddrive']} contains the following partitions:",
            fg='yellow')

        # We curate a list pf supported paritions
        # and print those that we don't support.
        partition_mountpoints = {}
        for partition in archinstall.arguments['harddrive']:
            try:
                if partition.filesystem_supported():
                    archinstall.log(f" {partition}")
                    partition_mountpoints[partition] = None
            except archinstall.UnknownFilesystemFormat as err:
                archinstall.log(f" {partition} (Filesystem not supported)",
                                fg='red')

        # We then ask what to do with the paritions.
        if (option := archinstall.ask_for_disk_layout()) == 'abort':
            archinstall.log(
                f"Safely aborting the installation. No changes to the disk or system has been made."
            )
            exit(1)
        elif option == 'keep-existing':
            archinstall.arguments['harddrive'].keep_partitions = True

            archinstall.log(
                f" ** You will now select which partitions to use by selecting mount points (inside the installation). **"
            )
            archinstall.log(
                f" ** The root would be a simple / and the boot partition /boot (as all paths are relative inside the installation). **"
            )
            while True:
                # Select a partition
                partition = archinstall.generic_select(
                    partition_mountpoints.keys(),
                    "Select a partition by number that you want to set a mount-point for (leave blank when done): "
                )
                if not partition:
                    break

                # Select a mount-point
                mountpoint = input(
                    f"Enter a mount-point for {partition}: ").strip(' ')
                if len(mountpoint):

                    # Get a valid & supported filesystem for the parition:
                    while 1:
                        new_filesystem = input(
                            f"Enter a valid filesystem for {partition} (leave blank for {partition.filesystem}): "
                        ).strip(' ')
                        if len(new_filesystem) <= 0:
                            if partition.encrypted and partition.filesystem == 'crypto_LUKS':
                                old_password = archinstall.arguments.get(
                                    '!encryption-password', None)
                                if not old_password:
                                    old_password = input(
                                        f'Enter the old encryption password for {partition}: '
                                    )

                                if (autodetected_filesystem :=
                                        partition.detect_inner_filesystem(
                                            old_password)):
                                    new_filesystem = autodetected_filesystem
                                else:
                                    archinstall.log(
                                        f"Could not auto-detect the filesystem inside the encrypted volume.",
                                        fg='red')
                                    archinstall.log(
                                        f"A filesystem must be defined for the unlocked encrypted partition."
                                    )
                                    continue
                            break

                        # Since the potentially new filesystem is new
                        # we have to check if we support it. We can do this by formatting /dev/null with the partitions filesystem.
                        # There's a nice wrapper for this on the partition object itself that supports a path-override during .format()
                        try:
                            partition.format(new_filesystem,
                                             path='/dev/null',
                                             log_formating=False,
                                             allow_formatting=True)
                        except archinstall.UnknownFilesystemFormat:
                            archinstall.log(
                                f"Selected filesystem is not supported yet. If you want archinstall to support '{new_filesystem}', please create a issue-ticket suggesting it on github at https://github.com/Torxed/archinstall/issues."
                            )
                            archinstall.log(
                                f"Until then, please enter another supported filesystem."
                            )
                            continue
                        except archinstall.SysCallError:
                            pass  # Expected exception since mkfs.<format> can not format /dev/null.
                            # But that means our .format() function supported it.
                        break

                    # When we've selected all three criterias,
                    # We can safely mark the partition for formatting and where to mount it.
                    # TODO: allow_formatting might be redundant since target_mountpoint should only be
                    #       set if we actually want to format it anyway.
                    partition.allow_formatting = True
                    partition.target_mountpoint = mountpoint
                    # Only overwrite the filesystem definition if we selected one:
                    if len(new_filesystem):
                        partition.filesystem = new_filesystem

            archinstall.log('Using existing partition table reported above.')
コード例 #5
0
ファイル: guided.py プロジェクト: kevr/archinstall
def ask_user_questions():
    """
		First, we'll ask the user for a bunch of user input.
		Not until we're satisfied with what we want to install
		will we continue with the actual installation steps.
	"""
    if not archinstall.arguments.get('keyboard-layout', None):
        while True:
            try:
                archinstall.arguments[
                    'keyboard-layout'] = archinstall.select_language(
                        archinstall.list_keyboard_languages()).strip()
                break
            except archinstall.RequirementError as err:
                archinstall.log(err, fg="red")

    # Before continuing, set the preferred keyboard layout/language in the current terminal.
    # This will just help the user with the next following questions.
    if len(archinstall.arguments['keyboard-layout']):
        archinstall.set_keyboard_language(
            archinstall.arguments['keyboard-layout'])

    # Set which region to download packages from during the installation
    if not archinstall.arguments.get('mirror-region', None):
        while True:
            try:
                archinstall.arguments[
                    'mirror-region'] = archinstall.select_mirror_regions(
                        archinstall.list_mirrors())
                break
            except archinstall.RequirementError as e:
                archinstall.log(e, fg="red")

    if not archinstall.arguments.get('sys-language',
                                     None) and archinstall.arguments.get(
                                         'advanced', False):
        archinstall.arguments['sys-language'] = input(
            "Enter a valid locale (language) for your OS, (Default: en_US): "
        ).strip()
        archinstall.arguments['sys-encoding'] = input(
            "Enter a valid system default encoding for your OS, (Default: utf-8): "
        ).strip()
        archinstall.log(
            "Keep in mind that if you want multiple locales, post configuration is required.",
            fg="yellow")

    if not archinstall.arguments.get('sys-language', None):
        archinstall.arguments['sys-language'] = 'en_US'
    if not archinstall.arguments.get('sys-encoding', None):
        archinstall.arguments['sys-encoding'] = 'utf-8'

    # Ask which harddrives/block-devices we will install to
    # and convert them into archinstall.BlockDevice() objects.
    if archinstall.arguments.get('harddrives', None) is None:
        archinstall.arguments['harddrives'] = archinstall.generic_multi_select(
            archinstall.all_disks(),
            text=
            "Select one or more harddrives to use and configure (leave blank to skip this step): ",
            allow_empty=True)

    if archinstall.arguments.get('harddrives',
                                 None) is not None and archinstall.storage.get(
                                     'disk_layouts', None) is None:
        archinstall.storage['disk_layouts'] = archinstall.select_disk_layout(
            archinstall.arguments['harddrives'])

    # Get disk encryption password (or skip if blank)
    if archinstall.arguments['harddrives'] and archinstall.arguments.get(
            '!encryption-password', None) is None:
        if (passwd := archinstall.get_password(
                prompt=
                'Enter disk encryption password (leave blank for no encryption): '
        )):
            archinstall.arguments['!encryption-password'] = passwd
コード例 #6
0
    archinstall.arguments['harddrive'].keep_partitions = False
    # Temporary workaround to make Desktop Environments work
    if archinstall.arguments.get('profile', None) is not None:
        if type(archinstall.arguments.get('profile', None)) is dict:
            archinstall.arguments['profile'] = archinstall.Profile(
                None,
                archinstall.arguments.get('profile', None)['path'])
        else:
            archinstall.arguments['profile'] = archinstall.Profile(
                None, archinstall.arguments.get('profile', None))
    else:
        archinstall.arguments['profile'] = None
    if archinstall.arguments.get('mirror-region', None) is not None:
        if type(archinstall.arguments.get('mirror-region', None)) is dict:
            archinstall.arguments['mirror-region'] = archinstall.arguments.get(
                'mirror-region', None)
        else:
            selected_region = archinstall.arguments.get('mirror-region', None)
            archinstall.arguments['mirror-region'] = {
                selected_region: archinstall.list_mirrors()[selected_region]
            }
    archinstall.arguments['sys-language'] = archinstall.arguments.get(
        'sys-language', 'en_US')
    archinstall.arguments['sys-encoding'] = archinstall.arguments.get(
        'sys-encoding', 'utf-8')
    if archinstall.arguments.get('gfx_driver', None) is not None:
        archinstall.storage['gfx_driver_packages'] = AVAILABLE_GFX_DRIVERS.get(
            archinstall.arguments.get('gfx_driver', None), None)

perform_installation_steps()
コード例 #7
0
# Unmount and close previous runs (in case the installer is restarted)
archinstall.sys_command(f'umount -R /mnt', surpress_errors=True)
archinstall.sys_command(f'cryptsetup close /dev/mapper/luksloop', surpress_errors=True)

"""
  First, we'll ask the user for a bunch of user input.
  Not until we're satisfied with what we want to install
  will we continue with the actual installation steps.
"""

keyboard_language = archinstall.select_language(archinstall.list_keyboard_languages())
archinstall.set_keyboard_language(keyboard_language)

# Set which region to download packages from during the installation
mirror_regions = archinstall.select_mirror_regions(archinstall.list_mirrors())

harddrive = archinstall.select_disk(archinstall.all_disks())
while (disk_password := getpass.getpass(prompt='Enter disk encryption password (leave blank for no encryption): ')):
	disk_password_verification = getpass.getpass(prompt='And one more time for verification: ')
	if disk_password != disk_password_verification:
		archinstall.log(' * Passwords did not match * ', bg='black', fg='red')
		continue
	break

hostname = input('Desired hostname for the installation: ')
if len(hostname) == 0: hostname = 'ArchInstall'

while (root_pw := getpass.getpass(prompt='Enter root password (leave blank to leave root disabled): ')):
	root_pw_verification = getpass.getpass(prompt='And one more time for verification: ')
	if root_pw != root_pw_verification:
コード例 #8
0
if not archinstall.arguments.get('silent'):
	ask_user_questions()
else:
	# Workarounds if config is loaded from a file
	# The harddrive section should be moved to perform_installation_steps, where it's actually being performed
	# Blockdevice object should be created in perform_installation_steps
	# This needs to be done until then
	archinstall.arguments['harddrive'] = archinstall.BlockDevice(path=archinstall.arguments['harddrive']['path'])
	# Temporarily disabling keep_partitions if config file is loaded
	archinstall.arguments['harddrive'].keep_partitions = False
	# Temporary workaround to make Desktop Environments work
	if archinstall.arguments.get('profile', None) is not None:
		if type(archinstall.arguments.get('profile', None)) is dict:
			archinstall.arguments['profile'] = archinstall.Profile(None, archinstall.arguments.get('profile', None)['path'])
		else:
			archinstall.arguments['profile'] = archinstall.Profile(None, archinstall.arguments.get('profile', None))
	else:
		archinstall.arguments['profile'] = None
	if archinstall.arguments.get('mirror-region', None) is not None:
		if type(archinstall.arguments.get('mirror-region', None)) is dict:
			archinstall.arguments['mirror-region'] = archinstall.arguments.get('mirror-region', None)
		else:
			selected_region = archinstall.arguments.get('mirror-region', None)
			archinstall.arguments['mirror-region'] = {selected_region: archinstall.list_mirrors()[selected_region]}
	archinstall.arguments['sys-language'] = archinstall.arguments.get('sys-language', 'en_US')
	archinstall.arguments['sys-encoding'] = archinstall.arguments.get('sys-encoding', 'utf-8')
	if archinstall.arguments.get('gfx_driver', None) is not None:
		archinstall.storage['gfx_driver_packages'] = AVAILABLE_GFX_DRIVERS.get(archinstall.arguments.get('gfx_driver', None), None)

perform_installation_steps()