Skip to content
Snippets Groups Projects
pkgs_envsetup.py 1.01 KiB
#!/usr/bin/env python3

from subprocess import run, DEVNULL, PIPE, STDOUT

PACKAGES = [
    "bsd-mailx",  # for "mail" command used in tester
    "python3-defusedxml",
    "python3-openssl",
    "python3-psutil",
    "python3-requests",
    "python3-spf",
]


def main():
    for pkg in PACKAGES:
        if run(
            ["/usr/bin/dpkg", "-s", pkg],
            shell=False,
            stdout=DEVNULL,
            stderr=DEVNULL,
            stdin=PIPE,
        ).returncode != 0:
            result = run(
                ["/usr/bin/apt", "install", "-y", pkg],
                shell=False,
                stdout=PIPE,
                stderr=STDOUT,
                stdin=PIPE,
            )
            if result.returncode == 0:
                print("{} install succeeded".format(pkg))
            else:
                print("{} install failed".format(pkg))
                print(result.stdout.decode("utf-8"))
        else:
            print("{} already installed".format(pkg))


if __name__ == "__main__":
    main()