Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2022-01-14 08:11:30 +0100
committerAnton Hvornum <anton@hvornum.se>2022-01-14 08:11:30 +0100
commit4bd07ea19f17ef8c78bf12f0d3d50f71c2306c19 (patch)
treef417000cc16087dca1aed81391431ab85de7f513 /examples
parent0bc3e94c795fdde55ccc9b233b897498dc7b498e (diff)
parente8b6b1b334fffe5c5de8c2951a974b0126ffd2b0 (diff)
Merge branch 'master' of github.com:archlinux/archinstall
Diffstat (limited to 'examples')
-rw-r--r--examples/guided.py140
-rw-r--r--examples/only_hd.py54
2 files changed, 40 insertions, 154 deletions
diff --git a/examples/guided.py b/examples/guided.py
index 57409644..aaf69376 100644
--- a/examples/guided.py
+++ b/examples/guided.py
@@ -57,133 +57,65 @@ def ask_user_questions():
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):
- archinstall.arguments['keyboard-layout'] = archinstall.select_language()
- # 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'])
+ global_menu = archinstall.GlobalMenu()
+ global_menu.enable('keyboard-layout')
- # 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()
+ if not archinstall.arguments.get('ntp', False):
+ archinstall.arguments['ntp'] = input("Would you like to use automatic time synchronization (NTP) with the default time servers? [Y/n]: ").strip().lower() in ('y', 'yes', '')
+ if archinstall.arguments['ntp']:
+ archinstall.log("Hardware time and other post-configuration steps might be required in order for NTP to work. For more information, please check the Arch wiki.", fg="yellow")
+ archinstall.SysCommand('timedatectl set-ntp true')
- 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")
+ # Set which region to download packages from during the installation
+ global_menu.enable('mirror-region')
- 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'
+ if archinstall.arguments.get('advanced', False):
+ global_menu.enable('sys-language', True)
+ global_menu.enable('sys-encoding', True)
# 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.select_harddrives()
- # we skip the customary .get('harddrives',None) 'cause we are pretty certain that at this point it contains at least none (behaviour has changed from previous version, where it had an empty list. Shouls be compatible with my code
- if not archinstall.arguments['harddrives']:
- archinstall.log("You decided to skip harddrive selection",fg="yellow",level=logging.INFO)
- archinstall.log(f"and will use whatever drive-setup is mounted at {archinstall.storage['MOUNT_POINT']} (experimental)",fg="yellow",level=logging.INFO)
- archinstall.log("WARNING: Archinstall won't check the suitability of this setup",fg="yellow",level=logging.INFO)
- if input("Do you wish to continue ? [Y/n]").strip().lower() == 'n':
- exit(1)
- else:
- if archinstall.storage.get('disk_layouts', None) is None:
- archinstall.storage['disk_layouts'] = archinstall.select_disk_layout(archinstall.arguments['harddrives'], archinstall.arguments.get('advanced', False))
-
- # Get disk encryption password (or skip if blank)
- if 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
-
- if archinstall.arguments.get('!encryption-password', None):
- # If no partitions was marked as encrypted, but a password was supplied and we have some disks to format..
- # Then we need to identify which partitions to encrypt. This will default to / (root).
- if len(list(archinstall.encrypted_partitions(archinstall.storage['disk_layouts']))) == 0:
- archinstall.storage['disk_layouts'] = archinstall.select_encrypted_partitions(archinstall.storage['disk_layouts'], archinstall.arguments['!encryption-password'])
+ global_menu.enable('harddrives')
+
+ global_menu.enable('disk_layouts')
+
+ # Get disk encryption password (or skip if blank)
+ global_menu.enable('!encryption-password')
# Ask which boot-loader to use (will only ask if we're in BIOS (non-efi) mode)
- if not archinstall.arguments.get("bootloader", None):
- archinstall.arguments["bootloader"] = archinstall.ask_for_bootloader(archinstall.arguments.get('advanced', False))
+ global_menu.enable('bootloader')
- if not archinstall.arguments.get('swap', None):
- archinstall.arguments['swap'] = archinstall.ask_for_swap()
+ global_menu.enable('swap')
# Get the hostname for the machine
- if not archinstall.arguments.get('hostname', None):
- archinstall.arguments['hostname'] = input('Desired hostname for the installation: ').strip(' ')
+ global_menu.enable('hostname')
# Ask for a root password (optional, but triggers requirement for super-user if skipped)
- if not archinstall.arguments.get('!root-password', None):
- archinstall.arguments['!root-password'] = archinstall.get_password(prompt='Enter root password (leave blank to disable root & create superuser): ')
-
- # Ask for additional users (super-user if root pw was not set)
- if not archinstall.arguments.get('!root-password', None) and not archinstall.arguments.get('!superusers', None):
- archinstall.arguments['!superusers'] = archinstall.ask_for_superuser_account('Create a required super-user with sudo privileges: ', forced=True)
+ global_menu.enable('!root-password')
- if not archinstall.arguments.get('!users'):
- users, superusers = archinstall.ask_for_additional_users('Enter a username to create an additional user (leave blank to skip & continue): ')
- archinstall.arguments['!users'] = users
- archinstall.arguments['!superusers'] = {**archinstall.arguments.get('!superusers', {}), **superusers}
+ global_menu.enable('!superusers')
+ global_menu.enable('!users')
# Ask for archinstall-specific profiles (such as desktop environments etc)
- if not archinstall.arguments.get('profile', None):
- archinstall.arguments['profile'] = archinstall.select_profile()
-
- # Check the potentially selected profiles preparations to get early checks if some additional questions are needed.
- if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_prep_function():
- namespace = f"{archinstall.arguments['profile'].namespace}.py"
- with archinstall.arguments['profile'].load_instructions(namespace=namespace) as imported:
- if not imported._prep_function():
- archinstall.log(' * Profile\'s preparation requirements was not fulfilled.', fg='red')
- exit(1)
+ global_menu.enable('profile')
# Ask about audio server selection if one is not already set
- if not archinstall.arguments.get('audio', None):
- # The argument to ask_for_audio_selection lets the library know if it's a desktop profile
- archinstall.arguments['audio'] = archinstall.ask_for_audio_selection(archinstall.is_desktop_profile(archinstall.arguments['profile']))
+ global_menu.enable('audio')
# Ask for preferred kernel:
- if not archinstall.arguments.get("kernels", None):
- archinstall.arguments['kernels'] = archinstall.select_kernel()
-
- # Additional packages (with some light weight error handling for invalid package names)
- print("Only packages such as base, base-devel, linux, linux-firmware, efibootmgr and optional profile packages are installed.")
- print("If you desire a web browser, such as firefox or chromium, you may specify it in the following prompt.")
- while True:
- if not archinstall.arguments.get('packages', None):
- archinstall.arguments['packages'] = [package for package in input('Write additional packages to install (space separated, leave blank to skip): ').split(' ') if len(package)]
-
- if len(archinstall.arguments['packages']):
- # Verify packages that were given
- try:
- archinstall.log("Verifying that additional packages exist (this might take a few seconds)")
- archinstall.validate_package_list(archinstall.arguments['packages'])
- break
- except archinstall.RequirementError as e:
- archinstall.log(e, fg='red')
- archinstall.arguments['packages'] = None # Clear the packages to trigger a new input question
- else:
- # no additional packages were selected, which we'll allow
- break
+ global_menu.enable('kernels')
+
+ global_menu.enable('packages')
# Ask or Call the helper function that asks the user to optionally configure a network.
- if not archinstall.arguments.get('nic', None):
- archinstall.arguments['nic'] = archinstall.ask_to_configure_network()
- if not archinstall.arguments['nic']:
- archinstall.log("No network configuration was selected. Network is going to be unavailable until configured manually!", fg="yellow")
+ global_menu.enable('nic')
+
+ global_menu.enable('timezone')
- if not archinstall.arguments.get('timezone', None):
- archinstall.arguments['timezone'] = archinstall.ask_for_a_timezone()
+ global_menu.enable('ntp')
- if archinstall.arguments['timezone']:
- if not archinstall.arguments.get('ntp', False):
- archinstall.arguments['ntp'] = input("Would you like to use automatic time synchronization (NTP) with the default time servers? [Y/n]: ").strip().lower() in ('y', 'yes', '')
- if archinstall.arguments['ntp']:
- archinstall.log("Hardware time and other post-configuration steps might be required in order for NTP to work. For more information, please check the Arch wiki.", fg="yellow")
+ global_menu.run()
def perform_filesystem_operations():
@@ -255,8 +187,8 @@ def perform_installation(mountpoint):
# Placing /boot check during installation because this will catch both re-use and wipe scenarios.
for partition in installation.partitions:
if partition.mountpoint == installation.target + '/boot':
- if partition.size <= 0.25: # in GB
- raise archinstall.DiskError(f"The selected /boot partition in use is not large enough to properly install a boot loader. Please resize it to at least 256MB and re-run the installation.")
+ if partition.size < 0.19: # ~200 MiB in GiB
+ raise archinstall.DiskError(f"The selected /boot partition in use is not large enough to properly install a boot loader. Please resize it to at least 200MiB and re-run the installation.")
# if len(mirrors):
# Certain services might be running that affects the system during installation.
diff --git a/examples/only_hd.py b/examples/only_hd.py
index 151b71a8..0120b64c 100644
--- a/examples/only_hd.py
+++ b/examples/only_hd.py
@@ -4,7 +4,6 @@ import os
import pathlib
import archinstall
-import glob
def load_mirror():
if archinstall.arguments.get('mirror-region', None) is not None:
@@ -27,20 +26,6 @@ def load_harddrives():
archinstall.arguments['harddrives'] = [archinstall.BlockDevice(BlockDev) for BlockDev in archinstall.arguments['harddrives']]
# Temporarily disabling keep_partitions if config file is loaded
-def load_disk_layouts():
- if archinstall.arguments.get('disk_layouts', None) is not None:
- dl_path = pathlib.Path(archinstall.arguments['disk_layouts'])
- if dl_path.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.")
def ask_harddrives():
# Ask which harddrives/block-devices we will install to
@@ -106,7 +91,6 @@ def load_config():
load_localization()
load_gfxdriver()
load_servers()
- load_disk_layouts()
def ask_user_questions():
"""
@@ -169,40 +153,6 @@ def perform_disk_operations():
with archinstall.Filesystem(drive, mode) as fs:
fs.load_layout(dl_disk)
-
-def create_subvolume(installation_mountpoint, subvolume_location):
- """
- This function uses btrfs to create a subvolume.
-
- @installation: archinstall.Installer instance
- @subvolume_location: a localized string or path inside the installation / or /boot for instance without specifying /mnt/boot
- """
- if type(installation_mountpoint) == str:
- installation_mountpoint_path = pathlib.Path(installation_mountpoint)
- else:
- installation_mountpoint_path = installation_mountpoint
- # Set up the required physical structure
- if type(subvolume_location) == str:
- subvolume_location = pathlib.Path(subvolume_location)
-
- target = installation_mountpoint_path / subvolume_location.relative_to(subvolume_location.anchor)
-
- # Difference from mount_subvolume:
- # We only check if the parent exists, since we'll run in to "target path already exists" otherwise
- if not target.parent.exists():
- target.parent.mkdir(parents=True)
-
- if glob.glob(str(target / '*')):
- raise archinstall.DiskError(f"Cannot create subvolume at {target} because it contains data (non-empty folder target)")
-
- # Remove the target if it exists. It is nor incompatible to the previous
- if target.exists():
- target.rmdir()
-
- archinstall.log(f"Creating a subvolume on {target}", level=logging.INFO)
- if (cmd := archinstall.SysCommand(f"btrfs subvolume create {target}")).exit_code != 0:
- raise archinstall.DiskError(f"Could not create a subvolume at {target}: {cmd}")
-
def perform_installation(mountpoint):
"""
Performs the installation steps on a block device.
@@ -220,6 +170,10 @@ def perform_installation(mountpoint):
if partition.mountpoint == installation.target + '/boot':
if partition.size <= 0.25: # in GB
raise archinstall.DiskError(f"The selected /boot partition in use is not large enough to properly install a boot loader. Please resize it to at least 256MB and re-run the installation.")
+ # to generate a fstab directory holder. Avoids an error on exit and at the same time checks the procedure
+ target = pathlib.Path(f"{mountpoint}/etc/fstab")
+ if not target.parent.exists():
+ target.parent.mkdir(parents=True)
# For support reasons, we'll log the disk layout post installation (crash or no crash)
archinstall.log(f"Disk states after installing: {archinstall.disk_layouts()}", level=logging.DEBUG)