From 8ee415e642c146e8b26b1306e2018fce58b79b89 Mon Sep 17 00:00:00 2001 From: jpic Date: Tue, 28 Jan 2020 02:01:27 +0100 Subject: [PATCH] 1337 multiline bash support --- podctl/build.py | 16 ++++++++++++---- podctl/visitors/run.py | 4 +--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/podctl/build.py b/podctl/build.py index febd303..aa0878e 100644 --- a/podctl/build.py +++ b/podctl/build.py @@ -29,14 +29,22 @@ class BuildScript(Script): def config(self, line): self.append(f'buildah config {line} $ctr') - def _run(self, cmd): + def _run(self, cmd, inject=False): user = self.container.variable('username') + _cmd = cmd if cmd.startswith('sudo '): - return f'buildah run --user root $ctr -- {cmd[5:]}' + _cmd = _cmd[5:] + + if '\n' in _cmd.strip(): + # 1337: multiline supports, kindof breaks sudo but really fixes cd + _cmd = ' '.join(['bash -eux <<__EOF\n', _cmd, '\n__EOF']) + + if cmd.startswith('sudo '): + return f'buildah run --user root $ctr -- {_cmd}' elif user and self.container.variable('user_created'): - return f'buildah run --user {user} $ctr -- {cmd}' + return f'buildah run --user {user} $ctr -- {_cmd}' else: - return f'buildah run $ctr -- {cmd}' + return f'buildah run $ctr -- {_cmd}' def run(self, cmd): self.append(self._run(cmd)) diff --git a/podctl/visitors/run.py b/podctl/visitors/run.py index b7472db..6e16577 100644 --- a/podctl/visitors/run.py +++ b/podctl/visitors/run.py @@ -4,6 +4,4 @@ class Run: def build(self, script): for command in self.commands: - for line in command.split('\n'): - if line.strip(): - script.run(line.strip()) + script.run(command)