diff options
Diffstat (limited to 'packages/official.py')
-rw-r--r-- | packages/official.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/packages/official.py b/packages/official.py new file mode 100644 index 0000000..785f1cd --- /dev/null +++ b/packages/official.py @@ -0,0 +1,58 @@ +from commia.prelude import * +from commia.ssh import ssh_args +from commia.util import check_continue, read_ini, read_inilist + +sections = read_inilist("packages/packages.inil", ["explicit", "ignore", "deny"]) +aur = set(read_ini("packages/aur.ini")["default"].keys()) + +pac_explicit = set( + run_sc([*ssh_args(), "pacman", "-Qqe"], text=True).stdout.splitlines() +) +pac_all = set(run_sc([*ssh_args(), "pacman", "-Qq"], text=True).stdout.splitlines()) + +explicit_check = sections["explicit"] - pac_explicit +to_install = explicit_check - pac_all +to_mark_explicit = explicit_check.intersection(pac_all) +to_mark_dep = pac_explicit - (sections["explicit"].union(sections["ignore"]).union(aur)) + +for package in to_install: + deps = set( + run_sc( + [*ssh_args(), "pacman", "-Sp", "--print-format", "%n", package] + ).stdout.splitlines() + ) + deny = deps & sections["deny"] + for deny in deny: + print(f"package {package} depends on banned package {deny}") + exit(1) + +for package in sections["deny"]: + if run_silent([*ssh_args(), "pacman", "-Q", package]).returncode == 0: + print(f"banned package {package} already installed") + exit(1) + +if len(to_install) > 0: + print("to install:", " ".join(to_install)) + +if len(to_mark_explicit) > 0: + print("to mark explicit:", " ".join(to_mark_explicit)) + +if len(to_mark_dep) > 0: + print("to mark dependency:", " ".join(to_mark_dep)) + +if len(to_install) + len(to_mark_explicit) + len(to_mark_dep) > 0 and check_continue(): + if len(to_install) > 0: + run_check([*ssh_args(), "pacman", "-Sy", "--noconfirm", *to_install]) + + if len(to_mark_explicit) > 0: + run_check([*ssh_args(), "pacman", "-D", "--asexplicit", *to_mark_explicit]) + + if len(to_mark_dep) > 0: + run_check([*ssh_args(), "pacman", "-D", "--asdep", *to_mark_dep]) + +cleanup = run_silent([*ssh_args(), "pacman", "-Qdtq"], text=True).stdout.splitlines() +if len(cleanup) > 0: + print("to cleanup:", " ".join(cleanup)) + if not check_continue(): + exit() + run_check([*ssh_args(), "pacman", "-Rs", "--noconfirm", *cleanup]) |