Red Hat Support Training - Tutorial Session Date: Presenter: Subject: RPM tricks and tips Description: How to scare customers with rpm trickery ______________________________________________________________________________ RPMS: (please note if shipped with Red Hat Linux) rpm popt ... Configuration files: /usr/lib/rpm/rpmrc /usr/lib/rpm/rpmpopt /usr/lib/rpm/macros Binary programs: /usr/bin/rpm Other software: cmprpm How to make work: Basic useage: Installing a package: rpm -ivh packagename.arch.rpm removing a package: rpm -e packagename upgrading a package: rpm -Uvh packagename.arch.rpm listing the files in a package: rpm -ql packagename viewing the info for a file: rpm -qi packagename Tips, tricks, gotchas: There are lots of wacky tricks you can do with rpm. Here is a few of them. * Finding what package owns a file: rpm -qf /path/to/filename * Finding out which arch of a package is installed (ie, i386, i686, etc) rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE}-%{ARCH}\n" packagename or just: rpm -q --queryformat "%{ARCH}\n" packagename * Finding info about a uninstalled rpm file: add the -p flag, ie: rpm -qpl packagename-1.0-5.i386.rpm (to show info about the file packagename-1.0-5.i386.rpm) * Viewing changes in a rpm: rpm --changelog packagename * Finding out what package provides some dep rpm -q --whatprovides /bin/sh Starting in 6.2, you can also query against an external rpm database, and we ship a db that is equivalent to all the packages installed. So you can do: rpm -q --redhatprovides /etc/exports For example, and it will tell you which rpm includes that package, even if it is not installed. Same goes for finding out what a package requires rpm -q --whatrequires bash rpm -q --redhatrequires bash There is also a --requires which will show you just the req's, and not the packages itself. This can be useful if something is complaining about missing deps, and you want to see what it needs to see if its satisfied by a non-rpm package. rpm -qp --requires bash-1.14.7-22.i386.rpm * To validate a package against the info stored in a database: rpm -V packagename Sometimes, say in a suspected compromise where you think the rpm database is compromised (or more likely, removed...) you can verify against the db in the rpmdb-redhat-6.2 package: rpm -V --dbpath /usr/lib/rpmdb/i386-redhat-linux/redhat/ bash * Seeing when a package was installed rpm -q --last packagename * Seeing the order packages were installed in rpm -qa --last * Replacing a newer package with an older one rpm -Uvh --oldpackge packagename * Removing a package from the rpm database, but keeping the files installed: rpm --justdb -e packagename * Getting a list of rpms sorted by size rpm -qa --queryformat "%{SIZE} %{NAME}\n" | sort -n * Getting a list of packages sorted by the date they were created: rpm -qa --queryformat "%{BUILDTIME}:%{NAME} %{BUILDTIME:date}\n" | sort -n | cut -f2 -d':' * Show all the packages that have BSD style licenses rpm -qa --qf "%{LICENSE}: %{NAME}\n" | grep ^BSD * Show all the packages with URL associated with them and the URLS rpm -qa --qf "%{NAME}: %{URL}\n" * To few a list of all rpms as html in lynx: rpm -qa --qf "%|URL?{%{NAME}}|
\n" | lynx -force_html /dev/stdin * Seeing all the files on the system that are not from an rpm: #!/bin/sh cd $1 for i in `find $1 -type f -name "*" ` do rpm -qf $i > /dev/null if [ ! $? ] ; then echo $i fi done Use like `find_non_rpms.sh /bin` * Extract one file from a rpm rpm2cpio foo-0.1-1.i386.rpm | cpio iuvm POPT Magic Now, the interesting thing about several of those commandline flags is that they aren't actually part of the rpm binary. Instead, the "popt" library, which is used to parse commandline arguments, parses them. The interesting thing about the popt library is that you can create commandline "aliases". Take a look at /usr/lib/rpm/rpmpopt for examples. A large portion of rpm commandline flags are actually implemented as popt arguments. So for example, the rather long commandline to get the arch info for a installed package is an ideal candidate for a popt aliases. popt aliases can be setup in /etc/popt or ~/.popt. For example, add the line: rpm alias --arch -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE}-%{ARCH}\n" to ~/.popt And then run: rpm --arch kernel cool eh? another twisted example, the html example rpm alias --html -qa --qf "%|URL?{%{NAME}}|
\n" --pipe "lynx -force_html /dev/stdin" put that in ~/.popt and run: rpm --html