Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/guided.py57
-rw-r--r--examples/minimal.py78
2 files changed, 63 insertions, 72 deletions
diff --git a/examples/guided.py b/examples/guided.py
index 4205518d..6feebd00 100644
--- a/examples/guided.py
+++ b/examples/guided.py
@@ -1,27 +1,7 @@
-import getpass, time, json, sys, signal, os
+import getpass, time, json, os
import archinstall
-
-"""
-This signal-handler chain (and global variable)
-is used to trigger the "Are you sure you want to abort?" question further down.
-It might look a bit odd, but have a look at the line: "if SIG_TRIGGER:"
-"""
-SIG_TRIGGER = False
-def kill_handler(sig, frame):
- print()
- exit(0)
-
-def sig_handler(sig, frame):
- global SIG_TRIGGER
- SIG_TRIGGER = True
- signal.signal(signal.SIGINT, kill_handler)
-
-original_sigint_handler = signal.getsignal(signal.SIGINT)
-signal.signal(signal.SIGINT, sig_handler)
-
-if archinstall.arguments.get('help'):
- print("See `man archinstall` for help.")
- exit(0)
+from archinstall.lib.hardware import hasUEFI
+from archinstall.lib.profiles import Profile
def ask_user_questions():
"""
@@ -166,7 +146,7 @@ def ask_user_questions():
# Ask for archinstall-specific profiles (such as desktop environments etc)
if not archinstall.arguments.get('profile', None):
- archinstall.arguments['profile'] = archinstall.select_profile(archinstall.list_profiles())
+ archinstall.arguments['profile'] = archinstall.select_profile(filter(lambda profile: (Profile(None, profile).is_top_level_profile()), archinstall.list_profiles()))
else:
archinstall.arguments['profile'] = archinstall.list_profiles()[archinstall.arguments['profile']]
@@ -182,7 +162,8 @@ def ask_user_questions():
# Additional packages (with some light weight error handling for invalid package names)
if not archinstall.arguments.get('packages', None):
- print("Packages not part of the desktop environment are not installed by default. If you desire a web browser, such as firefox or chromium, you may specify it in the following prompt.")
+ print("Packages not part of the desktop environment are not installed by default.")
+ print("If you desire a web browser, such as firefox or chromium, you may specify it in the following prompt.")
archinstall.arguments['packages'] = [package for package in input('Write additional packages to install (space separated, leave blank to skip): ').split(' ') if len(package)]
# Verify packages that were given
@@ -203,8 +184,6 @@ def ask_user_questions():
def perform_installation_steps():
- global SIG_TRIGGER
-
print()
print('This is your chosen configuration:')
archinstall.log("-- Guided template chosen (with below config) --", level=archinstall.LOG_LEVELS.Debug)
@@ -219,29 +198,7 @@ def perform_installation_steps():
"""
print(f" ! Formatting {archinstall.arguments['harddrive']} in ", end='')
-
- for i in range(5, 0, -1):
- print(f"{i}", end='')
-
- for x in range(4):
- sys.stdout.flush()
- time.sleep(0.25)
- print(".", end='')
-
- if SIG_TRIGGER:
- abort = input('\nDo you really want to abort (y/n)? ')
- if abort.strip() != 'n':
- exit(0)
-
- if SIG_TRIGGER is False:
- sys.stdin.read()
- SIG_TRIGGER = False
- signal.signal(signal.SIGINT, sig_handler)
-
- # Put back the default/original signal handler now that we're done catching
- # and interrupting SIGINT with "Do you really want to abort".
- print()
- signal.signal(signal.SIGINT, original_sigint_handler)
+ archinstall.do_countdown()
"""
Setup the blockdevice, filesystem (and optionally encryption).
diff --git a/examples/minimal.py b/examples/minimal.py
index 664bad0d..367574b5 100644
--- a/examples/minimal.py
+++ b/examples/minimal.py
@@ -1,30 +1,64 @@
import archinstall, getpass
-# Unmount and close previous runs
-archinstall.sys_command(f'umount -R /mnt', suppress_errors=True)
-archinstall.sys_command(f'cryptsetup close /dev/mapper/luksloop', suppress_errors=True)
-
# Select a harddrive and a disk password
-harddrive = archinstall.select_disk(archinstall.all_disks())
-disk_password = getpass.getpass(prompt='Disk password (won\'t echo): ')
+archinstall.log(f"Minimal only supports:")
+archinstall.log(f" * Being installed to a single disk")
+
+if archinstall.arguments.get('help', None):
+ archinstall.log(f" - Optional disk encryption via --!encryption-password=<password>")
+ archinstall.log(f" - Optional filesystem type via --filesystem=<fs type>")
+ archinstall.log(f" - Optional systemd network via --network")
+
+archinstall.arguments['harddrive'] = archinstall.select_disk(archinstall.all_disks())
+archinstall.arguments['harddrive'].keep_partitions = False
+
+def install_on(root, boot):
+ # We kick off the installer by telling it where the root and boot lives
+ with archinstall.Installer(root, boot_partition=boot, hostname='minimal-arch') as installation:
+ # Strap in the base system, add a boot loader and configure
+ # some other minor details as specified by this profile and user.
+ if installation.minimal_installation():
+ installation.add_bootloader()
+
+ # Optionally enable networking:
+ if archinstall.arguments.get('network', None):
+ installation.copy_ISO_network_config(enable_services=True)
+
+ installation.add_additional_packages(['nano', 'wget', 'git'])
+ installation.install_profile('minimal')
+
+ installation.user_create('devel', 'devel')
+ installation.user_set_pw('root', 'airoot')
+
+ # Once this is done, we output some useful information to the user
+ # And the installation is complete.
+ archinstall.log(f"There are two new accounts in your installation after reboot:")
+ archinstall.log(f" * root (password: airoot)")
+ archinstall.log(f" * devel (password: devel)")
+
+print(f" ! Formatting {archinstall.arguments['harddrive']} in ", end='')
+archinstall.do_countdown()
+
+# First, we configure the basic filesystem layout
+with archinstall.Filesystem(archinstall.arguments['harddrive'], archinstall.GPT) as fs:
+ # We use the entire disk instead of setting up partitions on your own
+ if archinstall.arguments['harddrive'].keep_partitions is False:
+ fs.use_entire_disk(root_filesystem_type=archinstall.arguments.get('filesystem', 'btrfs'))
-with archinstall.Filesystem(harddrive, archinstall.GPT) as fs:
- # Use the entire disk instead of setting up partitions on your own
- fs.use_entire_disk('luks2')
+ boot = fs.find_partition('/boot')
+ root = fs.find_partition('/')
- if harddrive.partition[1].size == '512M':
- raise OSError('Trying to encrypt the boot partition for petes sake..')
- harddrive.partition[0].format('fat32')
+ boot.format('vfat')
- with archinstall.luks2(harddrive.partition[1], 'luksloop', disk_password) as unlocked_device:
- unlocked_device.format('btrfs')
-
- with archinstall.Installer(unlocked_device, boot_partition=harddrive.partition[0], hostname='testmachine') as installation:
- if installation.minimal_installation():
- installation.add_bootloader()
+ # We encrypt the root partition if we got a password to do so with,
+ # Otherwise we just skip straight to formatting and installation
+ if archinstall.arguments.get('!encryption-password', None):
+ root.encrypt()
- installation.add_additional_packages(['nano', 'wget', 'git'])
- installation.install_profile('awesome')
+ with archinstall.luks2(root, 'luksloop', archinstall.arguments.get('!encryption-password', None)) as unlocked_root:
+ unlocked_root.format(root.filesystem)
- installation.user_create('anton', 'test')
- installation.user_set_pw('root', 'toor') \ No newline at end of file
+ install_on(unlocked_root)
+ else:
+ root.format(root.filesystem)
+ install_on(root, boot) \ No newline at end of file