prtorphan.awk: initial import

This commit is contained in:
John McQuah 2023-06-09 14:14:44 -04:00
parent 64a5505821
commit da3539c83a
1 changed files with 47 additions and 0 deletions

47
scripts/prtorphan.awk Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/awk -f
#
# reimplementation in awk of the prtorphan script by Opel (2003).
# Only detects installed ports that have been dropped from the repos,
# does NOT accept the argument '-d' to activate directory mode.
BEGIN {
RS="\n\n"; FS="\n";
while ( (getline < "/var/lib/pkg/db") > 0 ) {
Version[$1] = $2;
}
RS="\n"; FS=" ";
while ( (getline line < "/etc/prt-get.conf") > 0 ) {
if (line ~ /^prtdir /) {
sub(/^prtdir /,"",line);
sub(/ #.*$/,"",line);
if (line !~ /:/) {
portdirs[line] = 1;
} else {
split(line,a,":");
base = a[1];
split(a[2],filter,",");
for (i in filter) {
portdirs[(base "/" filter[i])] = 1;
}
}
}
}
for (dir in portdirs) {
ports = "find " dir " -name Pkgfile -printf '%h\n'";
while ((ports | getline entry) > 0 ) {
sub(/.*\//,"",entry);
if (entry == ".") {
validports[dir] = 1;
} else {
validports[entry] = 1;
}
}
}
# print the orphaned ports
for (name in Version) {
if (! (name in validports)) { printf("%s\n",name); }
}
}