Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/examples/minimal.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-04-08 21:14:19 +0200
committerAnton Hvornum <anton@hvornum.se>2021-04-08 21:14:19 +0200
commitb5245b31fec9c19a16a8b00233afb1cfee1499fa (patch)
tree7d01f4721f6b8473c0f72c8dd725e7724c594c20 /examples/minimal.py
parentae2da06075763d388c303e8cd7914694454aa8fb (diff)
I simplified the countdown, by moving it into it's own function instead of wrapped inside guided.. This can now be used by others for a simple countdown. I also re-worked the minimal.py example to work with the new internal partitioning logic API as well as support some flags from archinstall.arguments to minimize user input requirements to just one single question. This one question will most likely go away too, but stays for simplicity right now.
Diffstat (limited to 'examples/minimal.py')
-rw-r--r--examples/minimal.py78
1 files changed, 56 insertions, 22 deletions
diff --git a/examples/minimal.py b/examples/minimal.py
index 9124f5bd..b9472ac9 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('minimal')
+ with archinstall.luks2(root, 'luksloop', archinstall.arguments.get('!encryption-password', None)) as unlocked_root:
+ unlocked_root.format(root.filesystem)
- installation.user_create('devel', 'devel')
- installation.user_set_pw('root', 'toor')
+ install_on(unlocked_root)
+ else:
+ root.format(root.filesystem)
+ install_on(root) \ No newline at end of file