X-Git-Url: https://code.delx.au/monosys/blobdiff_plain/c3d2224a465f53831ae9c0e54a2cfb899e53868b..012474a44f238e3c4b5316553a23020e1b926e8b:/bin/aptorphan diff --git a/bin/aptorphan b/bin/aptorphan deleted file mode 100755 index 0b1d783..0000000 --- a/bin/aptorphan +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/python3 - -import codecs -import subprocess -import os -import sys - -APTORPHAN_PATH = os.path.expanduser("~/.aptorphan") - -def run(cmd): - result = [] - for line in subprocess.check_output(cmd).decode("utf-8").split("\n"): - line = line.strip() - if line: - result.append(line) - return result - -def strip_comment(line): - pos = line.find("#") - if pos >= 0: - line = line[:pos] - return line.strip() - - -required_config = """ -APT::Install-Recommends "false"; -APT::Install-Suggests "false"; -APT::AutoRemove::RecommendsImportant "false"; -APT::AutoRemove::SuggestsImportant "false"; -""".strip().split("\n") - -actual_config = run(["apt-config", "dump"]) - -missing_lines = [] -for required_line in required_config: - for line in actual_config: - if line == required_line: - break - else: - missing_lines.append(required_line) -if missing_lines: - print("Missing apt-config, add these lines to /etc/apt/apt.conf.d/99recommends-disable") - print("\n".join(missing_lines)) - sys.exit(1) - - - - -keep_pkg_list = [] -mark_explicit_list = [] -need_install_list = [] -installed_pkg_list = [] -explicit_pkg_list = [] - -for filename in os.listdir(APTORPHAN_PATH): - if filename.startswith("."): - continue - filename = os.path.join(APTORPHAN_PATH, filename) - for pkg in codecs.open(filename, "r", "utf-8"): - pkg = strip_comment(pkg) - if pkg in keep_pkg_list: - print("# Duplicate entry: " + pkg) - if pkg: - keep_pkg_list.append(pkg.strip()) - -for pkg in run(["aptitude", "search", "?or(~i!~aremove,~ainstall)", "-F", "%p"]): - installed_pkg_list.append(pkg.strip()) - -for pkg in run(["aptitude", "search", "?or(~i!~M!~aremove,~ainstall!~M)", "-F", "%p"]): - explicit_pkg_list.append(pkg.strip()) - - -for pkg in keep_pkg_list: - if pkg in explicit_pkg_list: - explicit_pkg_list.remove(pkg) - else: - if pkg in installed_pkg_list: - mark_explicit_list.append(pkg) - else: - need_install_list.append(pkg) - - -if mark_explicit_list: - print("# Found packages which should be marked as explicitly installed") - print("sudo aptitude --schedule-only install " + " ".join([("'"+x+"&m'") for x in mark_explicit_list])) - print() - -if need_install_list: - print("# Found packages which should be installed") - print("sudo aptitude --schedule-only install " + " ".join(need_install_list)) - print() - -if explicit_pkg_list: - print("# Found explicitly installed packages to keep or remove") - print("echo " + " ".join(explicit_pkg_list) + " | tr ' ' '\\n' >> ~/.aptorphan/keep") - print("sudo aptitude --schedule-only install " + " ".join([(x+"+M") for x in explicit_pkg_list])) - print() -