From 592c1737671e4de8f9601f94020d7fb9c162e6cb Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 19 May 2021 19:10:12 -0400 Subject: Iterate over custom-command array --- examples/guided.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index f0d0db7a..7ded5c53 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -4,6 +4,7 @@ import os import time import archinstall +from archinstall.lib.general import SysCommand from archinstall.lib.hardware import has_uefi from archinstall.lib.networking import check_mirror_reachable from archinstall.lib.profiles import Profile @@ -380,6 +381,13 @@ def perform_installation(mountpoint): if not imported._post_install(): archinstall.log(' * Profile\'s post configuration requirements was not fulfilled.', fg='red') exit(1) + + # If the user provided custom commands to be run post-installation, execute them now. + if len(archinstall.arguments['custom-commands']): + for command in archinstall.arguments['custom-commands']: + archinstall.log(f'Executing custom command "{command}" ...', fg='yellow') + SysCommand(f"arch-chroot /mnt {command}") + installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") if not archinstall.arguments.get('silent'): -- cgit v1.2.3-70-g09d2 From c03da01412ace204d86a57aa817b43159a699b80 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 19 May 2021 20:52:33 -0400 Subject: Run custom commands within bash session --- examples/guided.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index 7ded5c53..65f4c9d9 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -386,7 +386,7 @@ def perform_installation(mountpoint): if len(archinstall.arguments['custom-commands']): for command in archinstall.arguments['custom-commands']: archinstall.log(f'Executing custom command "{command}" ...', fg='yellow') - SysCommand(f"arch-chroot /mnt {command}") + SysCommand(f"arch-chroot /mnt bash -c '{command}'") installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") -- cgit v1.2.3-70-g09d2 From 27fa5119145ffdc50b7aff400315dc7a82a8cc29 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Wed, 19 May 2021 21:30:06 -0400 Subject: Try to use the new systemd-nspawn code paths --- examples/guided.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index 65f4c9d9..77f1f4f1 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -4,10 +4,10 @@ import os import time import archinstall -from archinstall.lib.general import SysCommand from archinstall.lib.hardware import has_uefi from archinstall.lib.networking import check_mirror_reachable from archinstall.lib.profiles import Profile +from archinstall.lib.systemd import Boot if archinstall.arguments.get('help'): print("See `man archinstall` for help.") @@ -187,10 +187,7 @@ def ask_user_questions(): if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_prep_function(): with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py") as imported: if not imported._prep_function(): - archinstall.log( - ' * Profile\'s preparation requirements was not fulfilled.', - fg='red' - ) + archinstall.log(' * Profile\'s preparation requirements was not fulfilled.', fg='red') exit(1) # Ask about audio server selection if one is not already set @@ -381,13 +378,13 @@ def perform_installation(mountpoint): if not imported._post_install(): archinstall.log(' * Profile\'s post configuration requirements was not fulfilled.', fg='red') exit(1) - + # If the user provided custom commands to be run post-installation, execute them now. if len(archinstall.arguments['custom-commands']): - for command in archinstall.arguments['custom-commands']: - archinstall.log(f'Executing custom command "{command}" ...', fg='yellow') - SysCommand(f"arch-chroot /mnt bash -c '{command}'") - + with Boot(archinstall) as session: + for command in archinstall.arguments['custom-commands']: + archinstall.log(f'Executing custom command "{command}" ...', fg='yellow') + session.SysCommand(["bash", "-c"] + command.split(' ')) installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") if not archinstall.arguments.get('silent'): -- cgit v1.2.3-70-g09d2 From 7a98ccb9aa82adc16c86a7e9bf5855bf268010bf Mon Sep 17 00:00:00 2001 From: Yash Tripathi Date: Thu, 20 May 2021 08:00:10 +0530 Subject: Update guided.py --- examples/guided.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index 77f1f4f1..29eea324 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -417,6 +417,6 @@ else: # Temporary workaround to make Desktop Environments work archinstall.storage['_desktop_profile'] = archinstall.arguments.get('desktop', None) if archinstall.arguments.get('profile', None): - archinstall.arguments['profile'] = Profile(installer=None, path=archinstall.arguments['profile']['path']) + archinstall.arguments['profile'] = archinstall.list_profiles()[archinstall.arguments['profile']] perform_installation_steps() -- cgit v1.2.3-70-g09d2 From 73e3b99f72a4ac47a4cd69a4fa794f02859b5c58 Mon Sep 17 00:00:00 2001 From: Yash Tripathi Date: Thu, 20 May 2021 18:11:22 +0530 Subject: changed "desktop" to "profile" while loading config --- examples/guided.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index 82ad0443..ad9e6bd1 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -413,6 +413,6 @@ else: # Temporarily disabling keep_partitions if config file is loaded archinstall.arguments['harddrive'].keep_partitions = False # Temporary workaround to make Desktop Environments work - archinstall.arguments['profile'] = archinstall.Profile(None, archinstall.arguments.get('desktop', None)) + archinstall.arguments['profile'] = archinstall.Profile(None, archinstall.arguments.get('profile', None)) perform_installation_steps() -- cgit v1.2.3-70-g09d2 From cf3e47aa44dcd66b97b2943c2392cbcb311952e0 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Thu, 20 May 2021 16:17:04 +0200 Subject: Swapped the instance sent to Boot() --- examples/guided.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index ad9e6bd1..960d4b38 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -379,7 +379,7 @@ def perform_installation(mountpoint): # If the user provided custom commands to be run post-installation, execute them now. if len(archinstall.arguments['custom-commands']): - with Boot(archinstall) as session: + with Boot(installation) as session: for command in archinstall.arguments['custom-commands']: archinstall.log(f'Executing custom command "{command}" ...', fg='yellow') session.SysCommand(["bash", "-c"] + command.split(' ')) -- cgit v1.2.3-70-g09d2 From c39fc34eab0afd6b36802f97bb0df284f9308a48 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Thu, 20 May 2021 13:16:18 -0400 Subject: Use temporary script files Path will be different inside of target env. --- examples/guided.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index 960d4b38..a2f2036e 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -380,9 +380,11 @@ def perform_installation(mountpoint): # If the user provided custom commands to be run post-installation, execute them now. if len(archinstall.arguments['custom-commands']): with Boot(installation) as session: - for command in archinstall.arguments['custom-commands']: + for index, command in enumerate(archinstall.arguments['custom-commands']): archinstall.log(f'Executing custom command "{command}" ...', fg='yellow') - session.SysCommand(["bash", "-c"] + command.split(' ')) + with open(f"/mnt/var/tmp/user-command.{index}.sh", "w") as temp_script: + temp_script.write(command) + session.SysCommand(["bash", f"/var/tmp/user-command.{index}.sh"]) installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") if not archinstall.arguments.get('silent'): -- cgit v1.2.3-70-g09d2 From 7811e01a9049d1c799bb9589807dd2cf3810eda8 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 20 May 2021 14:59:06 -0400 Subject: Switch back to arch-chroot This reverts commit 27fa5119145ffdc50b7aff400315dc7a82a8cc29. --- examples/guided.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index a2f2036e..1b7abab1 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -4,10 +4,10 @@ import os import time import archinstall +from archinstall.lib.general import SysCommand from archinstall.lib.hardware import has_uefi from archinstall.lib.networking import check_mirror_reachable from archinstall.lib.profiles import Profile -from archinstall.lib.systemd import Boot if archinstall.arguments.get('help'): print("See `man archinstall` for help.") @@ -379,12 +379,11 @@ def perform_installation(mountpoint): # If the user provided custom commands to be run post-installation, execute them now. if len(archinstall.arguments['custom-commands']): - with Boot(installation) as session: - for index, command in enumerate(archinstall.arguments['custom-commands']): - archinstall.log(f'Executing custom command "{command}" ...', fg='yellow') - with open(f"/mnt/var/tmp/user-command.{index}.sh", "w") as temp_script: - temp_script.write(command) - session.SysCommand(["bash", f"/var/tmp/user-command.{index}.sh"]) + for index, command in enumerate(archinstall.arguments['custom-commands']): + archinstall.log(f'Executing custom command "{command}" ...', fg='yellow') + with open(f"/mnt/var/tmp/user-command.{index}.sh", "w") as temp_script: + temp_script.write(command) + SysCommand(f"arch-chroot /mnt bash /var/tmp/user-command.{index}.sh") installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") if not archinstall.arguments.get('silent'): -- cgit v1.2.3-70-g09d2 From 5d6935f9f2105aa456259a82eacb58fbafefe60a Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 20 May 2021 15:32:15 -0400 Subject: Add logging of execution output --- examples/guided.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index 1b7abab1..34aacf67 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -383,7 +383,8 @@ def perform_installation(mountpoint): archinstall.log(f'Executing custom command "{command}" ...', fg='yellow') with open(f"/mnt/var/tmp/user-command.{index}.sh", "w") as temp_script: temp_script.write(command) - SysCommand(f"arch-chroot /mnt bash /var/tmp/user-command.{index}.sh") + execution_output = SysCommand(f"arch-chroot /mnt bash /var/tmp/user-command.{index}.sh") + archinstall.log(execution_output) installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") if not archinstall.arguments.get('silent'): -- cgit v1.2.3-70-g09d2 From 11c963232203d463c4fc6f9ec23f60d3b034572b Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 20 May 2021 16:13:16 -0400 Subject: Clean up temp files after they are run --- examples/guided.py | 1 + 1 file changed, 1 insertion(+) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index 34aacf67..7c93ac16 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -385,6 +385,7 @@ def perform_installation(mountpoint): temp_script.write(command) execution_output = SysCommand(f"arch-chroot /mnt bash /var/tmp/user-command.{index}.sh") archinstall.log(execution_output) + os.unlink(f"/mnt/var/tmp/user-command.{index}.sh") installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") if not archinstall.arguments.get('silent'): -- cgit v1.2.3-70-g09d2 From 5652ba20aebf11fa482c74cd85468bd092bc8213 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 20 May 2021 16:51:05 -0400 Subject: Extract custom-commands function into general.py --- archinstall/lib/general.py | 10 ++++++++++ examples/guided.py | 13 +++---------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'examples/guided.py') diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index 81793cb8..19b7b31c 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -366,3 +366,13 @@ def pid_exists(pid: int): return any(subprocess.check_output(['/usr/bin/ps', '--no-headers', '-o', 'pid', '-p', str(pid)]).strip()) except subprocess.CalledProcessError: return False + + +def run_custom_user_commands(commands): + for index, command in enumerate(commands): + log(f'Executing custom command "{command}" ...', fg='yellow') + with open(f"/mnt/var/tmp/user-command.{index}.sh", "w") as temp_script: + temp_script.write(command) + execution_output = SysCommand(f"arch-chroot /mnt bash /var/tmp/user-command.{index}.sh") + log(execution_output) + os.unlink(f"/mnt/var/tmp/user-command.{index}.sh") diff --git a/examples/guided.py b/examples/guided.py index 7c93ac16..fc24ad7e 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -4,10 +4,9 @@ import os import time import archinstall -from archinstall.lib.general import SysCommand +from archinstall.lib.general import run_custom_user_commands from archinstall.lib.hardware import has_uefi from archinstall.lib.networking import check_mirror_reachable -from archinstall.lib.profiles import Profile if archinstall.arguments.get('help'): print("See `man archinstall` for help.") @@ -378,14 +377,8 @@ def perform_installation(mountpoint): exit(1) # If the user provided custom commands to be run post-installation, execute them now. - if len(archinstall.arguments['custom-commands']): - for index, command in enumerate(archinstall.arguments['custom-commands']): - archinstall.log(f'Executing custom command "{command}" ...', fg='yellow') - with open(f"/mnt/var/tmp/user-command.{index}.sh", "w") as temp_script: - temp_script.write(command) - execution_output = SysCommand(f"arch-chroot /mnt bash /var/tmp/user-command.{index}.sh") - archinstall.log(execution_output) - os.unlink(f"/mnt/var/tmp/user-command.{index}.sh") + if archinstall.arguments.get('custom-commands', None): + run_custom_user_commands(archinstall.arguments['custom-commands']) installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") if not archinstall.arguments.get('silent'): -- cgit v1.2.3-70-g09d2 From e6befe53c75b65c88d8f018efc2e6c9479232e9f Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 20 May 2021 17:55:40 -0400 Subject: Use {installation.target} in custom commands handler --- archinstall/lib/general.py | 8 ++++---- examples/guided.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'examples/guided.py') diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index 19b7b31c..249c7890 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -368,11 +368,11 @@ def pid_exists(pid: int): return False -def run_custom_user_commands(commands): +def run_custom_user_commands(commands, installation): for index, command in enumerate(commands): log(f'Executing custom command "{command}" ...', fg='yellow') - with open(f"/mnt/var/tmp/user-command.{index}.sh", "w") as temp_script: + with open(f"{installation.target}/var/tmp/user-command.{index}.sh", "w") as temp_script: temp_script.write(command) - execution_output = SysCommand(f"arch-chroot /mnt bash /var/tmp/user-command.{index}.sh") + execution_output = SysCommand(f"arch-chroot {installation.target} bash /var/tmp/user-command.{index}.sh") log(execution_output) - os.unlink(f"/mnt/var/tmp/user-command.{index}.sh") + os.unlink(f"{installation.target}/var/tmp/user-command.{index}.sh") diff --git a/examples/guided.py b/examples/guided.py index fc24ad7e..7de95c72 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -378,7 +378,7 @@ def perform_installation(mountpoint): # If the user provided custom commands to be run post-installation, execute them now. if archinstall.arguments.get('custom-commands', None): - run_custom_user_commands(archinstall.arguments['custom-commands']) + run_custom_user_commands(archinstall.arguments['custom-commands'], installation) installation.log("For post-installation tips, see https://wiki.archlinux.org/index.php/Installation_guide#Post-installation", fg="yellow") if not archinstall.arguments.get('silent'): -- cgit v1.2.3-70-g09d2 From cba7dae8f059a39ca7276b517ae062aeeb1433f3 Mon Sep 17 00:00:00 2001 From: Yash Tripathi Date: Fri, 21 May 2021 04:00:09 +0530 Subject: fixed creating profile object if profile is passed in vars --- examples/guided.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index 7de95c72..27b359d1 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -179,6 +179,8 @@ 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(filter_top_level_profiles=True)) + else: + archinstall.arguments['profile'] = Profile(installer=None, path=archinstall.arguments['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(): -- cgit v1.2.3-70-g09d2 From bc58ec047d0c2eb08e2b6178ac278c8fd889e3db Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Thu, 20 May 2021 18:39:36 -0400 Subject: Re-add profile import --- examples/guided.py | 1 + 1 file changed, 1 insertion(+) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index 27b359d1..91dd1ddc 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -7,6 +7,7 @@ import archinstall from archinstall.lib.general import run_custom_user_commands from archinstall.lib.hardware import has_uefi from archinstall.lib.networking import check_mirror_reachable +from archinstall.lib.profiles import Profile if archinstall.arguments.get('help'): print("See `man archinstall` for help.") -- cgit v1.2.3-70-g09d2 From 7fefd55a0c716ef93f621d54d20f8d834cbc87ef Mon Sep 17 00:00:00 2001 From: Yash Tripathi Date: Fri, 21 May 2021 01:58:32 +0530 Subject: fallback added for when profile is null/empty --- examples/guided.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'examples/guided.py') diff --git a/examples/guided.py b/examples/guided.py index 91dd1ddc..d23c483e 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -412,6 +412,9 @@ else: # Temporarily disabling keep_partitions if config file is loaded archinstall.arguments['harddrive'].keep_partitions = False # Temporary workaround to make Desktop Environments work - archinstall.arguments['profile'] = archinstall.Profile(None, archinstall.arguments.get('profile', None)) + if archinstall.arguments.get('profile', None) is not None: + archinstall.arguments['profile'] = archinstall.Profile(None, archinstall.arguments.get('profile', None)) + else: + archinstall.arguments['profile'] = None perform_installation_steps() -- cgit v1.2.3-70-g09d2