Dedent cmd

This commit is contained in:
jpic 2020-01-31 21:56:13 +01:00
parent 7e9af1fe35
commit 0408590c4f

View File

@ -1,3 +1,5 @@
import textwrap
from .script import Script from .script import Script
@ -31,11 +33,18 @@ class BuildScript(Script):
def _run(self, cmd, inject=False): def _run(self, cmd, inject=False):
user = self.container.variable('username') user = self.container.variable('username')
_cmd = cmd _cmd = textwrap.dedent(cmd)
if cmd.startswith('sudo '): if cmd.startswith('sudo '):
_cmd = _cmd[5:] _cmd = _cmd[5:]
_cmd = ' '.join(['bash -eux <<__EOF\n', _cmd.strip(), '\n__EOF']) heredoc = False
for i in ('\n', '>', '<', '|', '&'):
if i in _cmd:
heredoc = True
break
if heredoc:
_cmd = ' '.join(['bash -eux <<__EOF\n', _cmd.strip(), '\n__EOF'])
if cmd.startswith('sudo '): if cmd.startswith('sudo '):
return f'buildah run --user root $ctr -- {_cmd}' return f'buildah run --user root $ctr -- {_cmd}'