From ca9944055b2f687c5581cbe5db0b0af4baf18296 Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 13 Nov 2024 00:06:56 -0700 Subject: [PATCH] only install if dependencies are missing --- pwnshop/challenge.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pwnshop/challenge.py b/pwnshop/challenge.py index 6e142b5..69ec976 100644 --- a/pwnshop/challenge.py +++ b/pwnshop/challenge.py @@ -316,14 +316,20 @@ def _create_container(self, image=None): detach=True, volumes = {self.work_dir : {'bind': self.work_dir, 'mode': 'rw'}} ) - ret, out = container.exec_run( - f'/bin/bash -c "apt-get update && apt-get install -y gcc patchelf {" ".join(self.APT_DEPENDENCIES)}"' + + requirements = [ "gcc", "patchelf" ] + self.APT_DEPENDENCIES + _, out = container.exec_run( + f"""/bin/bash -c 'dpkg -l | cut -f3 -d" " | grep -E "^({ "|".join(requirements) })$"'""" ) - if ret != 0: - print("DEPENDENCY INSTALL ERROR:") - print(out.decode('latin1')) - assert ret == 0, out + missing = set(requirements) - set(out.decode().strip().split("\n")) + + if missing: + ret, out = container.exec_run(f'/bin/bash -c "apt-get update && apt-get install -y {" ".join(missing)}"') + if ret != 0: + print("DEPENDENCY INSTALL ERROR:") + print(out.decode('latin1')) + assert ret == 0, out return container