From df1ed2034d17ff15bb321ff2c306c9e8aaedeec6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 14:04:06 +0100 Subject: Debugging tainted namespace on profile modules. --- archinstall/lib/profiles.py | 1 + 1 file changed, 1 insertion(+) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 01c3288c..92c9a140 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -125,6 +125,7 @@ class Script(): raise ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}") def load_instructions(self, namespace=None): + print(f"Load instructions for {self} with namespace {namespace}") if namespace: self.namespace = namespace -- cgit v1.2.3-54-g00ecf From b81d5e054d59df523a30f997e0ae66eb2c7107ff Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 14:19:39 +0100 Subject: Debugging tainted namespace on profile modules. --- archinstall/lib/profiles.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 92c9a140..bafa76df 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -129,6 +129,9 @@ class Script(): if namespace: self.namespace = namespace + if '.py' in self.namespace: + raise KeyError("Debugging") + self.spec = importlib.util.spec_from_file_location(self.namespace, self.path) imported = importlib.util.module_from_spec(self.spec) sys.modules[self.namespace] = imported -- cgit v1.2.3-54-g00ecf From 1fdda954dcdc69982de94e3c2000666379eb9b67 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 14:21:28 +0100 Subject: Debugging tainted namespace on profile modules. --- examples/guided.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/guided.py b/examples/guided.py index b6aa5810..f4fc533b 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -169,6 +169,7 @@ def ask_user_questions(): # Check the potentially selected profiles preperations to get early checks if some additional questions are needed. if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_prep_function(): + print(f"{archinstall.arguments['profile']} has prep-function, loading with namespace {archinstall.arguments['profile'].namespace}.py") with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py") as imported: if not imported._prep_function(): archinstall.log( -- cgit v1.2.3-54-g00ecf From 1998e0378cbf2348289a56679ddcfbfd58160987 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 14:21:47 +0100 Subject: Debugging tainted namespace on profile modules. --- archinstall/lib/profiles.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index bafa76df..a8a18f54 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -129,8 +129,8 @@ class Script(): if namespace: self.namespace = namespace - if '.py' in self.namespace: - raise KeyError("Debugging") + #if '.py' in self.namespace: + # raise KeyError("Debugging") self.spec = importlib.util.spec_from_file_location(self.namespace, self.path) imported = importlib.util.module_from_spec(self.spec) -- cgit v1.2.3-54-g00ecf From e1e1a916fcb8b769f0be4c5fa303a2eb5670c19b Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 14:32:36 +0100 Subject: Debugging tainted namespace on profile modules. --- archinstall/lib/profiles.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index a8a18f54..bafa76df 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -129,8 +129,8 @@ class Script(): if namespace: self.namespace = namespace - #if '.py' in self.namespace: - # raise KeyError("Debugging") + if '.py' in self.namespace: + raise KeyError("Debugging") self.spec = importlib.util.spec_from_file_location(self.namespace, self.path) imported = importlib.util.module_from_spec(self.spec) -- cgit v1.2.3-54-g00ecf From 1fb61bf8fcb5319cc5e1e99d9b92763f1271ae33 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 14:34:03 +0100 Subject: Debugging tainted namespace on profile modules. --- archinstall/lib/profiles.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index bafa76df..f90facc8 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -129,7 +129,7 @@ class Script(): if namespace: self.namespace = namespace - if '.py' in self.namespace: + if '.py.py' in self.namespace: raise KeyError("Debugging") self.spec = importlib.util.spec_from_file_location(self.namespace, self.path) @@ -173,6 +173,7 @@ class Profile(Script): # trigger a traditional: # if __name__ == 'moduleName' if '__name__' in source_data and '_prep_function' in source_data: + print(f"Checking if {self} has _prep_function by importing with namespace {self.namespace}.py") with self.load_instructions(namespace=f"{self.namespace}.py") as imported: if hasattr(imported, '_prep_function'): return True -- cgit v1.2.3-54-g00ecf From f76f5458daa63b06cf356f40a0eb27f957308b66 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 14:48:26 +0100 Subject: Debugging tainted namespace on profile modules. --- archinstall/lib/profiles.py | 1 + 1 file changed, 1 insertion(+) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index f90facc8..7b6e9b4d 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -76,6 +76,7 @@ class Script(): self.spec = None self.examples = None self.namespace = os.path.splitext(os.path.basename(self.path))[0] + print(f"Script loaded with namespace: {self.namespace}") def __enter__(self, *args, **kwargs): self.execute() -- cgit v1.2.3-54-g00ecf From c1e8e6b58dd71f14f2720f532c327d29e8473dbe Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 14:50:57 +0100 Subject: Debugging tainted namespace on profile modules. --- archinstall/lib/profiles.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 7b6e9b4d..63d32afa 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -76,7 +76,7 @@ class Script(): self.spec = None self.examples = None self.namespace = os.path.splitext(os.path.basename(self.path))[0] - print(f"Script loaded with namespace: {self.namespace}") + print(f"Script {self} loaded with namespace: {self.namespace}") def __enter__(self, *args, **kwargs): self.execute() @@ -126,17 +126,18 @@ class Script(): raise ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}") def load_instructions(self, namespace=None): - print(f"Load instructions for {self} with namespace {namespace}") - if namespace: - self.namespace = namespace + if not namespace: + namespace = self.namespace - if '.py.py' in self.namespace: - raise KeyError("Debugging") + if namespace in sys.modules: + print(f"Found {self} in sys.modules, returning cached import.") + return self - self.spec = importlib.util.spec_from_file_location(self.namespace, self.path) + self.spec = importlib.util.spec_from_file_location(namespace, self.path) imported = importlib.util.module_from_spec(self.spec) - sys.modules[self.namespace] = imported + sys.modules[namespace] = imported + print(f"Imported {self} into sys.modules. Returning fresh copy.") return self def execute(self): -- cgit v1.2.3-54-g00ecf From ec9059c039c3d47dc17e457cdc8a42549de87d5b Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 14:51:59 +0100 Subject: Debugging tainted namespace on profile modules. --- archinstall/lib/profiles.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 63d32afa..e22a3587 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -129,15 +129,11 @@ class Script(): if not namespace: namespace = self.namespace - if namespace in sys.modules: - print(f"Found {self} in sys.modules, returning cached import.") - return self - self.spec = importlib.util.spec_from_file_location(namespace, self.path) imported = importlib.util.module_from_spec(self.spec) sys.modules[namespace] = imported - print(f"Imported {self} into sys.modules. Returning fresh copy.") + print(f"Imported {self} into sys.modules with namespace {namespace}.") return self def execute(self): -- cgit v1.2.3-54-g00ecf From c99abb1a7b6b0fe75f8bc1b7558e0e13afb283c5 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 14:56:26 +0100 Subject: Debugging tainted namespace on profile modules. --- archinstall/lib/profiles.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index e22a3587..724b92e7 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -134,6 +134,9 @@ class Script(): sys.modules[namespace] = imported print(f"Imported {self} into sys.modules with namespace {namespace}.") + + if '.py' not in namespace: + raise KeyError("Debugging") return self def execute(self): -- cgit v1.2.3-54-g00ecf From 27bde44b8de447e8612a83bc6964fc1b5237e07d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 15:00:08 +0100 Subject: Debugging tainted namespace on profile modules. --- archinstall/lib/profiles.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 724b92e7..5d425a22 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -126,17 +126,15 @@ class Script(): raise ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}") def load_instructions(self, namespace=None): - if not namespace: - namespace = self.namespace + if namespace: + self.namespace = namespace - self.spec = importlib.util.spec_from_file_location(namespace, self.path) + self.spec = importlib.util.spec_from_file_location(self.namespace, self.path) imported = importlib.util.module_from_spec(self.spec) - sys.modules[namespace] = imported + sys.modules[self.namespace] = imported - print(f"Imported {self} into sys.modules with namespace {namespace}.") + print(f"Imported {self} into sys.modules with namespace {self.namespace}.") - if '.py' not in namespace: - raise KeyError("Debugging") return self def execute(self): -- cgit v1.2.3-54-g00ecf From 9ee64797011b541b38e68610a746eb6f303ab63d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 15:04:23 +0100 Subject: Enabling load_instructions() to set a temporary namespace, and then reverting it after the instructions are loaded. This is to temporarly override the namespace during import - enabling avoidance of triggering __name__ checks, and at the same time reverting back the namespace automatically to enable .execute() on the script (reusability of classes) --- archinstall/lib/profiles.py | 9 +++++++-- examples/guided.py | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 5d425a22..ef7bba00 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -125,7 +125,9 @@ class Script(): else: raise ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}") - def load_instructions(self, namespace=None): + def load_instructions(self, namespace=None, reset_namespace=False): + original_namespace = self.namespace + if namespace: self.namespace = namespace @@ -135,6 +137,9 @@ class Script(): print(f"Imported {self} into sys.modules with namespace {self.namespace}.") + if reset_namespace: + self.namespace = original_namespace + return self def execute(self): @@ -173,7 +178,7 @@ class Profile(Script): # if __name__ == 'moduleName' if '__name__' in source_data and '_prep_function' in source_data: print(f"Checking if {self} has _prep_function by importing with namespace {self.namespace}.py") - with self.load_instructions(namespace=f"{self.namespace}.py") as imported: + with self.load_instructions(namespace=f"{self.namespace}.py", reset_namespace=True) as imported: if hasattr(imported, '_prep_function'): return True return False diff --git a/examples/guided.py b/examples/guided.py index f4fc533b..4e3dd082 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -170,7 +170,7 @@ def ask_user_questions(): # Check the potentially selected profiles preperations to get early checks if some additional questions are needed. if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_prep_function(): print(f"{archinstall.arguments['profile']} has prep-function, loading with namespace {archinstall.arguments['profile'].namespace}.py") - with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py") as imported: + with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py", reset_namespace=True) as imported: if not imported._prep_function(): archinstall.log( ' * Profile\'s preparation requirements was not fulfilled.', -- cgit v1.2.3-54-g00ecf From 28606cde6127921615692460bbb4d80f68b7b727 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 15:07:45 +0100 Subject: Enabling load_instructions() to set a temporary namespace, and then reverting it after the instructions are loaded. This is to temporarly override the namespace during import - enabling avoidance of triggering __name__ checks, and at the same time reverting back the namespace automatically to enable .execute() on the script (reusability of classes) --- archinstall/lib/profiles.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index ef7bba00..8284bf40 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -135,11 +135,14 @@ class Script(): imported = importlib.util.module_from_spec(self.spec) sys.modules[self.namespace] = imported - print(f"Imported {self} into sys.modules with namespace {self.namespace}.") + print(f"Imported {self} into sys.modules with namespace {self.namespace}") + + if '.py' not in self.namespace: + raise KeyError(f"Debugging: {self.namespace}, {reset_namespace}, {self}") if reset_namespace: self.namespace = original_namespace - + return self def execute(self): -- cgit v1.2.3-54-g00ecf From a9f177e722d80ecbacb0c8e74ea0e8a4b88212be Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 15:13:08 +0100 Subject: Reverted reset_namespace idea. Didn't turn out as clean as I wanted it to. --- archinstall/lib/profiles.py | 12 ++---------- examples/guided.py | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 8284bf40..a0f2dc77 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -125,9 +125,7 @@ class Script(): else: raise ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}") - def load_instructions(self, namespace=None, reset_namespace=False): - original_namespace = self.namespace - + def load_instructions(self, namespace=None): if namespace: self.namespace = namespace @@ -137,12 +135,6 @@ class Script(): print(f"Imported {self} into sys.modules with namespace {self.namespace}") - if '.py' not in self.namespace: - raise KeyError(f"Debugging: {self.namespace}, {reset_namespace}, {self}") - - if reset_namespace: - self.namespace = original_namespace - return self def execute(self): @@ -181,7 +173,7 @@ class Profile(Script): # if __name__ == 'moduleName' if '__name__' in source_data and '_prep_function' in source_data: print(f"Checking if {self} has _prep_function by importing with namespace {self.namespace}.py") - with self.load_instructions(namespace=f"{self.namespace}.py", reset_namespace=True) as imported: + with self.load_instructions(namespace=f"{self.namespace}.py") as imported: if hasattr(imported, '_prep_function'): return True return False diff --git a/examples/guided.py b/examples/guided.py index 4e3dd082..f4fc533b 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -170,7 +170,7 @@ def ask_user_questions(): # Check the potentially selected profiles preperations to get early checks if some additional questions are needed. if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_prep_function(): print(f"{archinstall.arguments['profile']} has prep-function, loading with namespace {archinstall.arguments['profile'].namespace}.py") - with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py", reset_namespace=True) as imported: + 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.', -- cgit v1.2.3-54-g00ecf From 60817334224a8ade4c7e600498fe9bd8f540bf29 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 15:16:41 +0100 Subject: Storing original namespace of profiles as they were during initation. Namespaces now get reverted back to the original state just before .install() is called. This ensures any temporary namespace changes made during prep-checks etc doesn't stick around when we try to install. --- archinstall/lib/profiles.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index a0f2dc77..34ba09da 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -76,6 +76,7 @@ class Script(): self.spec = None self.examples = None self.namespace = os.path.splitext(os.path.basename(self.path))[0] + self.original_namespace = self.namespace print(f"Script {self} loaded with namespace: {self.namespace}") def __enter__(self, *args, **kwargs): @@ -149,7 +150,6 @@ class Script(): class Profile(Script): def __init__(self, installer, path, args={}): super(Profile, self).__init__(path, installer) - self._cache = None def __dump__(self, *args, **kwargs): return {'path' : self.path} @@ -158,6 +158,10 @@ class Profile(Script): return f'Profile({os.path.basename(self.profile)})' def install(self): + # Before installing, revert any temporary changes to the namespace. + # This ensures that the namespace during installation is the original initation namespace. + # (For instance awesome instead of aweosme.py or app-awesome.py) + self.namespace = self.original_namespace return self.execute() def has_prep_function(self): @@ -206,4 +210,11 @@ class Application(Profile): elif parsed_url.scheme in ('https', 'http'): return self.localize_path(self.profile) else: - raise ProfileNotFound(f"Application cannot handle scheme {parsed_url.scheme}") \ No newline at end of file + raise ProfileNotFound(f"Application cannot handle scheme {parsed_url.scheme}") + + def install(self): + # Before installing, revert any temporary changes to the namespace. + # This ensures that the namespace during installation is the original initation namespace. + # (For instance awesome instead of aweosme.py or app-awesome.py) + self.namespace = self.original_namespace + return self.execute() \ No newline at end of file -- cgit v1.2.3-54-g00ecf From 93faf07b6948074e9071faf75f96ff220714d5f9 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 15:25:24 +0100 Subject: Moved the globalization of 'installation' variable. Since Profile() might be created before the installation instance, we need to move the global variable declaration after installation has begun and there's an installation instance. --- archinstall/lib/installer.py | 9 +++++++++ archinstall/lib/profiles.py | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 2604e77d..8d7d6967 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -381,6 +381,15 @@ class Installer(): return self.pacstrap(*packages) def install_profile(self, profile): + # TODO: Replace this with a import archinstall.session instead in the profiles. + # The tricky thing with doing the import archinstall.session instead is that + # profiles might be run from a different chroot, and there's no way we can + # guarantee file-path safety when accessing the installer object that way. + # Doing the __builtins__ replacement, ensures that the global vriable "installation" + # is always kept up to date. It's considered a nasty hack - but it's a safe way + # of ensuring 100% accuracy of archinstall session variables. + __builtins__['installation'] = self.installer + if type(profile) == str: profile = Profile(self, profile) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 34ba09da..ee2ff39a 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -142,7 +142,6 @@ class Script(): if not self.namespace in sys.modules or self.spec is None: self.load_instructions() - __builtins__['installation'] = self.installer # TODO: Replace this with a import archinstall.session instead self.spec.loader.exec_module(sys.modules[self.namespace]) return sys.modules[self.namespace] -- cgit v1.2.3-54-g00ecf From 35e774f5f60e09f5a9a4deb7fb6317d87c9a131f Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 15:28:11 +0100 Subject: Spelling error on variable. --- archinstall/lib/installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 8d7d6967..db73d324 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -388,7 +388,7 @@ class Installer(): # Doing the __builtins__ replacement, ensures that the global vriable "installation" # is always kept up to date. It's considered a nasty hack - but it's a safe way # of ensuring 100% accuracy of archinstall session variables. - __builtins__['installation'] = self.installer + __builtins__['installation'] = self if type(profile) == str: profile = Profile(self, profile) -- cgit v1.2.3-54-g00ecf From cbb4629849a924590dd162f33af7c280241fd992 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 16:25:56 +0100 Subject: Slimmed down awesome further, also removed abandoned community package libu2f-host. --- profiles/awesome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profiles/awesome.py b/profiles/awesome.py index 0e027714..b914b175 100644 --- a/profiles/awesome.py +++ b/profiles/awesome.py @@ -32,7 +32,7 @@ if __name__ == 'awesome': editor = "nano" filebrowser = "nemo gpicview-gtk3" webbrowser = "chromium" # TODO: Ask the user to select one instead - utils = "openssh sshfs git htop pkgfile scrot dhclient wget libu2f-host" + utils = "openssh sshfs htop scrot wget" installation.add_additional_packages(f"{webbrowser} {utils} {filebrowser} {editor}") -- cgit v1.2.3-54-g00ecf From 3baaefb97db79f52f49f1d5e203cf03fb5cb4c86 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 16:35:26 +0100 Subject: Cleaned up after some debugging. --- archinstall/lib/profiles.py | 7 ++----- examples/guided.py | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index ee2ff39a..e9639451 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -1,7 +1,7 @@ import os, urllib.request, urllib.parse, ssl, json, re import importlib.util, sys, glob, hashlib from collections import OrderedDict -from .general import multisplit, sys_command, log +from .general import multisplit, sys_command from .exceptions import * from .networking import * from .output import log, LOG_LEVELS @@ -77,7 +77,7 @@ class Script(): self.examples = None self.namespace = os.path.splitext(os.path.basename(self.path))[0] self.original_namespace = self.namespace - print(f"Script {self} loaded with namespace: {self.namespace}") + log(f"Script {self} has been loaded with namespace '{self.namespace}'") def __enter__(self, *args, **kwargs): self.execute() @@ -133,8 +133,6 @@ class Script(): self.spec = importlib.util.spec_from_file_location(self.namespace, self.path) imported = importlib.util.module_from_spec(self.spec) sys.modules[self.namespace] = imported - - print(f"Imported {self} into sys.modules with namespace {self.namespace}") return self @@ -175,7 +173,6 @@ class Profile(Script): # trigger a traditional: # if __name__ == 'moduleName' if '__name__' in source_data and '_prep_function' in source_data: - print(f"Checking if {self} has _prep_function by importing with namespace {self.namespace}.py") with self.load_instructions(namespace=f"{self.namespace}.py") as imported: if hasattr(imported, '_prep_function'): return True diff --git a/examples/guided.py b/examples/guided.py index f4fc533b..b6aa5810 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -169,7 +169,6 @@ def ask_user_questions(): # Check the potentially selected profiles preperations to get early checks if some additional questions are needed. if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_prep_function(): - print(f"{archinstall.arguments['profile']} has prep-function, loading with namespace {archinstall.arguments['profile'].namespace}.py") with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py") as imported: if not imported._prep_function(): archinstall.log( -- cgit v1.2.3-54-g00ecf From 2fab088314d4d7e9f580376d035db1c2a96e043a Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 16:48:22 +0100 Subject: Added some debugging to help identify why archinstall cannot find unencrypted devices when setting up the boot loader. --- archinstall/lib/installer.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index db73d324..4b964773 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -352,6 +352,7 @@ class Installer(): if self.partition.encrypted: + log(f"Identifying root partition {self.partition} to boot based on disk UUID, looking for '{os.path.basename(self.partition.real_device)}'.", level=LOG_LEVELS.Info) for root, folders, uids in os.walk('/dev/disk/by-uuid'): for uid in uids: real_path = os.path.realpath(os.path.join(root, uid)) @@ -363,6 +364,7 @@ class Installer(): return True break else: + log(f"Identifying root partition {self.partition} to boot based on partition UUID, looking for '{os.path.basename(self.partition.path)}'.", level=LOG_LEVELS.Info) for root, folders, uids in os.walk('/dev/disk/by-partuuid'): for uid in uids: real_path = os.path.realpath(os.path.join(root, uid)) @@ -373,6 +375,7 @@ class Installer(): self.helper_flags['bootloader'] = bootloader return True break + raise RequirementError(f"Could not identify the UUID of {self.partition}, there for {self.mountpoint}/boot/loader/entries/arch.conf will be broken until fixed.") else: raise RequirementError(f"Unknown (or not yet implemented) bootloader added to add_bootloader(): {bootloader}") -- cgit v1.2.3-54-g00ecf From dbe086024d5fc1ab25218f1ea0e063881e66efd6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 16:58:27 +0100 Subject: Moved some info logs into debug instead to minimize user splash. --- archinstall/lib/installer.py | 4 ++-- archinstall/lib/profiles.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 4b964773..1c66f6ac 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -352,7 +352,7 @@ class Installer(): if self.partition.encrypted: - log(f"Identifying root partition {self.partition} to boot based on disk UUID, looking for '{os.path.basename(self.partition.real_device)}'.", level=LOG_LEVELS.Info) + log(f"Identifying root partition {self.partition} to boot based on disk UUID, looking for '{os.path.basename(self.partition.real_device)}'.", level=LOG_LEVELS.Debug) for root, folders, uids in os.walk('/dev/disk/by-uuid'): for uid in uids: real_path = os.path.realpath(os.path.join(root, uid)) @@ -364,7 +364,7 @@ class Installer(): return True break else: - log(f"Identifying root partition {self.partition} to boot based on partition UUID, looking for '{os.path.basename(self.partition.path)}'.", level=LOG_LEVELS.Info) + log(f"Identifying root partition {self.partition} to boot based on partition UUID, looking for '{os.path.basename(self.partition.path)}'.", level=LOG_LEVELS.Debug) for root, folders, uids in os.walk('/dev/disk/by-partuuid'): for uid in uids: real_path = os.path.realpath(os.path.join(root, uid)) diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index e9639451..08b1d618 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -77,7 +77,7 @@ class Script(): self.examples = None self.namespace = os.path.splitext(os.path.basename(self.path))[0] self.original_namespace = self.namespace - log(f"Script {self} has been loaded with namespace '{self.namespace}'") + log(f"Script {self} has been loaded with namespace '{self.namespace}'", level=LOG_LEVELS.Debug) def __enter__(self, *args, **kwargs): self.execute() -- cgit v1.2.3-54-g00ecf From 6a2dd8f5112f6f087772baf647a5c3b961541af5 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 17:11:29 +0100 Subject: Added more debug level information to parted in case it goes heywire. --- archinstall/lib/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 0a182eb0..a1880198 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -397,7 +397,7 @@ class Filesystem(): def raw_parted(self, string:str): x = sys_command(f'/usr/bin/parted -s {string}') - o = b''.join(x) + log(f"'parted -s {string}' returned: {b''.join(x)}", level=LOG_LEVELS.Debug) return x def parted(self, string:str): -- cgit v1.2.3-54-g00ecf From c00e09517fdb5ddfbc4d40b74b11a56795cebfde Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 17:18:00 +0100 Subject: Centralized a partition call to use the logging feature raw_parted(). --- archinstall/lib/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index a1880198..ed5d1b28 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -365,7 +365,7 @@ class Filesystem(): if self.blockdevice.keep_partitions is False: log(f'Wiping {self.blockdevice} by using partition format {self.mode}', level=LOG_LEVELS.Debug) if self.mode == GPT: - if sys_command(f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt',).exit_code == 0: + if self.raw_parted(f'{self.blockdevice.device} mklabel gpt').exit_code == 0: return self else: raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt') -- cgit v1.2.3-54-g00ecf From c8470b81a6f2e8395f74ce0c1168d133fb24b811 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 17:22:11 +0100 Subject: Debugging a partioning case. --- archinstall/lib/disk.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index ed5d1b28..fe891b28 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -437,6 +437,7 @@ class Filesystem(): log(f'Adding partition to {self.blockdevice}', level=LOG_LEVELS.Info) previous_partitions = self.blockdevice.partitions + print(previous_partitions) if format: partitioning = self.parted(f'{self.blockdevice.device} mkpart {type} {format} {start} {end}') == 0 else: @@ -444,6 +445,8 @@ class Filesystem(): if partitioning: start_wait = time.time() + time.sleep(2) + print(self.blockdevice.partitions) while previous_partitions == self.blockdevice.partitions: time.sleep(0.025) # Let the new partition come up in the kernel if time.time() - start_wait > 10: -- cgit v1.2.3-54-g00ecf From 298ed315318e75fe546144b781e4f9e9031d72db Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 17:25:18 +0100 Subject: Added an option to force-flush a blockdevice cache. creating a new Filesystem() now triggers a flush of the cache since all partitions are removed. There shouldn't be any harm in even bypassing the cache, but it's there for a few reasons. --- archinstall/lib/disk.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index fe891b28..efe3f50d 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -129,6 +129,9 @@ class BlockDevice(): return True return False + def flush_cache(self): + self.part_cache = OrderedDict() + class Partition(): def __init__(self, path, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): if not part_id: @@ -366,6 +369,7 @@ class Filesystem(): log(f'Wiping {self.blockdevice} by using partition format {self.mode}', level=LOG_LEVELS.Debug) if self.mode == GPT: if self.raw_parted(f'{self.blockdevice.device} mklabel gpt').exit_code == 0: + self.blockdevice.flush_cache() return self else: raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt') -- cgit v1.2.3-54-g00ecf From 83c0ee4b225d3263b7aa564035130151f8163584 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 21 Mar 2021 17:26:29 +0100 Subject: Removed some debugging output. --- archinstall/lib/disk.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index efe3f50d..b66aa162 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -441,7 +441,6 @@ class Filesystem(): log(f'Adding partition to {self.blockdevice}', level=LOG_LEVELS.Info) previous_partitions = self.blockdevice.partitions - print(previous_partitions) if format: partitioning = self.parted(f'{self.blockdevice.device} mkpart {type} {format} {start} {end}') == 0 else: @@ -449,8 +448,6 @@ class Filesystem(): if partitioning: start_wait = time.time() - time.sleep(2) - print(self.blockdevice.partitions) while previous_partitions == self.blockdevice.partitions: time.sleep(0.025) # Let the new partition come up in the kernel if time.time() - start_wait > 10: -- cgit v1.2.3-54-g00ecf