1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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])
|