[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: What to do after "rm -r /usr"?



news.spiegl@kascada.com (Andy Spiegl) writes:

> Oh, boy!  A friend just called me and said he did a
> "rm -r /usr" by mistake.  He did stop it after a while,
> though, so that he can at least still do a little bit
> on his system.
> 
> Now, he asked me, what he should do in order to get back
> to a stable system again.  I suggested letting dselect
> install all packages again.  But how can he make dselect
> think that the packages aren't installed yet??
> 
> Or is there a better method?  Please help me helping him.
> BTW, he has "bo" installed.

To tell dpkg that nothing is installed, your friend can do the
following:  (sed is in /bin, so should still be around)

cd /var/lib/spkg
cp status status-old
sed -e '\f^Status: fs/ installed$/ not-installed/' < status-old > status

However, before he then turns dpkg loose on his system, I suggest that
he get a copy of the file base1_3.tgz on put it into /tmp (on my 1.3.1
cd, this file is in bo/disks-i386/current/; it's also the file that
goes into the base disk images - if all your friend has is these base
disks, there is a way to reconstruct this file - let me know) and do:

cd /
tar -xvkzf /tmp/base1_3.tgz usr
tar -xzOf /tmp/base1_3.tgz var/lib/dpkg/status > /tmp/base-status
# That's a capital "o", not the digit zero in the previous line

Then, so that dpkg can know about the packages installed by the base
install, he needs to run the following perl script (since perl was
restored by the preceding tar statement):

#!/usr/bin/perl
# This script takes the file /var/lib/dpkg/status and the file
# /tmp/base-status and creates a new status file (called
# /var/lib/dpkg/status-new) which looks just like /var/lib/dpkg/status
# except that it has the installed/not-installed status taken from
# /tmp/base-status

$/ = "\n\n";
open(BASESTATUS, "</tmp/base-status");
while(<BASESTATUS>) {
  ($package) = m/^Package: (.*)$/m;
  ($stat1, $stat2, $stat3) = m/^Status: ([^ ]*) ([^ ]*) ([^ ]*)$/m;
  $packhash{$package} = $stat3;
}

open(CURSTATUS, "</var/lib/dpkg/status");
open(NEWSTATUS, ">/var/lib/dpkg/status-new");

while(<CURSTATUS>) {
  ($package) = m/^Package: (.*)$/m;
  if (defined($packhash{$package})) {
    s/^Status: ([^ ]*) ([^ ]*) ([^ ]*)$/Status: \1 \2 $packhash{$package}/m;
  }
  print NEWSTATUS $_;
}

# end script

Then do a
  cd /var/lib/dpkg
  diff status status-new | more

Just to make certain that the above script didn't mess things up, then 
do a 
  mv status-new status
And dpkg's status file should now list everything installed that comes
installed on the base distribution, and everything else as
not-installed.  Hopefully, dselect can then be safely used to install
everything again.


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org .
Trouble?  e-mail to templin@bucknell.edu .


Reply to: