#!/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); } } }