Skip to content

Commit

Permalink
only install if dependencies are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
zardus committed Nov 13, 2024
1 parent 9dc79e6 commit ca99440
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pwnshop/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ca99440

Please sign in to comment.