Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/examples/guided.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/guided.py')
-rw-r--r--examples/guided.py87
1 files changed, 67 insertions, 20 deletions
diff --git a/examples/guided.py b/examples/guided.py
index 30514a71..cc660b90 100644
--- a/examples/guided.py
+++ b/examples/guided.py
@@ -1,4 +1,20 @@
-import archinstall, getpass, time
+import archinstall
+import getpass, time, json, sys, signal
+
+"""
+This signal-handler chain (and global variable)
+is used to trigger the "Are you sure you want to abort?" question.
+"""
+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)
def perform_installation(device, boot_partition, language, mirrors):
"""
@@ -50,8 +66,13 @@ archinstall.sys_command(f'cryptsetup close /dev/mapper/luksloop', surpress_error
keyboard_language = archinstall.select_language(archinstall.list_keyboard_languages())
archinstall.set_keyboard_language(keyboard_language)
+# Create a storage structure for all our information.
+# We'll print this right before the user gets informed about the formatting timer.
+archinstall.storage['_guided'] = {}
+
# Set which region to download packages from during the installation
mirror_regions = archinstall.select_mirror_regions(archinstall.list_mirrors())
+archinstall.storage['_guided']['mirrors'] = mirror_regions
# Ask which harddrive/block-device we will install to
harddrive = archinstall.select_disk(archinstall.all_disks())
@@ -61,10 +82,12 @@ while (disk_password := getpass.getpass(prompt='Enter disk encryption password (
archinstall.log(' * Passwords did not match * ', bg='black', fg='red')
continue
break
+archinstall.storage['_guided']['harddrive'] = harddrive
# Ask for a hostname
hostname = input('Desired hostname for the installation: ')
if len(hostname) == 0: hostname = 'ArchInstall'
+archinstall.storage['_guided']['hostname'] = hostname
# Ask for a root password (optional, but triggers requirement for super-user if skipped)
while (root_pw := getpass.getpass(prompt='Enter root password (leave blank to leave root disabled): ')):
@@ -87,6 +110,10 @@ while 1:
archinstall.log(' * Since root is disabled, you need to create a least one (super) user!', bg='black', fg='red')
continue
break
+
+ if 'users' not in archinstall.storage['_guided']: archinstall.storage['_guided']['users'] = []
+ archinstall.storage['_guided']['users'].append(new_user)
+
new_user_passwd = getpass.getpass(prompt=f'Password for user {new_user}: ')
new_user_passwd_verify = getpass.getpass(prompt=f'Enter password again for verification: ')
if new_user_passwd != new_user_passwd_verify:
@@ -99,12 +126,17 @@ while 1:
# Ask for archinstall-specific profiles (such as desktop environments etc)
while 1:
profile = archinstall.select_profile(archinstall.list_profiles())
- if profile and type(profile) != str: # Got a imported profile
- if not profile[1]._prep_function():
- archinstall.log(' * Profile\'s preperation requirements was not fulfilled.', bg='black', fg='red')
- continue
- profile = profile[0]._path # Once the prep is done, replace the selected profile with the profile name ("path") given from select_profile()
- break
+ if profile:
+ archinstall.storage['_guided']['profile'] = profile
+
+ if type(profile) != str: # Got a imported profile
+ archinstall.storage['_guided']['profile'] = profile[0] # The second return is a module, and not a handle/object.
+ if not profile[1]._prep_function():
+ archinstall.log(' * Profile\'s preperation requirements was not fulfilled.', bg='black', fg='red')
+ continue
+
+ profile = profile[0]._path # Once the prep is done, replace the selected profile with the profile name ("path") given from select_profile()
+ break
else:
break
@@ -117,27 +149,42 @@ while 1:
try:
if archinstall.validate_package_list(packages):
+ archinstall.storage['_guided']['packages'] = packages
break
except archinstall.RequirementError as e:
print(e)
-# TODO: Print a summary here of all the options chosen.
-# Ideally, archinstall should keep track of this internally
-# and there should be something like print(archinstall.config).
+print()
+print('This is your chosen configuration:')
+print(json.dumps(archinstall.storage['_guided'], indent=4, sort_keys=True, cls=archinstall.JSON))
+print()
"""
Issue a final warning before we continue with something un-revertable.
+ We mention the drive one last time, and count from 5 to 0.
"""
-print(f' ! Formatting {harddrive} in 5...')
-time.sleep(1)
-print(f' ! Formatting {harddrive} in 4...')
-time.sleep(1)
-print(f' ! Formatting {harddrive} in 3...')
-time.sleep(1)
-print(f' ! Formatting {harddrive} in 2...')
-time.sleep(1)
-print(f' ! Formatting {harddrive} in 1...')
-time.sleep(1)
+
+print(f' ! Formatting {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)
+print()
+signal.signal(signal.SIGINT, original_sigint_handler)
"""
Setup the blockdevice, filesystem (and optionally encryption).