From 4ff35663b80e1bb40c44d4ceee85700ef428cab0 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 12 May 2021 13:55:41 +0200 Subject: Replaced the magic __builtin__ global variable. This should fix mypy complaints while still retaining the same functionality, kinda. It's less automatic but it's also less of dark magic, which makes sense for anyone but me. --- profiles/awesome.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'profiles/awesome.py') diff --git a/profiles/awesome.py b/profiles/awesome.py index a5dedccd..8ee113f4 100644 --- a/profiles/awesome.py +++ b/profiles/awesome.py @@ -30,23 +30,23 @@ def _prep_function(*args, **kwargs): # or through conventional import awesome if __name__ == 'awesome': # Install the application awesome from the template under /applications/ - awesome = archinstall.Application(installation, 'awesome') + awesome = archinstall.Application(archinstall.storage['installation_session'], 'awesome') awesome.install() - installation.add_additional_packages(__packages__) + archinstall.storage['installation_session'].add_additional_packages(__packages__) # TODO: Copy a full configuration to ~/.config/awesome/rc.lua instead. - with open(f'{installation.target}/etc/xdg/awesome/rc.lua', 'r') as fh: + with open(f'{archinstall.storage['installation_session'].target}/etc/xdg/awesome/rc.lua', 'r') as fh: awesome_lua = fh.read() ## Replace xterm with alacritty for a smoother experience. awesome_lua = awesome_lua.replace('"xterm"', '"alacritty"') - with open(f'{installation.target}/etc/xdg/awesome/rc.lua', 'w') as fh: + with open(f'{archinstall.storage['installation_session'].target}/etc/xdg/awesome/rc.lua', 'w') as fh: fh.write(awesome_lua) ## TODO: Configure the right-click-menu to contain the above packages that were installed. (as a user config) ## Remove some interfering nemo settings - installation.arch_chroot("gsettings set org.nemo.desktop show-desktop-icons false") - installation.arch_chroot("xdg-mime default nemo.desktop inode/directory application/x-gnome-saved-search") + archinstall.storage['installation_session'].arch_chroot("gsettings set org.nemo.desktop show-desktop-icons false") + archinstall.storage['installation_session'].arch_chroot("xdg-mime default nemo.desktop inode/directory application/x-gnome-saved-search") -- cgit v1.2.3-70-g09d2 From 22750cefc89e6439d14a5df105af17e4e85eb3cc Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 14 May 2021 16:55:47 +0200 Subject: Quotation error. --- profiles/awesome.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'profiles/awesome.py') diff --git a/profiles/awesome.py b/profiles/awesome.py index 8ee113f4..7b305eb2 100644 --- a/profiles/awesome.py +++ b/profiles/awesome.py @@ -36,13 +36,13 @@ if __name__ == 'awesome': archinstall.storage['installation_session'].add_additional_packages(__packages__) # TODO: Copy a full configuration to ~/.config/awesome/rc.lua instead. - with open(f'{archinstall.storage['installation_session'].target}/etc/xdg/awesome/rc.lua', 'r') as fh: + with open(f"{archinstall.storage['installation_session'].target}/etc/xdg/awesome/rc.lua", 'r') as fh: awesome_lua = fh.read() ## Replace xterm with alacritty for a smoother experience. awesome_lua = awesome_lua.replace('"xterm"', '"alacritty"') - with open(f'{archinstall.storage['installation_session'].target}/etc/xdg/awesome/rc.lua', 'w') as fh: + with open(f"{archinstall.storage['installation_session'].target}/etc/xdg/awesome/rc.lua", 'w') as fh: fh.write(awesome_lua) ## TODO: Configure the right-click-menu to contain the above packages that were installed. (as a user config) -- cgit v1.2.3-70-g09d2 From 5c6019124a2645b57cf2d51964e6720ec1d6bab7 Mon Sep 17 00:00:00 2001 From: Marcus Pereira Date: Sat, 15 May 2021 08:29:25 -0300 Subject: rename package name --- profiles/awesome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'profiles/awesome.py') diff --git a/profiles/awesome.py b/profiles/awesome.py index 7b305eb2..ee812eb3 100644 --- a/profiles/awesome.py +++ b/profiles/awesome.py @@ -6,7 +6,7 @@ is_top_level_profile = False # New way of defining packages for a profile, which is iterable and can be used out side # of the profile to get a list of "what packages will be installed". -__packages__ = ['nemo', 'gpicview-gtk3', 'main', 'alacritty'] +__packages__ = ['nemo', 'gpicview', 'main', 'alacritty'] def _prep_function(*args, **kwargs): """ -- cgit v1.2.3-70-g09d2 From ffd5b5f80453a609b76e050d6d4e8309c540c28e Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Sat, 15 May 2021 11:35:18 -0400 Subject: Very selectively fix some PEP 8 issues with profiles --- profiles/52-54-00-12-34-56.py | 4 ++-- profiles/applications/postgresql.py | 2 +- profiles/awesome.py | 3 ++- profiles/budgie.py | 6 ++++-- profiles/cinnamon.py | 15 +++++++++++-- profiles/deepin.py | 1 + profiles/desktop.py | 42 ++++++++++++++++++++++++++++++------- profiles/enlightenment.py | 1 + profiles/gnome.py | 4 +++- profiles/i3.py | 9 +++++--- profiles/kde.py | 2 ++ profiles/lxqt.py | 5 +++-- profiles/mate.py | 4 +++- profiles/minimal.py | 4 +++- profiles/server.py | 4 +++- profiles/sway.py | 4 +--- profiles/xfce4.py | 5 +++-- profiles/xorg.py | 1 + 18 files changed, 86 insertions(+), 30 deletions(-) (limited to 'profiles/awesome.py') diff --git a/profiles/52-54-00-12-34-56.py b/profiles/52-54-00-12-34-56.py index 28cd14f6..d4fc3d07 100644 --- a/profiles/52-54-00-12-34-56.py +++ b/profiles/52-54-00-12-34-56.py @@ -7,7 +7,7 @@ __packages__ = ['nano', 'wget', 'git'] if __name__ == '52-54-00-12-34-56': awesome = archinstall.Application(archinstall.storage['installation_session'], 'postgresql') awesome.install() - + """ # Unmount and close previous runs (Mainly only used for re-runs, but won't hurt.) archinstall.sys_command(f'umount -R /mnt', suppress_errors=True) @@ -57,4 +57,4 @@ with archinstall.Filesystem(harddrive) as fs: urllib.request.urlopen(req, timeout=5) except: pass -""" \ No newline at end of file +""" diff --git a/profiles/applications/postgresql.py b/profiles/applications/postgresql.py index 3f8c6950..29546d78 100644 --- a/profiles/applications/postgresql.py +++ b/profiles/applications/postgresql.py @@ -8,4 +8,4 @@ archinstall.storage['installation_session'].add_additional_packages(__packages__ archinstall.storage['installation_session'].arch_chroot("initdb -D /var/lib/postgres/data", runas='postgres') -archinstall.storage['installation_session'].enable_service('postgresql') \ No newline at end of file +archinstall.storage['installation_session'].enable_service('postgresql') diff --git a/profiles/awesome.py b/profiles/awesome.py index ee812eb3..62cb9e00 100644 --- a/profiles/awesome.py +++ b/profiles/awesome.py @@ -8,6 +8,7 @@ is_top_level_profile = False # of the profile to get a list of "what packages will be installed". __packages__ = ['nemo', 'gpicview', 'main', 'alacritty'] + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer @@ -46,7 +47,7 @@ if __name__ == 'awesome': fh.write(awesome_lua) ## TODO: Configure the right-click-menu to contain the above packages that were installed. (as a user config) - + ## Remove some interfering nemo settings archinstall.storage['installation_session'].arch_chroot("gsettings set org.nemo.desktop show-desktop-icons false") archinstall.storage['installation_session'].arch_chroot("xdg-mime default nemo.desktop inode/directory application/x-gnome-saved-search") diff --git a/profiles/budgie.py b/profiles/budgie.py index dbbd3a9d..abaf87b0 100644 --- a/profiles/budgie.py +++ b/profiles/budgie.py @@ -4,9 +4,10 @@ import archinstall is_top_level_profile = False -# "It is recommended also to install the gnome group, which contains applications required for the standard GNOME experience." - Arch Wiki +# "It is recommended also to install the gnome group, which contains applications required for the standard GNOME experience." - Arch Wiki __packages__ = ["budgie-desktop", "lightdm", "lightdm-gtk-greeter", "gnome"] + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer @@ -23,6 +24,7 @@ def _prep_function(*args, **kwargs): else: print('Deprecated (??): xorg profile has no _prep_function() anymore') + # Ensures that this code only gets executed if executed # through importlib.util.spec_from_file_location("budgie", "/somewhere/budgie.py") # or through conventional import budgie @@ -33,4 +35,4 @@ if __name__ == 'budgie': # Install the Budgie packages archinstall.storage['installation_session'].add_additional_packages(__packages__) - archinstall.storage['installation_session'].enable_service('lightdm') # Light Display Manager + archinstall.storage['installation_session'].enable_service('lightdm') # Light Display Manager diff --git a/profiles/cinnamon.py b/profiles/cinnamon.py index 89798671..0122677a 100644 --- a/profiles/cinnamon.py +++ b/profiles/cinnamon.py @@ -4,7 +4,17 @@ import archinstall is_top_level_profile = False -__packages__ = ["cinnamon", "system-config-printer", "gnome-keyring", "gnome-terminal", "blueberry", "metacity", "lightdm", "lightdm-gtk-greeter"] +__packages__ = [ + "cinnamon", + "system-config-printer", + "gnome-keyring", + "gnome-terminal", + "blueberry", + "metacity", + "lightdm", + "lightdm-gtk-greeter", +] + def _prep_function(*args, **kwargs): """ @@ -22,6 +32,7 @@ def _prep_function(*args, **kwargs): else: print('Deprecated (??): xorg profile has no _prep_function() anymore') + # Ensures that this code only gets executed if executed # through importlib.util.spec_from_file_location("cinnamon", "/somewhere/cinnamon.py") # or through conventional import cinnamon @@ -32,4 +43,4 @@ if __name__ == 'cinnamon': # Install the Cinnamon packages archinstall.storage['installation_session'].add_additional_packages(__packages__) - archinstall.storage['installation_session'].enable_service('lightdm') # Light Display Manager + archinstall.storage['installation_session'].enable_service('lightdm') # Light Display Manager diff --git a/profiles/deepin.py b/profiles/deepin.py index 757597f3..a4778b0d 100644 --- a/profiles/deepin.py +++ b/profiles/deepin.py @@ -6,6 +6,7 @@ is_top_level_profile = False __packages__ = ["deepin", "deepin-terminal", "deepin-editor", "lightdm", "lightdm-gtk-greeter"] + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer diff --git a/profiles/desktop.py b/profiles/desktop.py index 9e1d8b4c..84c1ac06 100644 --- a/profiles/desktop.py +++ b/profiles/desktop.py @@ -6,7 +6,19 @@ is_top_level_profile = True # New way of defining packages for a profile, which is iterable and can be used out side # of the profile to get a list of "what packages will be installed". -__packages__ = ['nano', 'vim', 'openssh', 'htop', 'wget', 'iwd', 'wireless_tools', 'wpa_supplicant', 'smartmontools', 'xdg-utils'] +__packages__ = [ + 'nano', + 'vim', + 'openssh', + 'htop', + 'wget', + 'iwd', + 'wireless_tools', + 'wpa_supplicant', + 'smartmontools', + 'xdg-utils', +] + def _prep_function(*args, **kwargs): """ @@ -16,11 +28,25 @@ def _prep_function(*args, **kwargs): for more input before any other installer steps start. """ - supported_desktops = ['gnome', 'kde', 'awesome', 'sway', 'cinnamon', 'xfce4', 'lxqt', 'i3', 'budgie', 'mate', 'deepin', 'enlightenment'] + supported_desktops = [ + 'gnome', + 'kde', + 'awesome', + 'sway', + 'cinnamon', + 'xfce4', + 'lxqt', + 'i3', + 'budgie', + 'mate', + 'deepin', + 'enlightenment', + ] + + desktop = archinstall.generic_select( + supported_desktops, 'Select your desired desktop environment: ', allow_empty_input=False, sort=True + ) - desktop = archinstall.generic_select(supported_desktops, 'Select your desired desktop environment: ', - allow_empty_input=False, sort=True) - # Temporarily store the selected desktop profile # in a session-safe location, since this module will get reloaded # the next time it gets executed. @@ -34,6 +60,7 @@ def _prep_function(*args, **kwargs): else: print(f"Deprecated (??): {desktop} profile has no _prep_function() anymore") + if __name__ == 'desktop': """ This "profile" is a meta-profile. @@ -47,9 +74,8 @@ if __name__ == 'desktop': There are plenty of desktop-turn-key-solutions based on Arch Linux, this is therefore just a helper to get started """ - + # Install common packages for all desktop environments archinstall.storage['installation_session'].add_additional_packages(__packages__) - - archinstall.storage['installation_session'].install_profile(archinstall.storage['_desktop_profile']) + archinstall.storage['installation_session'].install_profile(archinstall.storage['_desktop_profile']) diff --git a/profiles/enlightenment.py b/profiles/enlightenment.py index 6ff334de..4c5a7999 100644 --- a/profiles/enlightenment.py +++ b/profiles/enlightenment.py @@ -6,6 +6,7 @@ is_top_level_profile = False __packages__ = ["enlightenment", "terminology", "lightdm", "lightdm-gtk-greeter"] + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer diff --git a/profiles/gnome.py b/profiles/gnome.py index e6cc75c0..09fac1bb 100644 --- a/profiles/gnome.py +++ b/profiles/gnome.py @@ -7,6 +7,7 @@ is_top_level_profile = False # Note: GDM should be part of the gnome group, but adding it here for clarity __packages__ = ["gnome", "gnome-tweaks", "gdm"] + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer @@ -24,6 +25,7 @@ def _prep_function(*args, **kwargs): else: print('Deprecated (??): xorg profile has no _prep_function() anymore') + # Ensures that this code only gets executed if executed # through importlib.util.spec_from_file_location("gnome", "/somewhere/gnome.py") # or through conventional import gnome @@ -34,6 +36,6 @@ if __name__ == 'gnome': # Install the GNOME packages archinstall.storage['installation_session'].add_additional_packages(__packages__) - archinstall.storage['installation_session'].enable_service('gdm') # Gnome Display Manager + archinstall.storage['installation_session'].enable_service('gdm') # Gnome Display Manager # We could also start it via xinitrc since we do have Xorg, # but for gnome that's deprecated and wayland is preferred. diff --git a/profiles/i3.py b/profiles/i3.py index e99bc549..1972ba59 100644 --- a/profiles/i3.py +++ b/profiles/i3.py @@ -8,6 +8,7 @@ is_top_level_profile = False # of the profile to get a list of "what packages will be installed". __packages__ = ['i3lock', 'i3status', 'i3blocks', 'xterm', 'lightdm-gtk-greeter', 'lightdm', 'dmenu'] + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer @@ -17,8 +18,9 @@ def _prep_function(*args, **kwargs): """ supported_configurations = ['i3-wm', 'i3-gaps'] - desktop = archinstall.generic_select(supported_configurations, 'Select your desired configuration: ', - allow_empty_input=False, sort=True) + desktop = archinstall.generic_select( + supported_configurations, 'Select your desired configuration: ', allow_empty_input=False, sort=True + ) # Temporarily store the selected desktop profile # in a session-safe location, since this module will get reloaded @@ -33,6 +35,7 @@ def _prep_function(*args, **kwargs): else: print('Deprecated (??): xorg profile has no _prep_function() anymore') + if __name__ == 'i3': """ This "profile" is a meta-profile. @@ -46,7 +49,7 @@ if __name__ == 'i3': There are plenty of desktop-turn-key-solutions based on Arch Linux, this is therefore just a helper to get started """ - + # Install common packages for all i3 configurations archinstall.storage['installation_session'].add_additional_packages(__packages__[:4]) diff --git a/profiles/kde.py b/profiles/kde.py index aac5ade4..66625074 100644 --- a/profiles/kde.py +++ b/profiles/kde.py @@ -8,6 +8,7 @@ __packages__ = ["plasma-meta", "konsole", "kate", "dolphin", "sddm", "plasma-way # TODO: Remove hard dependency of bash (due to .bash_profile) + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer @@ -24,6 +25,7 @@ def _prep_function(*args, **kwargs): else: print('Deprecated (??): xorg profile has no _prep_function() anymore') + """ def _post_install(*args, **kwargs): if "nvidia" in _gfx_driver_packages: diff --git a/profiles/lxqt.py b/profiles/lxqt.py index 025d033d..af6337e6 100644 --- a/profiles/lxqt.py +++ b/profiles/lxqt.py @@ -1,4 +1,3 @@ - # A desktop environment using "LXQt" import archinstall @@ -7,6 +6,7 @@ is_top_level_profile = False __packages__ = ["lxqt", "breeze-icons", "oxygen-icons", "xdg-utils", "ttf-freefont", "leafpad", "slock", "sddm"] + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer @@ -23,6 +23,7 @@ def _prep_function(*args, **kwargs): else: print('Deprecated (??): xorg profile has no _prep_function() anymore') + # Ensures that this code only gets executed if executed # through importlib.util.spec_from_file_location("lxqt", "/somewhere/lxqt.py") # or through conventional import lxqt @@ -33,4 +34,4 @@ if __name__ == 'lxqt': # Install the LXQt packages archinstall.storage['installation_session'].add_additional_packages(__packages__) - archinstall.storage['installation_session'].enable_service('sddm') # SDDM Display Manager + archinstall.storage['installation_session'].enable_service('sddm') # SDDM Display Manager diff --git a/profiles/mate.py b/profiles/mate.py index e2421ed8..351f2250 100644 --- a/profiles/mate.py +++ b/profiles/mate.py @@ -6,6 +6,7 @@ is_top_level_profile = False __packages__ = ["mate", "mate-extra", "lightdm", "lightdm-gtk-greeter"] + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer @@ -22,6 +23,7 @@ def _prep_function(*args, **kwargs): else: print('Deprecated (??): xorg profile has no _prep_function() anymore') + # Ensures that this code only gets executed if executed # through importlib.util.spec_from_file_location("mate", "/somewhere/mate.py") # or through conventional import mate @@ -32,4 +34,4 @@ if __name__ == 'mate': # Install the MATE packages archinstall.storage['installation_session'].add_additional_packages(__packages__) - archinstall.storage['installation_session'].enable_service('lightdm') # Light Display Manager + archinstall.storage['installation_session'].enable_service('lightdm') # Light Display Manager diff --git a/profiles/minimal.py b/profiles/minimal.py index 79821a89..8af06a3a 100644 --- a/profiles/minimal.py +++ b/profiles/minimal.py @@ -4,6 +4,7 @@ import archinstall, os is_top_level_profile = True + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer @@ -11,7 +12,8 @@ def _prep_function(*args, **kwargs): we don't need to do anything special here, but it needs to exist and return True. """ - return True # Do nothing and just return True + return True # Do nothing and just return True + if __name__ == 'minimal': """ diff --git a/profiles/server.py b/profiles/server.py index d0346ace..36bfd3ab 100644 --- a/profiles/server.py +++ b/profiles/server.py @@ -6,6 +6,7 @@ is_top_level_profile = True available_servers = ["cockpit", "docker", "httpd", "lighttpd", "mariadb", "nginx", "postgresql", "sshd", "tomcat"] + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer @@ -13,9 +14,10 @@ def _prep_function(*args, **kwargs): """ selected_servers = archinstall.generic_multi_select(available_servers, f"Choose which servers to install and enable (leave blank for a minimal installation): ") archinstall.storage['_selected_servers'] = selected_servers - + return True + if __name__ == 'server': """ This "profile" is a meta-profile. diff --git a/profiles/sway.py b/profiles/sway.py index e90e5e8d..686fe868 100644 --- a/profiles/sway.py +++ b/profiles/sway.py @@ -39,9 +39,7 @@ if __name__ == "sway": "The proprietary Nvidia driver is not supported by Sway. It is likely that you will run into issues. Continue anyways? [y/N] " ) if choice.lower() in ("n", ""): - raise archinstall.lib.exceptions.HardwareIncompatibilityError( - "Sway does not support the proprietary nvidia drivers." - ) + raise archinstall.lib.exceptions.HardwareIncompatibilityError("Sway does not support the proprietary nvidia drivers.") # Install the Sway packages archinstall.storage['installation_session'].add_additional_packages(__packages__) diff --git a/profiles/xfce4.py b/profiles/xfce4.py index 43da23ac..ad00c461 100644 --- a/profiles/xfce4.py +++ b/profiles/xfce4.py @@ -1,4 +1,3 @@ - # A desktop environment using "Xfce4" import archinstall @@ -7,6 +6,7 @@ is_top_level_profile = False __packages__ = ["xfce4", "xfce4-goodies", "lightdm", "lightdm-gtk-greeter"] + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer @@ -23,6 +23,7 @@ def _prep_function(*args, **kwargs): else: print('Deprecated (??): xorg profile has no _prep_function() anymore') + # Ensures that this code only gets executed if executed # through importlib.util.spec_from_file_location("xfce4", "/somewhere/xfce4.py") # or through conventional import xfce4 @@ -33,4 +34,4 @@ if __name__ == 'xfce4': # Install the XFCE4 packages archinstall.storage['installation_session'].add_additional_packages(__packages__) - archinstall.storage['installation_session'].enable_service('lightdm') # Light Display Manager + archinstall.storage['installation_session'].enable_service('lightdm') # Light Display Manager diff --git a/profiles/xorg.py b/profiles/xorg.py index 19ca92d7..e7cf00d0 100644 --- a/profiles/xorg.py +++ b/profiles/xorg.py @@ -7,6 +7,7 @@ is_top_level_profile = True __packages__ = ['dkms', 'xorg-server', 'xorg-xinit', 'nvidia-dkms', 'xorg-server', *archinstall.lib.hardware.__packages__] + def _prep_function(*args, **kwargs): """ Magic function called by the importing installer -- cgit v1.2.3-70-g09d2 From 37e818b3d1a7b76d1bdc511876a2a30d7a7a32d1 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Sat, 15 May 2021 12:07:46 -0400 Subject: More manual fixes --- examples/guided.py | 36 +++++++++++++++++------------------- examples/minimal.py | 8 +++++--- examples/unattended.py | 2 +- profiles/52-54-00-12-34-56.py | 6 +++--- profiles/awesome.py | 6 +++--- 5 files changed, 29 insertions(+), 29 deletions(-) (limited to 'profiles/awesome.py') diff --git a/examples/guided.py b/examples/guided.py index 0ae253a0..b96c5793 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -10,11 +10,12 @@ if archinstall.arguments.get('help'): # For support reasons, we'll log the disk layout pre installation to match against post-installation layout archinstall.log(f"Disk states before installing: {archinstall.disk_layouts()}", level=archinstall.LOG_LEVELS.Debug) + def ask_user_questions(): """ - First, we'll ask the user for a bunch of user input. - Not until we're satisfied with what we want to install - will we continue with the actual installation steps. + First, we'll ask the user for a bunch of user input. + 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-language', None): while True: @@ -41,7 +42,6 @@ def ask_user_questions(): selected_region = archinstall.arguments['mirror-region'] archinstall.arguments['mirror-region'] = {selected_region : archinstall.list_mirrors()[selected_region]} - # Ask which harddrive/block-device we will install to if archinstall.arguments.get('harddrive', None): archinstall.arguments['harddrive'] = archinstall.BlockDevice(archinstall.arguments['harddrive']) @@ -67,7 +67,6 @@ def ask_user_questions(): partition_mountpoints[partition] = None except archinstall.UnknownFilesystemFormat as err: archinstall.log(f" {partition} (Filesystem not supported)", fg='red') - # We then ask what to do with the partitions. if (option := archinstall.ask_for_disk_layout()) == 'abort': @@ -122,8 +121,7 @@ def ask_user_questions(): archinstall.log(f"Until then, please enter another supported filesystem.") continue except archinstall.SysCallError: - pass # Expected exception since mkfs. can not format /dev/null. - # But that means our .format() function supported it. + pass # Expected exception since mkfs. can not format /dev/null. But that means our .format() function supported it. break # When we've selected all three criteria, @@ -151,7 +149,7 @@ def ask_user_questions(): # Get disk encryption password (or skip if blank) if archinstall.arguments['harddrive'] and archinstall.arguments.get('!encryption-password', None) is None: - if (passwd := archinstall.get_password(prompt='Enter disk encryption password (leave blank for no encryption): ')): + if passwd := archinstall.get_password(prompt='Enter disk encryption password (leave blank for no encryption): '): archinstall.arguments['!encryption-password'] = passwd archinstall.arguments['harddrive'].encryption_password = archinstall.arguments['!encryption-password'] archinstall.arguments["bootloader"] = archinstall.ask_for_bootloader() @@ -191,7 +189,7 @@ def ask_user_questions(): # Ask about audio server selection if one is not already set if not archinstall.arguments.get('audio', None): - # only ask for audio server selection on a desktop profile + # only ask for audio server selection on a desktop profile if str(archinstall.arguments['profile']) == 'Profile(desktop)': archinstall.arguments['audio'] = archinstall.ask_for_audio_selection() else: @@ -264,12 +262,12 @@ def perform_installation_steps(): # Wipe the entire drive if the disk flag `keep_partitions`is False. if archinstall.arguments['harddrive'].keep_partitions is False: fs.use_entire_disk(root_filesystem_type=archinstall.arguments.get('filesystem', 'btrfs')) - + # Check if encryption is desired and mark the root partition as encrypted. if archinstall.arguments.get('!encryption-password', None): root_partition = fs.find_partition('/') root_partition.encrypted = True - + # After the disk is ready, iterate the partitions and check # which ones are safe to format, and format those. for partition in archinstall.arguments['harddrive']: @@ -293,10 +291,10 @@ def perform_installation_steps(): unlocked_device.mount('/mnt') else: fs.find_partition('/').mount('/mnt') - + if hasUEFI(): fs.find_partition('/boot').mount('/mnt/boot') - + perform_installation('/mnt') @@ -307,7 +305,7 @@ def perform_installation(mountpoint): formatted and setup prior to entering this function. """ with archinstall.Installer(mountpoint, kernels=archinstall.arguments.get('kernels', 'linux')) as installation: - ## if len(mirrors): + # if len(mirrors): # Certain services might be running that affects the system during installation. # Currently, only one such service is "reflector.service" which updates /etc/pacman.d/mirrorlist # We need to wait for it before we continue since we opted in to use a custom mirror/region. @@ -319,7 +317,7 @@ def perform_installation(mountpoint): archinstall.use_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors for the live medium if installation.minimal_installation(): installation.set_hostname(archinstall.arguments['hostname']) - if archinstall.arguments['mirror-region'].get("mirrors",{})!= None: + if archinstall.arguments['mirror-region'].get("mirrors", {}) is not None: installation.set_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors in the installation medium if archinstall.arguments["bootloader"]=="grub-install" and hasUEFI()==True: installation.add_additional_packages("grub") @@ -339,7 +337,7 @@ def perform_installation(mountpoint): installation.enable_service('systemd-networkd') installation.enable_service('systemd-resolved') - if archinstall.arguments.get('audio', None) != None: + if archinstall.arguments.get('audio', None) is not None: installation.log(f"This audio server will be used: {archinstall.arguments.get('audio', None)}", level=logging.INFO) if archinstall.arguments.get('audio', None) == 'pipewire': print('Installing pipewire ...') @@ -350,7 +348,7 @@ def perform_installation(mountpoint): installation.add_additional_packages("pulseaudio") else: installation.log("No audio server will be installed.", level=logging.INFO) - + if archinstall.arguments.get('packages', None) and archinstall.arguments.get('packages', None)[0] != '': installation.add_additional_packages(archinstall.arguments.get('packages', None)) @@ -363,7 +361,7 @@ def perform_installation(mountpoint): for superuser, user_info in archinstall.arguments.get('superusers', {}).items(): installation.user_create(superuser, user_info["!password"], sudo=True) - if (timezone := archinstall.arguments.get('timezone', None)): + if timezone := archinstall.arguments.get('timezone', None): installation.set_timezone(timezone) if (root_pw := archinstall.arguments.get('!root-password', None)) and len(root_pw): @@ -390,4 +388,4 @@ def perform_installation(mountpoint): archinstall.log(f"Disk states after installing: {archinstall.disk_layouts()}", level=archinstall.LOG_LEVELS.Debug) ask_user_questions() -perform_installation_steps() \ No newline at end of file +perform_installation_steps() diff --git a/examples/minimal.py b/examples/minimal.py index 98d9a6f0..efd66ab7 100644 --- a/examples/minimal.py +++ b/examples/minimal.py @@ -11,8 +11,9 @@ if archinstall.arguments.get('help', None): archinstall.arguments['harddrive'] = archinstall.select_disk(archinstall.all_disks()) + def install_on(mountpoint): - # We kick off the installer by telling it where the + # We kick off the installer by telling it where the with archinstall.Installer(mountpoint) as installation: # Strap in the base system, add a boot loader and configure # some other minor details as specified by this profile and user. @@ -36,9 +37,10 @@ def install_on(mountpoint): archinstall.log(f" * root (password: airoot)") archinstall.log(f" * devel (password: devel)") + if archinstall.arguments['harddrive']: archinstall.arguments['harddrive'].keep_partitions = False - + print(f" ! Formatting {archinstall.arguments['harddrive']} in ", end='') archinstall.do_countdown() @@ -68,4 +70,4 @@ if archinstall.arguments['harddrive']: boot.mount('/mnt/boot') -install_on('/mnt') \ No newline at end of file +install_on('/mnt') diff --git a/examples/unattended.py b/examples/unattended.py index 679fbdf6..b0e52f20 100644 --- a/examples/unattended.py +++ b/examples/unattended.py @@ -17,4 +17,4 @@ for name, info in archinstall.list_profiles().items(): profile = archinstall.Profile(None, info['path']) profile.install() - break \ No newline at end of file + break diff --git a/profiles/52-54-00-12-34-56.py b/profiles/52-54-00-12-34-56.py index d4fc3d07..758a4cc2 100644 --- a/profiles/52-54-00-12-34-56.py +++ b/profiles/52-54-00-12-34-56.py @@ -1,6 +1,6 @@ import archinstall -import json -import urllib.request +# import json +# import urllib.request __packages__ = ['nano', 'wget', 'git'] @@ -27,7 +27,7 @@ with archinstall.Filesystem(harddrive) as fs: 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], diff --git a/profiles/awesome.py b/profiles/awesome.py index 62cb9e00..aa4702a6 100644 --- a/profiles/awesome.py +++ b/profiles/awesome.py @@ -40,14 +40,14 @@ if __name__ == 'awesome': with open(f"{archinstall.storage['installation_session'].target}/etc/xdg/awesome/rc.lua", 'r') as fh: awesome_lua = fh.read() - ## Replace xterm with alacritty for a smoother experience. + # Replace xterm with alacritty for a smoother experience. awesome_lua = awesome_lua.replace('"xterm"', '"alacritty"') with open(f"{archinstall.storage['installation_session'].target}/etc/xdg/awesome/rc.lua", 'w') as fh: fh.write(awesome_lua) - ## TODO: Configure the right-click-menu to contain the above packages that were installed. (as a user config) + # TODO: Configure the right-click-menu to contain the above packages that were installed. (as a user config) - ## Remove some interfering nemo settings + # Remove some interfering nemo settings archinstall.storage['installation_session'].arch_chroot("gsettings set org.nemo.desktop show-desktop-icons false") archinstall.storage['installation_session'].arch_chroot("xdg-mime default nemo.desktop inode/directory application/x-gnome-saved-search") -- cgit v1.2.3-70-g09d2 From 3ee38afce1d8f3680245293f8f97353054afd52a Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Sat, 15 May 2021 17:28:27 -0400 Subject: One package per line formatting in profiles - easier to read/maintain --- profiles/applications/awesome.py | 12 +++++++++++- profiles/awesome.py | 7 ++++++- profiles/budgie.py | 7 ++++++- profiles/deepin.py | 8 +++++++- profiles/enlightenment.py | 7 ++++++- profiles/gnome.py | 6 +++++- profiles/i3.py | 10 +++++++++- profiles/kde.py | 10 +++++++++- profiles/lxqt.py | 11 ++++++++++- profiles/server.py | 12 +++++++++++- profiles/xorg.py | 9 ++++++++- 11 files changed, 88 insertions(+), 11 deletions(-) (limited to 'profiles/awesome.py') diff --git a/profiles/applications/awesome.py b/profiles/applications/awesome.py index d5a8e793..33526fd7 100644 --- a/profiles/applications/awesome.py +++ b/profiles/applications/awesome.py @@ -1,6 +1,16 @@ import archinstall -__packages__ = ["awesome", "xorg-xrandr", "xterm", "feh", "slock", "terminus-font", "gnu-free-fonts", "ttf-liberation", "xsel"] +__packages__ = [ + "awesome", + "xorg-xrandr", + "xterm", + "feh", + "slock", + "terminus-font", + "gnu-free-fonts", + "ttf-liberation", + "xsel", +] archinstall.storage['installation_session'].install_profile('xorg') diff --git a/profiles/awesome.py b/profiles/awesome.py index aa4702a6..0c1b20ea 100644 --- a/profiles/awesome.py +++ b/profiles/awesome.py @@ -6,7 +6,12 @@ is_top_level_profile = False # New way of defining packages for a profile, which is iterable and can be used out side # of the profile to get a list of "what packages will be installed". -__packages__ = ['nemo', 'gpicview', 'main', 'alacritty'] +__packages__ = [ + "nemo", + "gpicview", + "main", + "alacritty", +] def _prep_function(*args, **kwargs): diff --git a/profiles/budgie.py b/profiles/budgie.py index abaf87b0..3e4a85df 100644 --- a/profiles/budgie.py +++ b/profiles/budgie.py @@ -5,7 +5,12 @@ import archinstall is_top_level_profile = False # "It is recommended also to install the gnome group, which contains applications required for the standard GNOME experience." - Arch Wiki -__packages__ = ["budgie-desktop", "lightdm", "lightdm-gtk-greeter", "gnome"] +__packages__ = [ + "budgie-desktop", + "gnome", + "lightdm", + "lightdm-gtk-greeter", +] def _prep_function(*args, **kwargs): diff --git a/profiles/deepin.py b/profiles/deepin.py index ebe730e2..5bc18285 100644 --- a/profiles/deepin.py +++ b/profiles/deepin.py @@ -4,7 +4,13 @@ import archinstall is_top_level_profile = False -__packages__ = ["deepin", "deepin-terminal", "deepin-editor", "lightdm", "lightdm-gtk-greeter"] +__packages__ = [ + "deepin", + "deepin-terminal", + "deepin-editor", + "lightdm", + "lightdm-gtk-greeter", +] def _prep_function(*args, **kwargs): diff --git a/profiles/enlightenment.py b/profiles/enlightenment.py index cfb97836..3850fed0 100644 --- a/profiles/enlightenment.py +++ b/profiles/enlightenment.py @@ -4,7 +4,12 @@ import archinstall is_top_level_profile = False -__packages__ = ["enlightenment", "terminology", "lightdm", "lightdm-gtk-greeter"] +__packages__ = [ + "enlightenment", + "terminology", + "lightdm", + "lightdm-gtk-greeter", +] def _prep_function(*args, **kwargs): diff --git a/profiles/gnome.py b/profiles/gnome.py index 7bf5b7fd..1b3bf327 100644 --- a/profiles/gnome.py +++ b/profiles/gnome.py @@ -5,7 +5,11 @@ import archinstall is_top_level_profile = False # Note: GDM should be part of the gnome group, but adding it here for clarity -__packages__ = ["gnome", "gnome-tweaks", "gdm"] +__packages__ = [ + "gnome", + "gnome-tweaks", + "gdm", +] def _prep_function(*args, **kwargs): diff --git a/profiles/i3.py b/profiles/i3.py index c25003f9..b26745a1 100644 --- a/profiles/i3.py +++ b/profiles/i3.py @@ -6,7 +6,15 @@ is_top_level_profile = False # New way of defining packages for a profile, which is iterable and can be used out side # of the profile to get a list of "what packages will be installed". -__packages__ = ['i3lock', 'i3status', 'i3blocks', 'xterm', 'lightdm-gtk-greeter', 'lightdm', 'dmenu'] +__packages__ = [ + 'i3lock', + 'i3status', + 'i3blocks', + 'xterm', + 'lightdm-gtk-greeter', + 'lightdm', + 'dmenu', +] def _prep_function(*args, **kwargs): diff --git a/profiles/kde.py b/profiles/kde.py index 451704b9..c58f4f45 100644 --- a/profiles/kde.py +++ b/profiles/kde.py @@ -4,7 +4,15 @@ import archinstall is_top_level_profile = False -__packages__ = ["plasma-meta", "konsole", "kate", "dolphin", "sddm", "plasma-wayland-session", "egl-wayland"] +__packages__ = [ + "plasma-meta", + "konsole", + "kate", + "dolphin", + "sddm", + "plasma-wayland-session", + "egl-wayland", +] # TODO: Remove hard dependency of bash (due to .bash_profile) diff --git a/profiles/lxqt.py b/profiles/lxqt.py index af6337e6..a241353a 100644 --- a/profiles/lxqt.py +++ b/profiles/lxqt.py @@ -4,7 +4,16 @@ import archinstall is_top_level_profile = False -__packages__ = ["lxqt", "breeze-icons", "oxygen-icons", "xdg-utils", "ttf-freefont", "leafpad", "slock", "sddm"] +__packages__ = [ + "lxqt", + "breeze-icons", + "oxygen-icons", + "xdg-utils", + "ttf-freefont", + "leafpad", + "slock", + "sddm", +] def _prep_function(*args, **kwargs): diff --git a/profiles/server.py b/profiles/server.py index 355be9f5..704c8efe 100644 --- a/profiles/server.py +++ b/profiles/server.py @@ -6,7 +6,17 @@ import archinstall is_top_level_profile = True -available_servers = ["cockpit", "docker", "httpd", "lighttpd", "mariadb", "nginx", "postgresql", "sshd", "tomcat"] +available_servers = [ + "cockpit", + "docker", + "httpd", + "lighttpd", + "mariadb", + "nginx", + "postgresql", + "sshd", + "tomcat", +] def _prep_function(*args, **kwargs): diff --git a/profiles/xorg.py b/profiles/xorg.py index e18a4f03..b8fb2cbb 100644 --- a/profiles/xorg.py +++ b/profiles/xorg.py @@ -4,7 +4,14 @@ import archinstall is_top_level_profile = True -__packages__ = ['dkms', 'xorg-server', 'xorg-xinit', 'nvidia-dkms', 'xorg-server', *archinstall.lib.hardware.__packages__] +__packages__ = [ + 'dkms', + 'xorg-server', + 'xorg-xinit', + 'nvidia-dkms', + 'xorg-server', + *archinstall.lib.hardware.__packages__, +] def _prep_function(*args, **kwargs): -- cgit v1.2.3-70-g09d2 From 49e6cbdc545402e066bdc2daf6054abf6c1bf977 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Wed, 19 May 2021 14:45:13 +0000 Subject: Reworking SysCommand & Moving to localectl for locale related activities * Moving to `localectl` rather than local file manipulation *(both for listing locales and setting them)*. * Swapped `loadkeys` for localectl. * Renamed `main` to `maim` in awesome profile. * Created `archinstall.Boot()` which spawns a `systemd-nspawn` container against the installation target. * Exposing systemd.py's internals to archinstall global scope. * Re-worked `SysCommand` completely, it's now a wrapper for `SysCommandWorker` which supports interacting with the process in a different way. `SysCommand` should behave just like the old one, for backwards compatibility reasons. This fixes #68 and #69. * `SysCommand()` now has a `.decode()` function that defaults to `UTF-8`. * Adding back peak_output=True to pacstrap. Co-authored-by: Anton Hvornum Co-authored-by: Dylan Taylor --- .gitignore | 5 +- archinstall/__init__.py | 1 + archinstall/lib/disk.py | 29 ++- archinstall/lib/general.py | 398 +++++++++++++++++++----------------- archinstall/lib/installer.py | 53 ++++- archinstall/lib/locale_helpers.py | 46 +++-- archinstall/lib/networking.py | 13 +- archinstall/lib/output.py | 2 +- archinstall/lib/systemd.py | 82 ++++++++ archinstall/lib/user_interaction.py | 12 +- examples/guided.py | 19 +- profiles/awesome.py | 2 +- 12 files changed, 417 insertions(+), 245 deletions(-) (limited to 'profiles/awesome.py') diff --git a/.gitignore b/.gitignore index d4ee5091..b357b543 100644 --- a/.gitignore +++ b/.gitignore @@ -20,9 +20,10 @@ SAFETY_LOCK **/**.network **/**.target **/**.qcow2 -**/test.py +/test*.py **/archiso /guided.py /install.log venv -.idea/** \ No newline at end of file +.idea/** +**/install.log \ No newline at end of file diff --git a/archinstall/__init__.py b/archinstall/__init__.py index 18c83a31..075b6f50 100644 --- a/archinstall/__init__.py +++ b/archinstall/__init__.py @@ -13,6 +13,7 @@ from .lib.packages import * from .lib.profiles import * from .lib.services import * from .lib.storage import * +from .lib.systemd import * from .lib.user_interaction import * __version__ = "2.2.0.dev1" diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index f8703ae3..44f2742b 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -1,6 +1,7 @@ import glob import pathlib import re +import time from collections import OrderedDict from typing import Optional @@ -77,7 +78,7 @@ class BlockDevice: raise DiskError(f'Could not locate backplane info for "{self.path}"') if self.info['type'] == 'loop': - for drive in json.loads(b''.join(SysCommand(['losetup', '--json'], hide_from_log=True)).decode('UTF_8'))['loopdevices']: + for drive in json.loads(b''.join(SysCommand(['losetup', '--json'])).decode('UTF_8'))['loopdevices']: if not drive['name'] == self.path: continue @@ -264,7 +265,9 @@ class Partition: raise DiskError(f'Could not mount and check for content on {self.path} because: {b"".join(handle)}') files = len(glob.glob(f"{temporary_mountpoint}/*")) - SysCommand(f'/usr/bin/umount {temporary_mountpoint}') + iterations = 0 + while SysCommand(f"/usr/bin/umount -R {temporary_mountpoint}").exit_code != 0 and (iterations := iterations+1) < 10: + time.sleep(1) temporary_path.rmdir() @@ -425,7 +428,7 @@ class Partition: """ try: self.format(self.filesystem, '/dev/null', log_formatting=False, allow_formatting=True) - except SysCallError: + except (SysCallError, DiskError): pass # We supported it, but /dev/null is not formatable as expected so the mkfs call exited with an error code except UnknownFilesystemFormat as err: raise err @@ -572,7 +575,7 @@ def all_disks(*args, **kwargs): kwargs.setdefault("partitions", False) drives = OrderedDict() # for drive in json.loads(sys_command(f'losetup --json', *args, **lkwargs, hide_from_log=True)).decode('UTF_8')['loopdevices']: - for drive in json.loads(b''.join(SysCommand('lsblk --json -l -n -o path,size,type,mountpoint,label,pkname,model', *args, **kwargs, hide_from_log=True)).decode('UTF_8'))['blockdevices']: + for drive in json.loads(b''.join(SysCommand('lsblk --json -l -n -o path,size,type,mountpoint,label,pkname,model')).decode('UTF_8'))['blockdevices']: if not kwargs['partitions'] and drive['type'] == 'part': continue @@ -603,13 +606,17 @@ def harddrive(size=None, model=None, fuzzy=False): return collection[drive] -def get_mount_info(path): +def get_mount_info(path) -> dict: try: - output = b''.join(SysCommand(f'/usr/bin/findmnt --json {path}')) + output = SysCommand(f'/usr/bin/findmnt --json {path}') except SysCallError: return {} output = output.decode('UTF-8') + + if not output: + return {} + output = json.loads(output) if 'filesystems' in output: if len(output['filesystems']) > 1: @@ -618,15 +625,19 @@ def get_mount_info(path): return output['filesystems'][0] -def get_partitions_in_use(mountpoint): +def get_partitions_in_use(mountpoint) -> list: try: - output = b''.join(SysCommand(f'/usr/bin/findmnt --json -R {mountpoint}')) + output = SysCommand(f'/usr/bin/findmnt --json -R {mountpoint}') except SysCallError: - return {} + return [] mounts = [] output = output.decode('UTF-8') + + if not output: + return [] + output = json.loads(output) for target in output.get('filesystems', []): mounts.append(Partition(target['source'], None, filesystem=target.get('fstype', None), mountpoint=target['target'])) diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index 9fbf2654..65c83484 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -4,6 +4,7 @@ import logging import os import pty import shlex +import subprocess import sys import time from datetime import datetime, date @@ -41,6 +42,8 @@ def locate_binary(name): return os.path.join(root, file) break # Don't recurse + raise RequirementError(f"Binary {name} does not exist.") + class JsonEncoder: def _encode(obj): @@ -84,108 +87,125 @@ class JSON(json.JSONEncoder, json.JSONDecoder): return super(JSON, self).encode(self._encode(obj)) -class SysCommand: - """ - Stolen from archinstall_gui - """ - - def __init__(self, cmd, callback=None, start_callback=None, peak_output=False, environment_vars=None, *args, **kwargs): - if environment_vars is None: +class SysCommandWorker: + def __init__(self, cmd, callbacks=None, peak_output=False, environment_vars=None, logfile=None, working_directory='./'): + if not callbacks: + callbacks = {} + if not environment_vars: environment_vars = {} - kwargs.setdefault("worker_id", gen_uid()) - kwargs.setdefault("emulate", False) - kwargs.setdefault("suppress_errors", False) - self.log = kwargs.get('log', log) + if type(cmd) is str: + cmd = shlex.split(cmd) - if kwargs['emulate']: - self.log(f"Starting command '{cmd}' in emulation mode.", level=logging.DEBUG) - - if type(cmd) is list: - # if we get a list of arguments - self.raw_cmd = shlex.join(cmd) - self.cmd = cmd - else: - # else consider it a single shell string - # this should only be used if really necessary - self.raw_cmd = cmd - try: - self.cmd = shlex.split(cmd) - except Exception as e: - raise ValueError(f'Incorrect string to split: {cmd}\n{e}') + if cmd[0][0] != '/' and cmd[0][:2] != './': + # "which" doesn't work as it's a builtin to bash. + # It used to work, but for whatever reason it doesn't anymore. + # We there for fall back on manual lookup in os.PATH + cmd[0] = locate_binary(cmd[0]) - self.args = args - self.kwargs = kwargs + self.cmd = cmd + self.callbacks = callbacks self.peak_output = peak_output self.environment_vars = environment_vars + self.logfile = logfile + self.working_directory = working_directory - self.kwargs.setdefault("worker", None) - self.callback = callback - self.pid = None self.exit_code = None - self.started = time.time() + self._trace_log = b'' + self._trace_log_pos = 0 + self.poll_object = epoll() + self.child_fd = None + self.started = None self.ended = None - self.worker_id = kwargs['worker_id'] - self.trace_log = b'' - self.status = 'starting' - user_catalogue = os.path.expanduser('~') + def __contains__(self, key: bytes): + """ + Contains will also move the current buffert position forward. + This is to avoid re-checking the same data when looking for output. + """ + assert type(key) == bytes - if workdir := kwargs.get('workdir', None): - self.cwd = workdir - self.exec_dir = workdir - else: - self.cwd = f"{user_catalogue}/.cache/archinstall/workers/{kwargs['worker_id']}/" - self.exec_dir = f'{self.cwd}/{os.path.basename(self.cmd[0])}_workingdir' + if (contains := key in self._trace_log[self._trace_log_pos:]): + self._trace_log_pos += self._trace_log[self._trace_log_pos:].find(key) + len(key) - if not self.cmd[0][0] == '/': - # "which" doesn't work as it's a builtin to bash. - # It used to work, but for whatever reason it doesn't anymore. So back to square one.. + return contains + + def __iter__(self, *args, **kwargs): + for line in self._trace_log[self._trace_log_pos:self._trace_log.rfind(b'\n')].split(b'\n'): + if line: + yield line + b'\n' - # self.log('Worker command is not executed with absolute path, trying to find: {}'.format(self.cmd[0]), origin='spawn', level=5) - # self.log('This is the binary {} for {}'.format(o.decode('UTF-8'), self.cmd[0]), origin='spawn', level=5) - self.cmd[0] = locate_binary(self.cmd[0]) + self._trace_log_pos = self._trace_log.rfind(b'\n') - if not os.path.isdir(self.exec_dir): - os.makedirs(self.exec_dir) + def __repr__(self): + self.make_sure_we_are_executing() + return str(self._trace_log) - if start_callback: - start_callback(self, *args, **kwargs) - self.run() + def __enter__(self): + return self - def __iter__(self, *args, **kwargs): - for line in self.trace_log.split(b'\n'): - yield line + def __exit__(self, *args): + # b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync. + # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager - def __repr__(self, *args, **kwargs): - return f"{self.cmd, self.trace_log}" + if self.child_fd: + try: + os.close(self.child_fd) + except: + pass - def decode(self, fmt='UTF-8'): - return self.trace_log.decode(fmt) + if self.peak_output: + # To make sure any peaked output didn't leave us hanging + # on the same line we were on. + sys.stdout.write("\n") + sys.stdout.flush() - def dump(self): - return { - 'status': self.status, - 'worker_id': self.worker_id, - 'worker_result': self.trace_log.decode('UTF-8'), - 'started': self.started, - 'ended': self.ended, - 'started_pprint': '{}-{}-{} {}:{}:{}'.format(*time.localtime(self.started)), - 'ended_pprint': '{}-{}-{} {}:{}:{}'.format(*time.localtime(self.ended)) if self.ended else None, - 'exit_code': self.exit_code, - } + if len(args) >= 2 and args[1]: + log(args[1], level=logging.ERROR, fg='red') + + if self.exit_code != 0: + raise SysCallError(f"{self.cmd} exited with abnormal exit code: {self.exit_code}") + + def is_alive(self): + self.poll() + + if self.started and self.ended is None: + return True + + return False + + def write(self, data: bytes, line_ending=True): + assert type(data) == bytes # TODO: Maybe we can support str as well and encode it + + self.make_sure_we_are_executing() + + os.write(self.child_fd, data + (b'\n' if line_ending else b'')) + + def make_sure_we_are_executing(self): + if not self.started: + return self.execute() + + def tell(self) -> int: + self.make_sure_we_are_executing() + return self._trace_log_pos + + def seek(self, pos): + self.make_sure_we_are_executing() + # Safety check to ensure 0 < pos < len(tracelog) + self._trace_log_pos = min(max(0, pos), len(self._trace_log)) def peak(self, output: Union[str, bytes]) -> bool: - if type(output) == bytes: - try: - output = output.decode('UTF-8') - except UnicodeDecodeError: + if self.peak_output: + if type(output) == bytes: + try: + output = output.decode('UTF-8') + except UnicodeDecodeError: + return False + + output = output.strip('\r\n ') + if len(output) <= 0: return False - output = output.strip('\r\n ') - if len(output) <= 0: - return False - if self.peak_output: from .user_interaction import get_terminal_width # Move back to the beginning of the terminal @@ -207,125 +227,127 @@ class SysCommand: sys.stdout.flush() return True - def run(self): - self.status = 'running' - old_dir = os.getcwd() - os.chdir(self.exec_dir) - self.pid, child_fd = pty.fork() - if not self.pid: # Child process - # Replace child process with our main process - if not self.kwargs['emulate']: - try: - os.execve(self.cmd[0], self.cmd, {**os.environ, **self.environment_vars}) - except FileNotFoundError: - self.status = 'done' - self.log(f"{self.cmd[0]} does not exist.", level=logging.DEBUG) - self.exit_code = 1 - return False - - os.chdir(old_dir) + def poll(self): + self.make_sure_we_are_executing() - poller = epoll() - poller.register(child_fd, EPOLLIN | EPOLLHUP) - - if 'events' in self.kwargs and 'debug' in self.kwargs: - self.log(f'[D] Using triggers for command: {self.cmd}', level=logging.DEBUG) - self.log(json.dumps(self.kwargs['events']), level=logging.DEBUG) - - alive = True - last_trigger_pos = 0 - while alive and not self.kwargs['emulate']: - for fileno, event in poller.poll(0.1): - try: - output = os.read(child_fd, 8192) - self.peak(output) - self.trace_log += output - except OSError: - alive = False - break - - if 'debug' in self.kwargs and self.kwargs['debug'] and len(output): - self.log(self.cmd, 'gave:', output.decode('UTF-8'), level=logging.DEBUG) - - if 'on_output' in self.kwargs: - self.kwargs['on_output'](self.kwargs['worker'], output) - - lower = output.lower() - broke = False - if 'events' in self.kwargs: - for trigger in list(self.kwargs['events']): - if type(trigger) != bytes: - original = trigger - trigger = bytes(original, 'UTF-8') - self.kwargs['events'][trigger] = self.kwargs['events'][original] - del self.kwargs['events'][original] - if type(self.kwargs['events'][trigger]) != bytes: - self.kwargs['events'][trigger] = bytes(self.kwargs['events'][trigger], 'UTF-8') - - if trigger.lower() in self.trace_log[last_trigger_pos:].lower(): - trigger_pos = self.trace_log[last_trigger_pos:].lower().find(trigger.lower()) - - if 'debug' in self.kwargs and self.kwargs['debug']: - self.log(f"Writing to subprocess {self.cmd[0]}: {self.kwargs['events'][trigger].decode('UTF-8')}", level=logging.DEBUG) - self.log(f"Writing to subprocess {self.cmd[0]}: {self.kwargs['events'][trigger].decode('UTF-8')}", level=logging.DEBUG) - - last_trigger_pos = trigger_pos - os.write(child_fd, self.kwargs['events'][trigger]) - del self.kwargs['events'][trigger] - broke = True - break - - if broke: - continue - - # Adding a exit trigger: - if len(self.kwargs['events']) == 0: - if 'debug' in self.kwargs and self.kwargs['debug']: - self.log(f"Waiting for last command {self.cmd[0]} to finish.", level=logging.DEBUG) - - if bytes(']$'.lower(), 'UTF-8') in self.trace_log[0 - len(']$') - 5:].lower(): - if 'debug' in self.kwargs and self.kwargs['debug']: - self.log(f"{self.cmd[0]} has finished.", level=logging.DEBUG) - alive = False - break - - self.status = 'done' - - if 'debug' in self.kwargs and self.kwargs['debug']: - self.log(f"{self.cmd[0]} waiting for exit code.", level=logging.DEBUG) - - if not self.kwargs['emulate']: + got_output = False + for fileno, event in self.poll_object.poll(0.1): + try: + output = os.read(self.child_fd, 8192) + got_output = True + self.peak(output) + self._trace_log += output + except OSError as err: + self.ended = time.time() + break + + if self.ended or (got_output is False and pid_exists(self.pid) is False): + self.ended = time.time() try: self.exit_code = os.waitpid(self.pid, 0)[1] except ChildProcessError: try: - self.exit_code = os.waitpid(child_fd, 0)[1] + self.exit_code = os.waitpid(self.child_fd, 0)[1] except ChildProcessError: self.exit_code = 1 - else: - self.exit_code = 0 - if 'debug' in self.kwargs and self.kwargs['debug']: - self.log(f"{self.cmd[0]} got exit code: {self.exit_code}", level=logging.DEBUG) + def execute(self) -> bool: + if (old_dir := os.getcwd()) != self.working_directory: + os.chdir(self.working_directory) + + # Note: If for any reason, we get a Python exception between here + # and until os.close(), the traceback will get locked inside + # stdout of the child_fd object. `os.read(self.child_fd, 8192)` is the + # only way to get the traceback without loosing it. + self.pid, self.child_fd = pty.fork() + os.chdir(old_dir) + + if not self.pid: + try: + os.execve(self.cmd[0], self.cmd, {**os.environ, **self.environment_vars}) + except FileNotFoundError: + log(f"{self.cmd[0]} does not exist.", level=logging.ERROR, fg="red") + self.exit_code = 1 + return False + + self.started = time.time() + self.poll_object.register(self.child_fd, EPOLLIN | EPOLLHUP) + + return True + + def decode(self, encoding='UTF-8'): + return self._trace_log.decode(encoding) + + +class SysCommand: + def __init__(self, cmd, callback=None, start_callback=None, peak_output=False, environment_vars=None, working_directory='./'): + _callbacks = {} + if callback: + _callbacks['on_end'] = callback + if start_callback: + _callbacks['on_start'] = start_callback + + self.cmd = cmd + self._callbacks = _callbacks + self.peak_output = peak_output + self.environment_vars = environment_vars + self.working_directory = working_directory - if 'ignore_errors' in self.kwargs: - self.exit_code = 0 + self.session = None + self.create_session() - if self.exit_code != 0 and not self.kwargs['suppress_errors']: - # self.log(self.trace_log.decode('UTF-8'), level=logging.DEBUG) - # self.log(f"'{self.raw_cmd}' did not exit gracefully, exit code {self.exit_code}.", level=logging.ERROR) - raise SysCallError( - message=f"{self.trace_log.decode('UTF-8')}\n'{self.raw_cmd}' did not exit gracefully (trace log above), exit code: {self.exit_code}", - exit_code=self.exit_code) + def __enter__(self): + return self.session - self.ended = time.time() - with open(f'{self.cwd}/trace.log', 'wb') as fh: - fh.write(self.trace_log) + def __exit__(self, *args, **kwargs): + # b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync. + # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager + + if len(args) >= 2 and args[1]: + log(args[1], level=logging.ERROR, fg='red') + + def __iter__(self, *args, **kwargs): + + for line in self.session: + yield line + + def __repr__(self, *args, **kwargs): + return self.session._trace_log.decode('UTF-8') + + def __json__(self): + return { + 'cmd': self.cmd, + 'callbacks': self._callbacks, + 'peak': self.peak_output, + 'environment_vars': self.environment_vars, + 'session': True if self.session else False + } + + def create_session(self): + if self.session: + return True try: - os.close(child_fd) - except: - pass + self.session = SysCommandWorker(self.cmd, callbacks=self._callbacks, peak_output=self.peak_output, environment_vars=self.environment_vars) + + while self.session.ended is None: + self.session.poll() + + except SysCallError: + return False + + return True + + def decode(self, fmt='UTF-8'): + return self.session._trace_log.decode(fmt) + + @property + def exit_code(self): + return self.session.exit_code + + @property + def trace_log(self): + return self.session._trace_log def prerequisite_check(): @@ -337,3 +359,9 @@ def prerequisite_check(): def reboot(): o = b''.join(SysCommand("/usr/bin/reboot")) + +def pid_exists(pid :int): + try: + return any(subprocess.check_output(['/usr/bin/ps', '--no-headers', '-o', 'pid', '-p', str(pid)]).strip()) + except subprocess.CalledProcessError: + return False \ No newline at end of file diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 61b0a3a1..29b3bc1a 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1,8 +1,8 @@ from .disk import * from .hardware import * +from .locale_helpers import verify_x11_keyboard_layout from .mirrors import * from .storage import storage -from .systemd import Networkd from .user_interaction import * # Any package that the Installer() is responsible for (optional and the default ones) @@ -78,7 +78,6 @@ class Installer: # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager if len(args) >= 2 and args[1]: - # self.log(self.trace_log.decode('UTF-8'), level=logging.DEBUG) self.log(args[1], level=logging.ERROR, fg='red') self.sync_log_to_install_medium() @@ -136,7 +135,7 @@ class Installer: self.log(f'Installing packages: {packages}', level=logging.INFO) if (sync_mirrors := SysCommand('/usr/bin/pacman -Syy')).exit_code == 0: - if (pacstrap := SysCommand(f'/usr/bin/pacstrap {self.target} {" ".join(packages)}', **kwargs)).exit_code == 0: + if (pacstrap := SysCommand(f'/usr/bin/pacstrap {self.target} {" ".join(packages)}', peak_output=True)).exit_code == 0: return True else: self.log(f'Could not strap in packages: {pacstrap.exit_code}', level=logging.INFO) @@ -149,9 +148,8 @@ class Installer: def genfstab(self, flags='-pU'): self.log(f"Updating {self.target}/etc/fstab", level=logging.INFO) - fstab = SysCommand(f'/usr/bin/genfstab {flags} {self.target}').trace_log - with open(f"{self.target}/etc/fstab", 'ab') as fstab_fh: - fstab_fh.write(fstab) + with open(f"{self.target}/etc/fstab", 'a') as fstab_fh: + fstab_fh.write(SysCommand(f'/usr/bin/genfstab {flags} {self.target}').decode()) if not os.path.isfile(f'{self.target}/etc/fstab'): raise RequirementError(f'Could not generate fstab, strapping in packages most likely failed (disk out of space?)\n{fstab}') @@ -215,6 +213,8 @@ class Installer: subprocess.check_call(f"/usr/bin/arch-chroot {self.target}", shell=True) def configure_nic(self, nic, dhcp=True, ip=None, gateway=None, dns=None, *args, **kwargs): + from .systemd import Networkd + if dhcp: conf = Networkd(Match={"Name": nic}, Network={"DHCP": "yes"}) else: @@ -514,11 +514,44 @@ class Installer: o = b''.join(SysCommand(f"/usr/bin/arch-chroot {self.target} sh -c \"chsh -s {shell} {user}\"")) pass - def set_keyboard_language(self, language): + def set_keyboard_language(self, language: str) -> bool: if len(language.strip()): - with open(f'{self.target}/etc/vconsole.conf', 'w') as vconsole: - vconsole.write(f'KEYMAP={language}\n') - vconsole.write('FONT=lat9w-16\n') + if not verify_keyboard_layout(language): + self.log(f"Invalid keyboard language specified: {language}", fg="red", level=logging.ERROR) + return False + + # In accordance with https://github.com/archlinux/archinstall/issues/107#issuecomment-841701968 + # Setting an empty keymap first, allows the subsequent call to set layout for both console and x11. + from .systemd import Boot + + with Boot(self) as session: + session.SysCommand(["localectl", "set-keymap", '""']) + + if (output := session.SysCommand(["localectl", "set-keymap", language])).exit_code != 0: + raise ServiceException(f"Unable to set locale '{language}' for console: {output}") + + self.log(f"Keyboard language for this installation is now set to: {language}") else: self.log('Keyboard language was not changed from default (no language specified).', fg="yellow", level=logging.INFO) + + return True + + def set_x11_keyboard_language(self, language: str) -> bool: + """ + A fallback function to set x11 layout specifically and separately from console layout. + This isn't strictly necessary since .set_keyboard_language() does this as well. + """ + if len(language.strip()): + if not verify_x11_keyboard_layout(language): + self.log(f"Invalid x11-keyboard language specified: {language}", fg="red", level=logging.ERROR) + return False + + with Boot(self) as session: + session.SysCommand(["localectl", "set-x11-keymap", '""']) + + if (output := session.SysCommand(["localectl", "set-x11-keymap", language])).exit_code != 0: + raise ServiceException(f"Unable to set locale '{language}' for X11: {output}") + else: + self.log(f'X11-Keyboard language was not changed from default (no language specified).', fg="yellow", level=logging.INFO) + return True diff --git a/archinstall/lib/locale_helpers.py b/archinstall/lib/locale_helpers.py index 2db429fd..36228edc 100644 --- a/archinstall/lib/locale_helpers.py +++ b/archinstall/lib/locale_helpers.py @@ -1,23 +1,18 @@ -import os -import subprocess +import logging -from .exceptions import * - - -# from .general import sys_command +from .exceptions import ServiceException +from .general import SysCommand +from .output import log def list_keyboard_languages(): - locale_dir = '/usr/share/kbd/keymaps/' - - if not os.path.isdir(locale_dir): - raise RequirementError(f'Directory containing locales does not exist: {locale_dir}') + for line in SysCommand("localectl --no-pager list-keymaps", environment_vars={'SYSTEMD_COLORS': '0'}): + yield line.decode('UTF-8').strip() - for root, folders, files in os.walk(locale_dir): - for file in files: - if os.path.splitext(file)[1] == '.gz': - yield file.strip('.gz').strip('.map') +def list_x11_keyboard_languages(): + for line in SysCommand("localectl --no-pager list-x11-keymap-layouts", environment_vars={'SYSTEMD_COLORS': '0'}): + yield line.decode('UTF-8').strip() def verify_keyboard_layout(layout): @@ -27,11 +22,28 @@ def verify_keyboard_layout(layout): return False -def search_keyboard_layout(layout_filter): +def verify_x11_keyboard_layout(layout): + for language in list_x11_keyboard_languages(): + if layout.lower() == language.lower(): + return True + return False + + +def search_keyboard_layout(layout): for language in list_keyboard_languages(): - if layout_filter.lower() in language.lower(): + if layout.lower() in language.lower(): yield language def set_keyboard_language(locale): - return subprocess.call(['loadkeys', locale]) == 0 + if len(locale.strip()): + if not verify_keyboard_layout(locale): + log(f"Invalid keyboard locale specified: {locale}", fg="red", level=logging.ERROR) + return False + + if (output := SysCommand(f'localectl set-keymap {locale}')).exit_code != 0: + raise ServiceException(f"Unable to set locale '{locale}' for console: {output}") + + return True + + return False diff --git a/archinstall/lib/networking.py b/archinstall/lib/networking.py index dbd510dd..fdeefb84 100644 --- a/archinstall/lib/networking.py +++ b/archinstall/lib/networking.py @@ -1,5 +1,6 @@ import fcntl import os +import logging import socket import struct from collections import OrderedDict @@ -7,7 +8,7 @@ from collections import OrderedDict from .exceptions import * from .general import SysCommand from .storage import storage - +from .output import log def get_hw_addr(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -27,12 +28,12 @@ def list_interfaces(skip_loopback=True): def check_mirror_reachable(): - try: - check = SysCommand("pacman -Sy") - return check.exit_code == 0 - except: - return False + if (exit_code := SysCommand("pacman -Sy").exit_code) == 0: + return True + elif exit_code == 256: + log("check_mirror_reachable() uses 'pacman -Sy' which requires root.", level=logging.ERROR, fg="red") + return False def enrich_iface_types(interfaces: dict): result = {} diff --git a/archinstall/lib/output.py b/archinstall/lib/output.py index 20b0df8d..595e9693 100644 --- a/archinstall/lib/output.py +++ b/archinstall/lib/output.py @@ -155,7 +155,7 @@ def log(*args, **kwargs): log("Deprecated level detected in log message, please use new logging. instead for the following log message:", fg="red", level=logging.ERROR, force=True) kwargs['level'] = logging.DEBUG - if kwargs['level'] > storage.get('LOG_LEVEL', logging.INFO) and 'force' not in kwargs: + if kwargs['level'] < storage.get('LOG_LEVEL', logging.INFO) and 'force' not in kwargs: # Level on log message was Debug, but output level is set to Info. # In that case, we'll drop it. return None diff --git a/archinstall/lib/systemd.py b/archinstall/lib/systemd.py index 5607250b..e64ff7e0 100644 --- a/archinstall/lib/systemd.py +++ b/archinstall/lib/systemd.py @@ -1,3 +1,10 @@ +import logging + +from .general import SysCommand, SysCommandWorker, locate_binary +from .installer import Installer +from .output import log +from .storage import storage + class Ini: def __init__(self, *args, **kwargs): """ @@ -36,3 +43,78 @@ class Networkd(Systemd): """ Placeholder class to do systemd-network specific setups. """ + + +class Boot: + def __init__(self, installation: Installer): + self.instance = installation + self.container_name = 'archinstall' + self.session = None + self.ready = False + + def __enter__(self): + if (existing_session := storage.get('active_boot', None)) and existing_session.instance != self.instance: + raise KeyError("Archinstall only supports booting up one instance, and a active session is already active and it is not this one.") + + if existing_session: + self.session = existing_session.session + self.ready = existing_session.ready + else: + self.session = SysCommandWorker([ + '/usr/bin/systemd-nspawn', + '-D', self.instance.target, + '-b', + '--machine', self.container_name + ]) + + if not self.ready: + while self.session.is_alive(): + if b' login:' in self.session: + self.ready = True + break + + storage['active_boot'] = self + return self + + def __exit__(self, *args, **kwargs): + # b''.join(sys_command('sync')) # No need to, since the underlying fs() object will call sync. + # TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager + + if len(args) >= 2 and args[1]: + log(args[1], level=logging.ERROR, fg='red') + log(f"The error above occured in a temporary boot-up of the installation {self.instance}", level=logging.ERROR, fg="red") + + SysCommand(f'machinectl shell {self.container_name} /bin/bash -c "shutdown now"') + + def __iter__(self): + if self.session: + for value in self.session: + yield value + + def __contains__(self, key: bytes): + if self.session is None: + return False + + return key in self.session + + def is_alive(self): + if self.session is None: + return False + + return self.session.is_alive() + + def SysCommand(self, cmd :list, *args, **kwargs): + if cmd[0][0] != '/' and cmd[0][:2] != './': + # This check is also done in SysCommand & SysCommandWorker. + # However, that check is done for `machinectl` and not for our chroot command. + # So this wrapper for SysCommand will do this additionally. + + cmd[0] = locate_binary(cmd[0]) + + return SysCommand(["machinectl", "shell", self.container_name, *cmd], *args, **kwargs) + + def SysCommandWorker(self, cmd :list, *args, **kwargs): + if cmd[0][0] != '/' and cmd[0][:2] != './': + cmd[0] = locate_binary(cmd[0]) + + return SysCommandWorker(["machinectl", "shell", self.container_name, *cmd], *args, **kwargs) \ No newline at end of file diff --git a/archinstall/lib/user_interaction.py b/archinstall/lib/user_interaction.py index 5f849607..50c62aa9 100644 --- a/archinstall/lib/user_interaction.py +++ b/archinstall/lib/user_interaction.py @@ -591,7 +591,7 @@ def select_profile(options): raise RequirementError("Selecting profiles require a least one profile to be given as an option.") -def select_language(options, show_only_country_codes=True): +def select_language(options, show_only_country_codes=True, input_text='Select one of the above keyboard languages (by number or full name): '): """ Asks the user to select a language from the `options` dictionary parameter. Usually this is combined with :ref:`archinstall.list_keyboard_languages`. @@ -613,14 +613,13 @@ def select_language(options, show_only_country_codes=True): languages = sorted(list(options)) if len(languages) >= 1: - for index, language in enumerate(languages): - print(f"{index}: {language}") + print_large_list(languages, margin_bottom=4) print(" -- You can choose a layout that isn't in this list, but whose name you know --") - print(" -- Also, you can enter '?' or 'help' to search for more languages, or skip to use US layout --") + print(f" -- Also, you can enter '?' or 'help' to search for more languages, or skip to use {default_keyboard_language} layout --") while True: - selected_language = input('Select one of the above keyboard languages (by name or full name): ') + selected_language = input(input_text) if not selected_language: return default_keyboard_language elif selected_language.lower() in ('?', 'help'): @@ -705,8 +704,7 @@ def select_driver(options=AVAILABLE_GFX_DRIVERS): default_option = options["All open-source (default)"] if drivers: - lspci = SysCommand('/usr/bin/lspci') - for line in lspci.trace_log.split(b'\r\n'): + for line in SysCommand('/usr/bin/lspci'): if b' vga ' in line.lower(): if b'nvidia' in line.lower(): print(' ** nvidia card detected, suggested driver: nvidia **') diff --git a/examples/guided.py b/examples/guided.py index cce06b29..b9b06a64 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -1,6 +1,7 @@ import json import logging import time +import os import archinstall from archinstall.lib.hardware import has_uefi @@ -51,7 +52,7 @@ def ask_user_questions(): else: archinstall.arguments['harddrive'] = archinstall.select_disk(archinstall.all_disks()) if archinstall.arguments['harddrive'] is None: - archinstall.arguments['target-mount'] = '/mnt' + archinstall.arguments['target-mount'] = archinstall.storage.get('MOUNT_POINT', '/mnt') # Perform a quick sanity check on the selected harddrive. # 1. Check if it has partitions @@ -291,14 +292,14 @@ def perform_installation_steps(): # unlocks the drive so that it can be used as a normal block-device within archinstall. with archinstall.luks2(fs.find_partition('/'), 'luksloop', archinstall.arguments.get('!encryption-password', None)) as unlocked_device: unlocked_device.format(fs.find_partition('/').filesystem) - unlocked_device.mount('/mnt') + unlocked_device.mount(archinstall.storage.get('MOUNT_POINT', '/mnt')) else: - fs.find_partition('/').mount('/mnt') + fs.find_partition('/').mount(archinstall.storage.get('MOUNT_POINT', '/mnt')) if has_uefi(): - fs.find_partition('/boot').mount('/mnt/boot') + fs.find_partition('/boot').mount(archinstall.storage.get('MOUNT_POINT', '/mnt')+'/boot') - perform_installation('/mnt') + perform_installation(archinstall.storage.get('MOUNT_POINT', '/mnt')) def perform_installation(mountpoint): @@ -324,7 +325,6 @@ def perform_installation(mountpoint): installation.set_mirrors(archinstall.arguments['mirror-region']) # Set the mirrors in the installation medium if archinstall.arguments["bootloader"] == "grub-install" and has_uefi(): installation.add_additional_packages("grub") - installation.set_keyboard_language(archinstall.arguments['keyboard-language']) installation.add_bootloader(archinstall.arguments["bootloader"]) # If user selected to copy the current ISO network configuration @@ -370,6 +370,10 @@ def perform_installation(mountpoint): if (root_pw := archinstall.arguments.get('!root-password', None)) and len(root_pw): installation.user_set_pw('root', root_pw) + # This step must be after profile installs to allow profiles to install language pre-requisits. + # After which, this step will set the language both for console and x11 if x11 was installed for instance. + installation.set_keyboard_language(archinstall.arguments['keyboard-language']) + if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_post_install(): with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py") as imported: if not imported._post_install(): @@ -389,7 +393,8 @@ def perform_installation(mountpoint): if not check_mirror_reachable(): - archinstall.log("Arch Linux mirrors are not reachable. Please check your internet connection and try again.", level=logging.INFO, fg="red") + log_file = os.path.join(archinstall.storage.get('LOG_PATH', None), archinstall.storage.get('LOG_FILE', None)) + archinstall.log(f"Arch Linux mirrors are not reachable. Please check your internet connection and the log file '{log_file}'.", level=logging.INFO, fg="red") exit(1) ask_user_questions() diff --git a/profiles/awesome.py b/profiles/awesome.py index 0c1b20ea..9648fc4a 100644 --- a/profiles/awesome.py +++ b/profiles/awesome.py @@ -9,7 +9,7 @@ is_top_level_profile = False __packages__ = [ "nemo", "gpicview", - "main", + "maim", "alacritty", ] -- cgit v1.2.3-70-g09d2