Subject: pkgdb regeneration
To: None <tech-pkg@netbsd.org>
From: pancake <pancake@phreaker.net>
List: tech-pkg
Date: 08/09/2004 18:03:57
I wrote a 5m shellscript that walks throught pkgsrc tree looking for files and tries to give a list of the installed packages. This is useful on pkgdb destruction or lost packages.
I think that anybody could be interested on that:
#!/bin/sh
#
# pkgsrc db regenerator
#
PKGSRC=/usr/pkgsrc
PREFIX=/usr/pkg
MARGIN=5
cd ${PKGSRC}
echo "Loading pkgsrc tree...";
DIRS=`find . -type d -maxdepth 2 -mindepth 2`
echo "Comparing PLIST against /usr/pkg prefix... ";
for A in ${DIRS} ; do
if [ -e "$A/PLIST" ]; then
FILES=`grep -v -e ^\@ $A/PLIST`;
TOTAL=0;
FOUND=0;
for B in ${FILES}; do
if [ -e "${PREFIX}/${B}" ]; then
FOUND=`echo ${FOUND}+1|bc`;
fi
TOTAL=`echo ${TOTAL}+1|bc`;
done
# Margin implementation
test ${TOTAL} -gt ${MARGIN}
if [ "$?" = "0" ]; then
FOUNT=`echo ${FOUND}+${MARGIN}-${TOTAL}|bc`;
test ${FOUNT} -gt 0
else
true
fi
if [ "$?" = "0" ]; then
if [ ! ${FOUND} = "0" ]; then
echo "$A (${FOUND}/${TOTAL})"
fi
fi
fi
done