wally fatboy klingon
Fight ePatents in Europe!
Get FireFox
I'm a hacker!
Valid CSS!
Valid HTML 4.01!
 
I once fscked up my FreeBSD package database in /var/db/pkg/ by unpacking a backup from a different server right over it. I know I should have been more careful, but I wasn't, so now I had a broken packagelist. The system thought all those packages were installed while they actually weren't. Running 'pkgdb -F' didn't fix it, and I couldn't think of any other solution, so I made my own.

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