diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index 814556f8b..7ded1f375 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -48,7 +48,7 @@ class UnpackEntry: :param destination: """ __slots__ = ('source', 'sourcefs', 'destination', 'copied', 'total', 'exclude', 'excludeFile', - 'mountPoint', 'weight') + 'mountPoint', 'weight', 'include') def __init__(self, source, sourcefs, destination): """ @@ -71,6 +71,7 @@ class UnpackEntry: self.total = 0 self.mountPoint = None self.weight = 1 + self.include = True def is_file(self): return self.sourcefs == "file" @@ -419,6 +420,18 @@ def extract_weight(entry): return 1 +def fetch_from_globalstorage(keys_list): + value = libcalamares.globalstorage.value(keys_list[0]) + if value is None: + return None + for key in keys_list[1:]: + if isinstance(value, dict) and key in value: + value = value[key] + else: + return None + return value + + def run(): """ Unsquash filesystem. @@ -474,6 +487,28 @@ def run(): sourcefs = entry["sourcefs"] destination = os.path.abspath(root_mount_point + entry["destination"]) + include = entry.get("include", True) + if isinstance(include, bool): + pass # 'include' is already True or False + elif isinstance(include, str): + keys = include.split(".") + gs_value = fetch_from_globalstorage(keys) + if gs_value is None: + libcalamares.utils.warning("Include key '{}' not found in global storage, assuming False".format(include)) + include = False + elif isinstance(gs_value, bool): + include = gs_value + else: + libcalamares.utils.warning("Include key '{}' is not a boolean, assuming True".format(include)) + include = True + else: + libcalamares.utils.warning("Invalid 'include' value '{}', assuming True".format(include)) + include = True + + if not include: + libcalamares.utils.debug("Skipping unpack of {} due to 'include' being False".format(source)) + continue + if not os.path.isdir(destination) and sourcefs != "file": libcalamares.utils.warning(("The destination \"{}\" in the target system is not a directory").format(destination)) if is_first: diff --git a/src/modules/unpackfs/unpackfs.conf b/src/modules/unpackfs/unpackfs.conf index d12110b60..57ff45efd 100644 --- a/src/modules/unpackfs/unpackfs.conf +++ b/src/modules/unpackfs/unpackfs.conf @@ -86,6 +86,19 @@ # of trailing slashes apply. In order to *rename* a file as it is # copied, specify one single file (e.g. CHANGES) and a full pathname # for its destination name, as in the example below. +# +# It is also possible to dynamically include a source by passing a boolean +# This is used in e.g. stacked squashfses, where the user can select a specific +# install type. The default is true. +# +# - source: ./example.minimal.sqfs +# sourcefs: squashfs +# destination: "" +# include: false +# - source: ./example.standard.sqfs +# sourcefs: squashfs +# destination: "" +# include: exampleGlobalStorageVariable unpack: - source: ../CHANGES diff --git a/src/modules/unpackfs/unpackfs.schema.yaml b/src/modules/unpackfs/unpackfs.schema.yaml index 0d96fe9cb..4d412c5fb 100644 --- a/src/modules/unpackfs/unpackfs.schema.yaml +++ b/src/modules/unpackfs/unpackfs.schema.yaml @@ -18,4 +18,8 @@ properties: excludeFile: { type: string } exclude: { type: array, items: { type: string } } weight: { type: integer, exclusiveMinimum: 0 } + include: + anyOf: + - type: boolean + - type: string required: [ source , sourcefs, destination ]