LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Looking for scripts to help fix my mistake (https://www.linuxquestions.org/questions/slackware-14/looking-for-scripts-to-help-fix-my-mistake-377980/)

shilo 10-29-2005 03:46 AM

Looking for scripts to help fix my mistake
 
I messed up BIG today.

What I wanted to type was:

Code:

rm -r usr
But what I typed instead was:

Code:

rm -r /usr
Luckily, I "ctrl-c"d it after ~2 min.

Through some (what I thought was) clever thinking on my part, I managed to get my system back up and running.

Now, I want to verify that everything is really fixed. I am looking for two scripts (which are, in essence, corrollaries of each other.

Script 1:

I am looking for a script that will parse /var/log/packages for installed files and tell me if a file that should be installed is missing.

Script 2:

I am looking for a script that will parse /var/log/packages and tell me which files are orphans (i.e. they don't belong to any package). This script could/should probably ignore /home, /root, and /tmp. It should also probably avoid some other things (/var?).

For my purposes, such a script would only need to deal with /usr :). But I was thinking that two scripts like these would probably be pretty handy for a SLackware admin in general. I'm hoping that aomething like these already exists. If not, this might be a good place to flesh something like that out.

I think these scripts (if they don't already exist) would make good additions to the Slackware package management tools. They could help out when doing major system upgrades.

A bit OT (in my own post, no less), here is some info on what I have done so far to remedy my huge mistake.

Some info:

My system:

Fresh Slackware 10.2: Full Install

Upgraded to -current via SWareT (not a huge issue at this point, since there have been very few changes to -current since the SLackware 10.2 release)

Dropline 2.12.1 (always kept current via the dropline-installer): Full install

Several self compiled packages (all made with SlackBuild scripts)

Only one third-party package (SWareT)

LOTS of separate partitions. Fortunately, I had set aside one 10G partition

How I "fixed" my system so far:

First up, I installed a fresh Slackware 10.2 on my spare partition

Next, I copied all of the new /usr to the old /usr. I used "cp" with the Recursive option and the Interactive option. The Recursive option made sure I got everything. The Interactive option made sure I didn't overwrite anything. For those unfamiliar with the Interactive option (-i), it asks before overwriting a pre-existing file. I figured out that just pressing enter was the same as "n", at which point I wedged something in my keyboard and made a snack. My thinking here was that I wanted to copy over files that I was missing. If the files hadn't been deleted, no need to mess with them.

I later thought that I probably should have specified teh -a option (to retain permissions). But I then thought that it really didn't matter, since Slackware tends to create anything under /usr as root.root.

That should have solved my issues with having Slackware 10.2 installed.

Next, I wanted to make sure I was A-OK wit hmy updates to -current. I issued the following commands:

Code:

cd /var/swaret
upgradepkg --reinstall *.tgz

That should have taken care of my Slackware -current installation.

Next up was Dropline. First, I used "upgradepkg --reinstall" for the dropline-installer. Then I realized tha tthe dropline installer would think everything was already peachy-keen. So I did the following:

Code:

cd /var/log/packages
rm *dl

Then I ran the dropline-installer. Things were not all smooth. The X11 font packages would not install (they would crash the dropline-installer. I realized tha tthis was due to differences in Dropline's X11 packages. Knowing that, I copied all the X11 files from the new /usr to the old /usr. I then used pkgtool to remove all of them (knowing that all files which were also contained in a Dropline X11 package would be left alone). This worked beautifully, and I was able to complete my Dropline install afterwards with no issues.

At this point, I used "upgradepkg --reinstall" to re-install SWareT. THis was mainly so I could check out things with the following commands:

Code:

updatedb
swaret --dep

This let me know tha I wasn't missing any dependencies for my installed programs.

Next, I rebuilt all of /usr/src with my custom kernels. Luckily, I save my configs on a separate partition.

The final step was to re-install my custom packages (just to be sure everything is working). I am still on that step, but I don't forsee any problems .

So wha tis left that may be an issue? The only thing I can think of right now is the packages thatDropline removes from a stock 10.2 install. That shouldn't be too much trouble. Other than that, I am hoping that the scripts that I described earlier already exist. THis would confirm that EVERYTHING is back to normal.

Tinkster 10-29-2005 04:48 AM

Re: Looking for scripts to help fix my mistake
 
Quote:

Originally posted by shilo
Script 1:

I am looking for a script that will parse /var/log/packages for installed files and tell me if a file that should be installed is missing.
Code:

#!/bin/bash
# package-health-check ... whipped up for shilo :)
cd /var/log/packages
for i in `ls -1`
do
  for j in `awk '!/install\// &&  !/^\./ && !/:/ && /\// {print "/"$0}' $i`
  do
    if [ ! -e $j ]; then
      echo $j "missing"
    fi
  done
done

Should do the trick


Quote:

Originally posted by shilo
Script 2:

I am looking for a script that will parse /var/log/packages and tell me which files are orphans (i.e. they don't belong to any package). This script could/should probably ignore /home, /root, and /tmp. It should also probably avoid some other things (/var?).

For my purposes, such a script would only need to deal with /usr :). But I was thinking that two scripts like these would probably be pretty handy for a SLackware admin in general. I'm hoping that aomething like these already exists. If not, this might be a good place to flesh something like that out.
Code:

#!/bin/bash
# orphan-check ... whipped up for shilo :)
#for i in `locate .|sed 's@^/@@'|egrep -v "(/root|/home|/tmp)"`
for i in `locate . |sed 's@^/@@'|egrep -v "(/root|/home|/tmp)"`
do
  if grep "$i" /var/log/packages/*  2>&1 >/dev/null
      then echo "potential orphan: "$i
  fi
done

Number two should work to, I didn't bother with proper quoting, though.


Cheers,
Tink

shilo 10-29-2005 10:02 AM

WHOO-WHOO!

THANK YOU, TINKSTER!!!

Tinkster 10-29-2005 02:49 PM

Quote:

Originally posted by shilo
WHOO-WHOO!

THANK YOU, TINKSTER!!!

You're welcome ;}


Cheers,
Tink

PDock 10-30-2005 05:20 AM

WHOO-WHOO!

THANK YOU, TINKSTER!!!

a cheap addition/change
Code:

#!/bin/bash
# package-health-check ... whipped up for shilo :)
cd /var/log/packages
for i in `ls -1`
do
  for j in `awk '!/install\// &&  !/^\./ && !/:/ && /\// {print "/"$0}' $i`
  do
    if [ ! -e $j ]; then
      echo $j "missing from: "$i
    fi
  done
done

ppd


All times are GMT -5. The time now is 02:24 AM.