Help - Search - Members - Calendar
Full Version: Script to Repair Installation
MandrivaUsers.org > General Help > Tips and Tricks
Steve Scrimpshire
This is a script I wrote, part of which was taken from aru. This script assumes you have your urpmi sources correctly configured and it contains no local sources. You can do that here:
http://urpmi.org/easyurpmi/index.php
I'm trying to figure out how to do this with local sources taken into consideration, too:
CODE
#!/bin/bash

# rpmfix - searches your system for missing files and reinstalls rpms they belong to
# Copyright (C) 2003  Steve Scrimpshire
# email: omarserenity@gmail.com

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# http://www.gnu.org/copyleft/gpl.html#SEC1

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


rm -f notonmirrors
rm -f missing_files.list

rpm -Va --nodeps --nomd5 --noscripts | grep missing | grep -v "/dev/" | tee missing_files.list
TEST=$(rpm -qf $(awk '{print $NF}' missing_files.list) | uniq)

urpmi.update -a

for name in $TEST
  do
      echo $name
     GET=$(urpmq --sources $name 2>/dev/null)
      if [ $GET ]
         then
         if [[ $name != XFree* ]]
            then
               wget $GET
            else
               echo "I won't fix $name because I always have problems doing that!"
         fi
         else
            echo "$name does not exist on the mirrors!"
            echo "$name" >> notonmirrors
      fi
  done

DIR=$(ls)

for file in $DIR
   do
      if [[ $file == *.rpm ]]
         then
            rpm -ivh --replacefiles --replacepkgs $file
            rm -f $file
      fi
   done

exit 0


I created a special directory to put this script in and after it runs, you may or may not see a new file in that directory called notonmirrors, which will contain the names of pkgs that have missing files, but urpmq could not find them on the mirrors, so you will have to fix them manually. I have it ignore XFree pkgs, because there is always some files for fonts that are missing and no matter how many times you reinstall it, they are still missing.
Steve Scrimpshire
Has anyone found this useful at all?
kmack
It looks really good, but have not had a chance to try it. In middle of moving across the pacific and my desktop will be in a container for a month or so! :-) THanks for sharing it and did you ever get the local sources added to it? I like to download to a directory and install from local source and then keep cd's of the patches, etc so I can reinstall if I need to do so w/o re-downloading.
neutro
Well I'm currently running the line to see if I am actually missing files wink.gif
This script would have been useful last time my system borked and mistakingly pressed "Y" when fsck asked me to check filesystem integrity (thus bypassing ext3 journal recovery). I lost lots of files and replaced by hand quite a few rpms. Once in a while I still find that some program that I haven't used since is broken, and I have to reinstall it.

Are you aware of any risk in using your script? (e.g. overwriting config files or nasty side-effects such as this?)
Steve Scrimpshire
I have not experienced it overwriting config files, but that is not to say that it couldn't happen.
neutro
Well thanks, it worked well with no side effects so far.
Geez, I wass missing /usr/bin/passwd ohmy.gif
Apoc
Looks good will try this out tonight.. anything to make my life easier is good
biggrin.gif
aroy_802701
QUOTE (Steve Scrimpshire @ Feb 15 2004, 05:54 AM)
Has anyone found this useful at all?
*

Yeah, thanks. Repaired broken deps for documentation, mainly. Couldn't find glibc-devel in any of the urpmi mirrors (because newer version existed in them) and had to do urpmi manually for that. But basically works really well.
frosterrj
QUOTE (Steve Scrimpshire @ Feb 15 2004, 05:54 AM)
Has anyone found this useful at all?
*

Well, its kind of interesting to see what came out of the Missing Files and Not on Mirror lists, just not sure how to interpret the results!

For Examlple:
Not On Mirror says:
glibc-devel-2.3.3-20mdk
jre-1.5.0-fcs
j2re-1.4.2_05-fcs
xorg-x11-6.7.0-2mdk
xorg-x11-75dpi-fonts-6.7.0-2mdk

Missing Files Says:
missing /boot/kernel.h-2.6.8
missing /usr/java/jre1.5.0/lib/charsets.pack
missing /usr/java/jre1.5.0/lib/deploy.pack
missing /usr/java/jre1.5.0/lib/ext/localedata.pack
missing /usr/java/jre1.5.0/lib/javaws.pack
missing /usr/java/jre1.5.0/lib/jsse.pack
missing /usr/java/jre1.5.0/lib/plugin.pack
missing /usr/java/jre1.5.0/lib/rt.pack
missing /usr/java/j2re1.4.2_05/javaws/javaws.pack
missing /usr/java/j2re1.4.2_05/lib/charsets.pack
missing /usr/java/j2re1.4.2_05/lib/ext/localedata.pack
missing /usr/java/j2re1.4.2_05/lib/jsse.pack
missing /usr/java/j2re1.4.2_05/lib/plugin.pack
missing /usr/java/j2re1.4.2_05/lib/rt.pack
missing /usr/java/j2re1.4.2_05/lib/unpack
missing /usr/X11R6/lib/X11/fonts/Speedo/encodings.dir
missing /usr/X11R6/lib/X11/fonts/TTF/encodings.dir
missing /usr/X11R6/lib/X11/fonts/Type1/encodings.dir
missing /usr/X11R6/lib/X11/fonts/75dpi/encodings.dir

Since I am running Xorg from the 10.1CE, is it just a version issue since I have a cooker repository in my sources list? I am pretty sure I have kernel source installed too, so why the missing kernel.h? I am running 2.6.8.1-10mdk.

Robert
Gowator
made sticky since its such an outstandingly useful tip!
Steve Scrimpshire
Thanks, Gowator! blush.gif

There are some packages that are going to always claim to be missing files...that has something to do with the packaging and nothing I can do except put an ignore line in the script.

As for the 'not on mirrors', sometimes they change naming conventions and that might cause that or the particular mirror you are using might not be updated properly.
jeanackle
QUOTE (Steve Scrimpshire @ Feb 15 2004, 05:54 AM)
Has anyone found this useful at all?
*

Do birds fly? tongue.gif

QUOTE (neutro @ Feb 15 2004, 07:12 PM)
Are you aware of any risk in using your script? (e.g. overwriting config files or nasty side-effects such as this?)
*

I'm not completely sure, but I think that "rpm --replace-files" saves a copy of the old config files as "configfile".rpmsave.
Or am I mistaking its behaviour with the one of urpmi? unsure.gif
Steve Scrimpshire
Ok, let's make it safer:
CODE
#!/bin/bash

# rpmfix - searches your system for missing files and reinstalls rpms they belong to
# Copyright (C) 2003  Steve Scrimpshire
# email: omarserenity@gmail.com
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# http://www.gnu.org/copyleft/gpl.html#SEC1

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


rm -f notonmirrors
rm -f missing_files.list

rpm -Va --nodeps --nomd5 --noscripts | grep missing | grep -v "/dev/" | tee missing_files.list
TEST=$(rpm -qf $(awk '{print $NF}' missing_files.list) | uniq)

urpmi.update -a

for name in $TEST
do
     echo $name
    GET=$(urpmq --sources $name 2>/dev/null)
     if [ $GET ]
        then
        if [[ $name != XFree* ]]
           then
              wget $GET
           else
              echo "I won't fix $name because I always have problems doing that!"
        fi
        else
           echo "$name does not exist on the mirrors!"
           echo "$name" >> notonmirrors
     fi
done

DIR=$(ls)

for file in $DIR
  do
     if [[ $file == *.rpm ]]
        then
           rpm -ivh --replacepkgs $file
           rm -f $file
     fi
  done

exit 0


That way, it won't replace existing files. Thanks for pointing that out.
LatterDaySaint
G'Day Steve, I have tried the 2 scripts at the beginning of your thread but I get an empty page on the first webpage and a error on the second ,I'm wondering if their still valid or not as they seem to point to nowhere.. is there another thread somewhere that may have similar teachings on finding missing files ect? Thanks Jason
Steve Scrimpshire
What do you mean an empty page? What errors do you get?
The second version of the script should be the one to use.
LatterDaySaint
I tried 3 or 4 times and got error saying something like "not found the requested url /easyurpmi/index.php was not found on this server.
Steve Scrimpshire
Try setting up your urpmi sources with the EasyUrpmi link at the top right-hand side of this page. It actually is more reliable.
LatterDaySaint
Steve,I already got my urpmi sources, but found when I tried your script Example "! /bin/bash" & rpmfix to start things off that I got no response ,so I thought one of these 2 posts might of led to more examples , Im still a linux novice trying to learn but have a little trouble understanding scripting but want to give it a go, I have come accross some tutorials in somePC mags I have and will see if they can get me going as well? I havnt read your tutorial right through yet so maybe I have done something wrong , Should typing ! /bin/bash or rpmfind give me some results or do I have something missing? Thanks
Steve Scrimpshire
Ahhh...I see the problem. What i posted is a script not commands you run from a terminal. Copy and paste the entire code sample into a file and save it, making sure that #!/bin/bash is on the very top line. You can name it whatever yo want, like repairinstall. Then type this command:
chmod +x repairinstall
then as root:
./repairinstall

If you are already running this as a script, make sure all the lines that have # in the beginning, keep them.
jeanackle
Hi Steve,

What you said earlier about XFree packages (they seem to need being reinstalled everytime) is valid for my glibc-devel and kernel-source packages as well. So, I changed a line in your script:
CODE
if [[ $name != XFree* ]]

Is now:
CODE
if [[ $name != XFree* && $name != glibc-devel* && $name != kernel-source* ]]

Now they don't bother me anymore... afro.gif

Just thought I'd let you know about it.

Cheers
christophe_ca
Hi! When I'm trying to run this script, I get a Permission denied message. I'm a total newbie with scripts. What do I do?

Thank you
devries
Have you made it executable? (if you use kde, rightclick the file, properties, tab accesrights, check executable)
jeanackle
In Nautilus (GNOME), it would be:
Right-click the file -> Properties -> Permissions -> Check "Executable" checkboxes

Or, in a terminal, type in:
CODE
chmod a+x rpmfix

Assuming you named the script "rpmfix". Otherwise, just replace that with whatever you named it.

Cheers,
christophe_ca
Hi! I did chmod a+x and it worked. I had a message saying: "rpmq: no argument to your request" (translation from French). The reason I'm running this script is to be able to run menudrake. When I try to, I get a segmentation fault.

thanks.gif
Steve Scrimpshire
Hmmm... no argument to your request sounds like you aren't missing any files.
Can you attach your missing_files.list to a post here? You'll have to rename it to missing_files.txt to get it to attach. It'll be in the same directory you run the script from.
christophe_ca
Here's the file:
Steve Scrimpshire
I meant the file called missing_files.list that the script creates in the directory you run the script from. If the file does not exist, it means either:
(a) You do not have write permissions in the directory you run the script from
(b) None of your rpms are missing any files, which is highly doubtful
christophe_ca
I found the file you were talking about but it's empty
christophe_ca
I can't attach a file anymore? Why!?
christophe_ca
The file missing_files.list is 0k
Steve Scrimpshire
What is the output of this command, run as root?

rpm -Va --nodeps --nomd5 --noscripts | grep missing | grep -v "/dev/"
christophe_ca
Nothing appears!
Steve Scrimpshire
Then none of your pkgs are missing any files. Amazing.
christophe_ca
None of my packages are missing and I still get a segmentation fault when I try to run menudrake! What do I do?
Steve Scrimpshire
I dunno. Maybe post a question in the appropriate forum? biggrin.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.