#!/usr/bin/env python3 from subprocess import run, DEVNULL, PIPE, STDOUT PACKAGES = [ "bsd-mailx", # for "mail" command used in tester "python3-apt", # for: test_apt "python3-defusedxml", # for: test_wowza "python3-dnspython", # for: test_caches "python3-openssl", # for: test_ssl "python3-psutil", # for: test_wowza "python3-psycopg2", # for: test_postgresql "python3-pydbus", # for: test_dns_records "python3-requests", # for: test_nginx_status, test_nginx_vhosts, test_ssl, test_apt_proxy, test_ubicast_packages_access "python3-spf", # for: test_email ] 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-get", "install", "-q", "-y", pkg, ], shell=False, stdout=PIPE, stderr=STDOUT, stdin=PIPE, env={"DEBIAN_FRONTEND": "noninteractive"}, ) 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()