I had accidentally deleted /var/lib/dpkg/info/ from one of my Debian GNU/Linux systems, with the consequence that APT misses relevant metadata. I vaguely remember having done this before and I might do it stupidly again. Therefore I wrote a script which seems to fix this.
#!/bin/sh
# Repare dpkg database in /var/lib/dpkg/info/ from /var/lib/dpkg/status.
#
STATUS=/var/lib/dpkg/status
INFO=dpkg-info
BASEDIR=`pwd`
echo File ${STATUS} will be used to read which packages you have
installed.
echo New info/* files will be moved into ${INFO}/.
mkdir ${INFO}
for PACKAGE in `grep ^Package ${STATUS} | awk '{print $2}'`; do
echo Processing ${PACKAGE}...
aptitude download ${PACKAGE} || continue
dpkg-deb -e `ls ${PACKAGE}*.deb` || continue
cd ${BASEDIR}/DEBIAN/
for CTRLFILE in *; do mv ${CTRLFILE}
../${INFO}/${PACKAGE}.${CTRLFILE}; done
cd ${BASEDIR}/
rm ${PACKAGE}*.deb
done
This can be ran as a normal user. If you then move all files from dpkg-info/ to /var/lib/dpkg/info/ APT should work well again. You should change the script if you already have a large amount of deb files in /var/cache/apt/archives/.
Do whatever you want with the script. The script is as-is, without any waranties.
Update: This method does not restore the *.list files, thus leaving me without all necessary dpkg metadata.
