forked from Rosuav/shed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkgsources.pike
32 lines (32 loc) · 1.19 KB
/
pkgsources.pike
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
int main()
{
sscanf(Process.run(({"dpkg", "--get-selections"}))->stdout, "%{%s%*[\t]%s\n%}", array info);
array(string) purge = ({ }), auto = ({ });
mapping(string:int) sources = ([]), activesources = ([]);
foreach (info; int i; [string pkg, string status])
{
if (status == "deinstall") {purge += ({pkg}); continue;}
if (status != "install") {write("UNKNOWN STATUS %O %O\n", pkg, status); continue;}
int flagged = 0;
write("[%d/%d] %s\e[K\r", i, sizeof(info), pkg);
foreach (Process.run(({"apt-cache", "policy", pkg}))->stdout/"\n", string line)
{
if (has_prefix(line, " ***")) flagged = 1;
else if (has_prefix(line, " "))
{
++sources[line];
if (!flagged) continue;
++activesources[line];
if (!has_value(line, "ubuntu")) continue;
write("%s %s\n", pkg, String.trim_all_whites(line));
if (has_prefix(pkg, "lib")) auto += ({pkg});
}
else flagged = 0;
}
}
write("\e[K");
write("All sources: %O\n", sources);
write("Active sources: %O\n", activesources);
if (sizeof(purge)) write("sudo apt-get purge%{ %s%}\n", purge); //Don't actually do it, just give the user the option.
if (sizeof(auto)) write("sudo apt-mark auto%{ %s%}\n", auto); //Ditto
}