This checks the contents of every package for existance and calculates a percentage of the existing files versus the reported files by 'pkg_info -L'. Since I did a full upgrade of the system before I fscked it up, I knew all files would be in place, so my threshold was at 99%. I guess you don't want to change this.
The script:
#!/bin/sh # pkg_deregister.sh by S. Smeenk <ssmeenk@freshdot.net> for DIR in /var/db/pkg/* do FILES=`pkg_info -L "$DIR" | grep "^/" | wc -l | sed -e 's/ //g'` CNT=0 for FILE in `pkg_info -L "$DIR" | grep "^/"` do if [ -e $FILE ]; then CNT=`expr $CNT + 1` fi done PER=`echo "(100/$FILES)*$CNT" | bc -l | cut -d'.' -f1` if [ $PER -lt 99 ]; then echo $DIR fi done