From 8b81550c96e30fce95d273cd6e53d144d88b6f59 Mon Sep 17 00:00:00 2001 From: Aaruni Kaushik Date: Thu, 1 Oct 2026 18:09:29 +0200 Subject: [PATCH 1/8] Add magma mode to UI and runtime mode --- src/maps | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 114 insertions(+), 6 deletions(-) diff --git a/src/maps b/src/maps index d498f08..0141b2d 100755 --- a/src/maps +++ b/src/maps @@ -111,6 +111,8 @@ def addCLI(): default=False, help="Export a runtime as a URL which maps can open") parser_runtime.add_argument('--export-tar', dest='EXPORTTAR', action='store', default=False, help="Export a runtime as a compressed tarball") + parser_runtime.add_argument('--magma', dest='MAGMA', action='store_true', + default=False, help="Enable magma mode") # arguments for remote management parser_remote = subparser.add_parser("remote", @@ -530,7 +532,97 @@ def disambiguate_runtime(repo: OSTree.Repo, rrstring: str, installed: bool = Tru return ["notfound", "notfound"] -def make_bwrap_command(location, overlay, command, nogui, gui): +def get_magma_root(magmapath): + """ + This subroutine takes path to the magma driver script, and then returns both the driver script, + and the inferred magma root path. + """ + magmarootpath = "" + with open(magmapath,'r') as magmafile: + for line in magmafile: + line = line.strip() + if line.startswith("ROOT"): + magmarootpath = line.split('=')[-1].strip('"').strip("'") + break + if not magmarootpath: + if VERBOSE: + print("Unable to find ROOT directive in magma driver file. Is magma correctly installed?") + print("Trying to infer maga root from path, but this might fail.....") + + if not magmarootpath or magmarootpath == "....": + # do the magma logic to infer magma root + magmarootpath = '/'.join(magmapath.split('/')[0:-1]) + + return magmarootpath + + +def find_magma_path(magmapath=""): + """ + This subroutine tries to discover an installation of magma, and returns with the paths of the + magma driver script, and the magma root. + """ + provided_path = True + if not magmapath: + # check if magma is installed in "the right place" + magmapath = '/usr/local/magma' + provided_path = False + + found = False + if os.path.exists(magmapath): + if VERBOSE: + if provided_path: + print("Found magma at the provided path") + else: + print("Found the standard magma path") + print(magmapath) + found = True + + if not found: + if provided_path: + print("The magma driver script was not found at the provided path!") + print("Please double check the provided path") + print(magmapath) + print("Alternatively, do not provide a path to try to discover a magma installation") + sys.exit(-9) + + # try to discover magma in the usual suspected places + if VERBOSE: + print(f"magma was not found at the standard path of {magmapath}") + print("Trying to discover via $PATH") + mypath = os.getenv("PATH") + if not mypath: + print("Could not read the PATH variable! This is a fatal error! Please contact support") + sys.exit(-10) + mypath = mypath.split(':') + if VERBOSE: + print("The discovered PATH is") + print(mypath) + for path in mypath: + if VERBOSE: + print(f"Checking {path} for magma...") + magmapath = f"{path}/magma" + if os.path.isfile(magmapath): + print("found magma!") + found = True + break + if not found: + print("Unable to discover magma. This is a fatal error in magma mode. Crashing...") + sys.exit(-11) + + # get the magma root + magmarootpath = get_magma_root(magmapath) + if not magmarootpath: + print("Unable to find magma root! Crashing...") + sys.exit(-12) + if not os.path.isdir(magmarootpath): + print("Discovered magma root was not a directory!") + print(magmarootpath) + sys.exit(-13) + + return magmapath, magmarootpath + + +def make_bwrap_command(location, overlay, command, nogui, gui, magma=False): """ Subroutine builds the bubblewrap command to execute """ @@ -546,6 +638,11 @@ def make_bwrap_command(location, overlay, command, nogui, gui): # add the resolv.conf file bwrapstring += '--ro-bind-try /etc/resolv.conf /etc/resolv.conf ' + if magma: + magmapath, magmarootpath = find_magma_path() + bwrapstring += f"--ro-bind {magmapath} {magmapath} --ro-bind {magmarootpath} {magmarootpath}" + + try: session = senv['XDG_SESSION_TYPE'] except KeyError: @@ -687,14 +784,25 @@ def mode_run(repo, args): # check for manifest file if os.path.isfile(f"{DATADIR}/rwfs/manifest.toml"): with open(f"{DATADIR}/rwfs/manifest.toml", 'rb') as manifest_file: - command = tomli.load(manifest_file) - command = command['Core']["command"] + manifest = tomli.load(manifest_file) + command = manifest['Core']["command"] + if manifest['Core'].get('magma'): + magma = True + else: + magma = False elif os.path.isfile(f"{DATADIR}/rofs/manifest.toml"): with open(f"{DATADIR}/rofs/manifest.toml", 'rb') as manifest_file: - command = tomli.load(manifest_file) - command = command['Core']["command"] + manifest = tomli.load(manifest_file) + command = manifest['Core']["command"] + if manifest['Core'].get('magma'): + magma = True + else: + magma = False else: command = "bash" + magma = False + if args.MAGMA: + magma = True if args.COMMAND: command = args.COMMAND if command == '': @@ -702,7 +810,7 @@ def mode_run(repo, args): # launch sandbox print(f"Launching {remote}:{runtime}...") # construct bwrapstring - bwrapstring, senv = make_bwrap_command(f"{DATADIR}", True, command, args.NOGUI, args.GUI) + bwrapstring, senv = make_bwrap_command(f"{DATADIR}", True, command, args.NOGUI, args.GUI, magma) rstatus = subprocess.run(bwrapstring.split(), env=senv, check=False) if rstatus.returncode != 0: From 53ca6f7def74ca36ed6ceef963f8ad01e8f65a9b Mon Sep 17 00:00:00 2001 From: Aaruni Kaushik Date: Mon, 5 Oct 2026 14:46:43 +0200 Subject: [PATCH 2/8] Lint most stuff --- pylint.toml | 2 +- src/maps | 37 +++++++++++++++++-------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/pylint.toml b/pylint.toml index e1d09d6..7e52e4e 100644 --- a/pylint.toml +++ b/pylint.toml @@ -91,7 +91,7 @@ py-version = "3.11" # When enabled, pylint would attempt to guess common misconfiguration and emit # user-friendly hints instead of false-positive error messages. -suggestion-mode = true +#suggestion-mode = true # Allow loading of arbitrary C extensions. Extensions are imported into the # active Python interpreter and may run arbitrary code. diff --git a/src/maps b/src/maps index 0141b2d..4e6bb27 100755 --- a/src/maps +++ b/src/maps @@ -538,7 +538,7 @@ def get_magma_root(magmapath): and the inferred magma root path. """ magmarootpath = "" - with open(magmapath,'r') as magmafile: + with open(magmapath, 'r', encoding='UTF-8') as magmafile: for line in magmafile: line = line.strip() if line.startswith("ROOT"): @@ -546,7 +546,9 @@ def get_magma_root(magmapath): break if not magmarootpath: if VERBOSE: - print("Unable to find ROOT directive in magma driver file. Is magma correctly installed?") + print( + "Unable to find ROOT directive in magma driver file. Is magma correctly installed?" + ) print("Trying to infer maga root from path, but this might fail.....") if not magmarootpath or magmarootpath == "....": @@ -566,7 +568,7 @@ def find_magma_path(magmapath=""): # check if magma is installed in "the right place" magmapath = '/usr/local/magma' provided_path = False - + found = False if os.path.exists(magmapath): if VERBOSE: @@ -584,7 +586,7 @@ def find_magma_path(magmapath=""): print(magmapath) print("Alternatively, do not provide a path to try to discover a magma installation") sys.exit(-9) - + # try to discover magma in the usual suspected places if VERBOSE: print(f"magma was not found at the standard path of {magmapath}") @@ -608,7 +610,7 @@ def find_magma_path(magmapath=""): if not found: print("Unable to discover magma. This is a fatal error in magma mode. Crashing...") sys.exit(-11) - + # get the magma root magmarootpath = get_magma_root(magmapath) if not magmarootpath: @@ -640,8 +642,8 @@ def make_bwrap_command(location, overlay, command, nogui, gui, magma=False): if magma: magmapath, magmarootpath = find_magma_path() - bwrapstring += f"--ro-bind {magmapath} {magmapath} --ro-bind {magmarootpath} {magmarootpath}" - + bwrapstring += f"--ro-bind {magmapath} {magmapath} --ro-bind {magmarootpath} " + \ + "{magmarootpath}" try: session = senv['XDG_SESSION_TYPE'] @@ -782,27 +784,22 @@ def mode_run(repo, args): sys.exit(-1) # lets decide, -1 is for all mkdir errors # check for manifest file + manifestpath = "" if os.path.isfile(f"{DATADIR}/rwfs/manifest.toml"): - with open(f"{DATADIR}/rwfs/manifest.toml", 'rb') as manifest_file: - manifest = tomli.load(manifest_file) - command = manifest['Core']["command"] - if manifest['Core'].get('magma'): - magma = True - else: - magma = False + manifestpath = f"{DATADIR}/rwfs/manifest.toml" elif os.path.isfile(f"{DATADIR}/rofs/manifest.toml"): - with open(f"{DATADIR}/rofs/manifest.toml", 'rb') as manifest_file: + manifestpath = f"{DATADIR}/rofs/manifest.toml" + + if manifestpath: + with open(manifestpath, 'rb') as manifest_file: manifest = tomli.load(manifest_file) command = manifest['Core']["command"] - if manifest['Core'].get('magma'): - magma = True - else: - magma = False + magma = bool(manifest['Core'].get('magma')) else: command = "bash" magma = False if args.MAGMA: - magma = True + magma = True if args.COMMAND: command = args.COMMAND if command == '': From e60dda2b0568ad61e730d5b65df6bb929ae16efb Mon Sep 17 00:00:00 2001 From: Aaruni Kaushik Date: Tue, 6 Oct 2026 11:46:05 +0200 Subject: [PATCH 3/8] Export magmapath to runtime --- src/maps | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/maps b/src/maps index 4e6bb27..40055cf 100755 --- a/src/maps +++ b/src/maps @@ -640,10 +640,11 @@ def make_bwrap_command(location, overlay, command, nogui, gui, magma=False): # add the resolv.conf file bwrapstring += '--ro-bind-try /etc/resolv.conf /etc/resolv.conf ' + magmapath = "" if magma: magmapath, magmarootpath = find_magma_path() bwrapstring += f"--ro-bind {magmapath} {magmapath} --ro-bind {magmarootpath} " + \ - "{magmarootpath}" + f"{magmarootpath} " try: session = senv['XDG_SESSION_TYPE'] @@ -693,6 +694,8 @@ def make_bwrap_command(location, overlay, command, nogui, gui, magma=False): senv['SHELL'] = '/usr/bin/bash' senv['PATH'] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:'\ '/usr/local/games' + if magmapath: + senv['PATH'] += f":{'/'.join(magmapath.split('/')[0:-1])}" if TERM is not None: senv['TERM'] = TERM else: From c7db317299c4bc069ecc22f141d016dbedd90806 Mon Sep 17 00:00:00 2001 From: Aaruni Kaushik Date: Tue, 6 Oct 2026 12:00:51 +0200 Subject: [PATCH 4/8] magma mode in sandbox mode --- src/maps | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/maps b/src/maps index 40055cf..01c0c5d 100755 --- a/src/maps +++ b/src/maps @@ -146,6 +146,8 @@ def addCLI(): default=False, help="Disable GUI") parser_pack.add_argument('--gui', dest="GUI", action='store_true', default=False, help="Force enable GUI") + parser_pack.add_argument('--magma', dest="MAGMA", action='store_true', + default=False, help="Enable magma mode") return parser, parser_runtime, parser_remote, parser_pack @@ -1144,7 +1146,7 @@ def mode_package(repo, repopath, args): # its the user's responsibility to ensure the tree is good print(f"Launching a sandbox in {args.LOCATION}...") bwrapstring, senv = make_bwrap_command(args.LOCATION, False, "/usr/bin/bash", args.NOGUI, - args.GUI) + args.GUI, args.MAGMA) rstatus = subprocess.run(bwrapstring.split(), env=senv, check=False) if VERBOSE: print("Exiting sandbox...") From 3ea4d079bb8102858aed4c7987ab45ca3b3d1741 Mon Sep 17 00:00:00 2001 From: Aaruni Kaushik Date: Tue, 6 Oct 2026 12:05:37 +0200 Subject: [PATCH 5/8] More resilient reading of manifest --- src/maps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/maps b/src/maps index 01c0c5d..959d171 100755 --- a/src/maps +++ b/src/maps @@ -798,7 +798,7 @@ def mode_run(repo, args): if manifestpath: with open(manifestpath, 'rb') as manifest_file: manifest = tomli.load(manifest_file) - command = manifest['Core']["command"] + command = manifest['Core']["command"] if manifest['Core'].get("command") else "bash" magma = bool(manifest['Core'].get('magma')) else: command = "bash" From 5e26add2c4b5e5ddfe1fff38b0353b37b9d44c6e Mon Sep 17 00:00:00 2001 From: Aaruni Kaushik Date: Tue, 6 Oct 2026 14:56:33 +0200 Subject: [PATCH 6/8] Move print behind verbose check --- src/maps | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/maps b/src/maps index 959d171..a2f433b 100755 --- a/src/maps +++ b/src/maps @@ -606,7 +606,8 @@ def find_magma_path(magmapath=""): print(f"Checking {path} for magma...") magmapath = f"{path}/magma" if os.path.isfile(magmapath): - print("found magma!") + if VERBOSE: + print("found magma!") found = True break if not found: From 66b2fca2a97a2e78b963eadef8a419509f4cbfe7 Mon Sep 17 00:00:00 2001 From: Aaruni Kaushik Date: Thu, 29 Oct 2026 17:27:28 +0100 Subject: [PATCH 7/8] Try to resolve bash variables --- src/maps | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/maps b/src/maps index a2f433b..d942301 100755 --- a/src/maps +++ b/src/maps @@ -534,6 +534,40 @@ def disambiguate_runtime(repo: OSTree.Repo, rrstring: str, installed: bool = Tru return ["notfound", "notfound"] +def resolve_bash_var(bvar:str, fpath:str) -> str: + if not '$' in bvar: + return bvar + lvar = bvar.split('=')[0] + cvars = bvar.split('=')[-1].strip().strip('"').strip("'").split('/') + dvar = '' + for v in cvars: + if '$' in v: + dvar = v[1:] + break + if dvar: + # a variable was used, but we don't really know where it came from... + evar = "" + if os.getenv(dvar): + # try the env vars first + evar = os.getenv(dvar) + else: + # try reading the file for variable assignment + with open(fpath, 'r') as bfile: + for line in bfile: + if line.strip().startswith(f"{dvar}="): + evar = line.split('=')[1].strip().strip('"').strip("'") + break + # even more else: what if the driver file is evil, and sources some other bash files first? + # could try to scan through the driver file for source keywords, but will attempt that if + # we actually run into that problem. + if evar: + cvars[cvars.index(f"${dvar}")] = evar + bvar = '/'.join(cvars) + if '$' in bvar: + return resolve_bash_var(f"{lvar}='{bvar}'", fpath) + return f"{lvar}='{bvar}'" + + def get_magma_root(magmapath): """ This subroutine takes path to the magma driver script, and then returns both the driver script, @@ -557,6 +591,10 @@ def get_magma_root(magmapath): # do the magma logic to infer magma root magmarootpath = '/'.join(magmapath.split('/')[0:-1]) + # in case magmaroothpath has bash variables in it, attempt to resolve them + # if not, the function is basically a no-op. + magmarootpath = resolve_bash_var(magmarootpath, magmapath) + return magmarootpath From 44c2a96a8dc20aea5b3cdf0debf444d8896668f4 Mon Sep 17 00:00:00 2001 From: Aaruni Kaushik Date: Wed, 4 Nov 2026 17:15:35 +0100 Subject: [PATCH 8/8] Add ability to manually mount paths for magma --- src/maps | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/maps b/src/maps index d942301..320f690 100755 --- a/src/maps +++ b/src/maps @@ -113,6 +113,8 @@ def addCLI(): default=False, help="Export a runtime as a compressed tarball") parser_runtime.add_argument('--magma', dest='MAGMA', action='store_true', default=False, help="Enable magma mode") + parser_runtime.add_argument('--magma-path', dest='MAGMA_PATH', action="store", + default=False, help="Paths to mount in as magma") # arguments for remote management parser_remote = subparser.add_parser("remote", @@ -148,6 +150,8 @@ def addCLI(): default=False, help="Force enable GUI") parser_pack.add_argument('--magma', dest="MAGMA", action='store_true', default=False, help="Enable magma mode") + parser_pack.add_argument('--magma-path', dest='MAGMA_PATH', action="store", + default=False, help="Paths to mount in as magma") return parser, parser_runtime, parser_remote, parser_pack @@ -665,7 +669,7 @@ def find_magma_path(magmapath=""): return magmapath, magmarootpath -def make_bwrap_command(location, overlay, command, nogui, gui, magma=False): +def make_bwrap_command(location, overlay, command, nogui, gui, magma=False, inmagmapath=""): """ Subroutine builds the bubblewrap command to execute """ @@ -683,9 +687,13 @@ def make_bwrap_command(location, overlay, command, nogui, gui, magma=False): magmapath = "" if magma: - magmapath, magmarootpath = find_magma_path() - bwrapstring += f"--ro-bind {magmapath} {magmapath} --ro-bind {magmarootpath} " + \ - f"{magmarootpath} " + if inmagmapath: + for path in inmagmapath.split(':'): + bwrapstring += f"--ro-bind {path} {path} " + else: + magmapath, magmarootpath = find_magma_path() + bwrapstring += f"--ro-bind {magmapath} {magmapath} --ro-bind {magmarootpath} " + \ + f"{magmarootpath} " try: session = senv['XDG_SESSION_TYPE'] @@ -851,7 +859,8 @@ def mode_run(repo, args): # launch sandbox print(f"Launching {remote}:{runtime}...") # construct bwrapstring - bwrapstring, senv = make_bwrap_command(f"{DATADIR}", True, command, args.NOGUI, args.GUI, magma) + bwrapstring, senv = make_bwrap_command(f"{DATADIR}", True, command, args.NOGUI, args.GUI, magma, + args.MAGMA_PATH) rstatus = subprocess.run(bwrapstring.split(), env=senv, check=False) if rstatus.returncode != 0: @@ -1185,7 +1194,7 @@ def mode_package(repo, repopath, args): # its the user's responsibility to ensure the tree is good print(f"Launching a sandbox in {args.LOCATION}...") bwrapstring, senv = make_bwrap_command(args.LOCATION, False, "/usr/bin/bash", args.NOGUI, - args.GUI, args.MAGMA) + args.GUI, args.MAGMA, args.MAGMA_PATH) rstatus = subprocess.run(bwrapstring.split(), env=senv, check=False) if VERBOSE: print("Exiting sandbox...")