#!/usr/bin/env python3

from subprocess import run, DEVNULL, PIPE

PACKAGES = [
    "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=DEVNULL,
                stderr=DEVNULL,
                stdin=PIPE,
            )
            if not result:
                print("{} install succeeded".format(pkg))
            else:
                print("{} install failed".format(pkg))
        else:
            print("{} already installed".format(pkg))


if __name__ == "__main__":
    main()