Commit 8bf501e1 authored by segfault's avatar segfault

Enable use of pipes in commands executed in the container

This is required to configure SFTP
parent 527594ea
......@@ -209,7 +209,7 @@ class ContainerManager(object):
self.status_callback(_("Updating package cache"))
self.execute_apt("update", timeout=APT_UPDATE_TIMEOUT)
self.status_callback(_("Downloading packages"))
self.execute_apt("install", "-y", *packages, timeout=APT_INSTALL_TIMEOUT)
self.execute_apt("install -y " + ' '.join(packages), timeout=APT_INSTALL_TIMEOUT)
def bind(self, source: str, target: str):
logger.debug("Bind mounting %r in %r", target, self.name)
......@@ -236,10 +236,10 @@ class ContainerManager(object):
except sh.ErrorReturnCode_1:
return False
def execute_command(self, command: List[str], timeout=30, handle_stderr_line: callable = None):
def execute_command(self, command: str, timeout=30, handle_stderr_line: callable = None):
logger.debug("Executing command in %r: '%s'", self.name, command)
exit_code = None
p = subprocess.Popen(["systemd-run", "--pipe", "--wait", "-M", self.name] + command,
p = subprocess.Popen(["systemd-run", "--pipe", "--wait", "-M", self.name, "/bin/sh", "-c", command],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
......@@ -255,7 +255,8 @@ class ContainerManager(object):
time.sleep(0.2)
if exit_code is None:
raise ContainerError("Timeout while running command '%s' (timeout %s)" % (' '.join(command), timeout))
raise CommandFailedError("Timeout while running command '%s' (timeout %s) stderr: %s" %
(command, timeout, p.stderr.read()))
if handle_stderr_line:
for l in p.stderr.readlines():
......@@ -263,9 +264,9 @@ class ContainerManager(object):
if exit_code != 0:
raise CommandFailedError("Command '%s' failed with exit code %s. stderr: %s" %
(' '.join(command), exit_code, p.stderr.read()))
(command, exit_code, p.stderr.read()))
def execute_apt(self, *args, timeout):
def execute_apt(self, command: str, timeout):
def handle_stderr_line(line):
line = line.strip()
......@@ -276,7 +277,7 @@ class ContainerManager(object):
# Parse APT error
if line.startswith('E:'):
error_message = line[2:]
raise APTError("APT command '%s' failed: %s" % (' '.join(command), error_message))
raise APTError("APT command '%s' failed: %s" % (command, error_message))
# Parse APT status information
# https://github.com/mvo5/apt/blob/master/README.progress-reporting
......@@ -286,7 +287,7 @@ class ContainerManager(object):
elif info[0] == "pmstatus":
self.status_callback(info[3])
command = ["/usr/bin/apt-get", "--option=APT::Status-Fd=2"] + list(args)
command = "/usr/bin/apt-get --option=APT::Status-Fd=2 " + command
self.execute_command(command, timeout=timeout, handle_stderr_line=handle_stderr_line)
@contextmanager
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment