recovery from "rm -rf /var/lib/dpkg/info" ?

Kees Cook kees at ubuntu.com
Thu Aug 23 19:52:08 BST 2007


Hi Kristian,

On Wed, Aug 22, 2007 at 02:17:06PM -0400, Kristian Erik Hermansen wrote:
> On 8/22/07, Ben Collins <ben.collins at ubuntu.com> wrote:
> > sudo apt-get --reinstall install `dpkg --get-selections | grep '[[:space:]]install' | cut -f1`
> >
> > This _might_ work. There is no silver bullet to fix your problem other
> > than file backups.
> 
> I like your kung-fu, but how is this any different than...
> 
> $ sudo aptitude reinstall ~i

Perhaps extracting the needed files directly from the .deb archives will
do the trick?  Try this insanity, with sudo.  I have no idea if it will
work, YMMV, etc etc, but I think this is generally what's needed to get
all your dpkg info files back in place....

#!/bin/bash
set -e

# Clean out /var/cache/apt/archives
apt-get clean
# Fill it with all the .debs we need
apt-get --reinstall -dy install $(dpkg --get-selections | grep '[[:space:]]install' | cut -f1)

DIR=$(mktemp -d -t info-XXXXXX)
for deb in /var/cache/apt/archives/*.deb
do
	# Move to working directory
	cd "$DIR"
	# Create DEBIAN directory
	mkdir -p DEBIAN
	# Extract control files
	dpkg-deb -e "$deb"
	# Extract file list, fixing up the leading ./ and turning / into /.
	dpkg-deb -c "$deb" | awk '{print $NF}' | cut -c2- | sed -e 's/^\/$/\/./' > DEBIAN/list
	# Figure out binary package name
	DEB=$(basename "$deb" | cut -d_ -f1)
	# Copy each control file into place
	cd DEBIAN
	for file in *
	do
		cp -a "$file" /var/lib/dpkg/info/"$DEB"."$file"
	done
	# Clean up
	cd ..
	rm -rf DEBIAN
done
rmdir "$DIR"

-- 
Kees Cook
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : https://lists.ubuntu.com/archives/ubuntu-us-ma/attachments/20070823/ae629ff8/attachment.pgp 


More information about the Ubuntu-us-ma mailing list