PDA

View Full Version : Trivial yum search script


jackal
2004-05-05, 05:58 PM CDT
After finding that the -C flag to yum was not working as expected, which should make it use the cache and not download all the headers from the repos, I made this little bash script. This will search the cache of headers that you currently have downloaded on your machine, with almost no latency.

It is very trivial, but since I'm sure some users don't know how to write bash scripts at all, I thought I would post it here:

To use the script, create a plain text file with you favorite text editor (vim, emacs, gedit, etc) with the following code and save it as /usr/bin/yum-search. Then, as root, make it executable with "chmod 755 /usr/bin/yum-search" (without the double quotes).


#!/bin/bash

if [ $# -gt 0 ]; then

find /var/cache/yum/ | grep -v packages | sed "s|^/var/cache/yum/||g" | grep -i $1

else

echo -e "Useage: yum-search <pkgname>\n"

fi



The output looks as follows:


[john@diablo john]$ yum-search
Useage: yum-search <pkgname>

[john@diablo john]$ yum-search mplayer
livna-stable/headers/mplayer-mencoder-0-0.92-0.lvn.1.1.91.i386.hdr
livna-stable/headers/mplayer-gui-0-0.92-0.lvn.1.1.91.i386.hdr
livna-stable/headers/mplayer-skins-0-1.2-0.lvn.1.1.90.noarch.hdr
livna-stable/headers/mplayerplug-in-0-2.11-0.lvn.2.1.90.i386.hdr
freshrpms/headers/mplayer-skins-0-1.3-3.fr.noarch.hdr
freshrpms/headers/mplayer-0-1.0-0.9.20040415.1.fc1.fr.i386.hdr
freshrpms/headers/mplayer-fonts-0-1.1-2.fr.noarch.hdr
[john@diablo john]$



EDIT - edited to get rid of the redundant "packages" display

martinjh99
2004-05-09, 12:58 AM CDT
Nice! Thanks for that!

jackal
2004-05-09, 09:39 AM CDT
I forgot to mention that the idea to just search /var/cache came from someone on #fedora, but I forget who it was. I just made it into a nice little bash script that got rid of some of the fluff.

micha
2004-05-09, 03:23 PM CDT
Works great !!!
Thanks a lot :)

theurge
2004-05-11, 02:36 AM CDT
Just a trivial cosmetic change to a trivial search script:


#!/bin/bash

if [ $# -gt 0 ]; then

find /var/cache/yum/ | grep -v packages | sed "s|^/var/cache/yum/||g" | grep -i $1 | sed 's/.hdr//g'

else

echo -e "Useage: yum-search <pkgname>\n"

fi


Sample output:


[cboyd@micron scripts]$ yum-search.sh gcc
base/headers/compat-gcc-java-0-7.3-2.96.118.i386
base/headers/compat-gcc-c++-0-7.3-2.96.118.i386
base/headers/compat-gcc-g77-0-7.3-2.96.118.i386
base/headers/gcc-g77-0-3.3.2-1.i386
base/headers/gcc-java-0-3.3.2-1.i386
base/headers/compat-gcc-0-7.3-2.96.118.i386
base/headers/gcc-gnat-0-3.3.2-1.i386
base/headers/compat-gcc-objc-0-7.3-2.96.118.i386
base/headers/gcc-objc-0-3.3.2-1.i386
base/headers/gcc32-0-3.2.3-6.i386
[cboyd@micron scripts]$