From 390db5620fbc8af59bea42b650b723f967838d64 Mon Sep 17 00:00:00 2001 From: Mirko Brombin Date: Thu, 1 Dec 2022 10:37:18 +0100 Subject: [PATCH] core: Support for outRun bang can be used to execute commands outsie of the main shell script --- vanilla_first_setup/utils/processor.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/vanilla_first_setup/utils/processor.py b/vanilla_first_setup/utils/processor.py index 4fababe..a0956a3 100644 --- a/vanilla_first_setup/utils/processor.py +++ b/vanilla_first_setup/utils/processor.py @@ -29,6 +29,7 @@ class Processor: @staticmethod def run(log_path, pre_run, post_run, commands): commands = pre_run + commands + post_run + out_run = "" abroot_bin = shutil.which("abroot") logger.info("processing the following commands: \n%s" % @@ -44,6 +45,11 @@ class Processor: for command in commands: if command.startswith("!noSudo"): command = command.replace("!noSudo", "sudo -u $USER") + + # outRun band is used to run a command outside of the main + # shell script. + if command.startswith("!outRun"): + out_run += command.replace("!outRun", "") + "\n" f.write(f"{command}\n") @@ -89,4 +95,9 @@ class Processor: if os.path.exists(autostart_file): os.remove(autostart_file) + # run the outRun commands + if out_run: + logger.info("running outRun commands: \n%s" % out_run) + subprocess.run(out_run, shell=True) + return True