Skip to content

Commit

Permalink
add apt install command
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Sep 21, 2023
1 parent 500733b commit 3b72722
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/ibek/support_cmds/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,31 @@ def add_to_config_site(
if text != "":
config_site = get_config_site_file(module, host, target)
add_text_once(config_site, text)


@support_cli.command(
context_settings={"allow_extra_args": True, "ignore_unknown_options": True}
)
def apt_install(
ctx: typer.Context,
debs: List[str] = typer.Argument(..., help="list of debian packages to install"),
):
"""
Install debian packages into the container. If they have an http:// or https://
prefix then they will be downloaded and installed from file.
"""
temp = Path("/tmp")

for i, pkg in enumerate(debs):
if pkg.startswith("http://") or pkg.startswith("https://"):
pkg_file = temp / pkg.split("/")[-1]
subprocess.call(["wget", pkg, "-O", str(pkg_file)])
debs[i] = str(pkg_file)

command = (
"apt-get install -y --no-install-recommends "
+ " ".join(debs)
+ " ".join(ctx.args)
)

exit(subprocess.call(["bash", "-c", command]))

0 comments on commit 3b72722

Please sign in to comment.