From da3539c83a1f78f732b3a5bc32849456b0ee550f Mon Sep 17 00:00:00 2001 From: John McQuah Date: Fri, 9 Jun 2023 14:14:44 -0400 Subject: [PATCH] prtorphan.awk: initial import --- scripts/prtorphan.awk | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 scripts/prtorphan.awk diff --git a/scripts/prtorphan.awk b/scripts/prtorphan.awk new file mode 100755 index 0000000..9ce1dbe --- /dev/null +++ b/scripts/prtorphan.awk @@ -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); } + } +}