initCommon(); $template->displayHeader(); ?>

14.6. Querying the RPM Database

In addition to querying RPM files, you can script the commands you use to query the RPM database. This is most useful for the long commands with query formats, especially if you have a hard time remembering all the formats.

14.6.1. Querying for all packages installed at the same time

If you want to list all the packages that were installed with the same transaction ID as a particular package, for example, you can use a script like rpmtran, in Listing 15-4.

Listing 15-4: rpmtran

#!/bin/sh

tid=`rpm -q --qf "%{INSTALLTID}\n" $*`

rpm -q --tid $tid

This script uses the query format to get the transaction ID, or tid, for a particular package. It then passes this transaction ID to the rpm command to query for all packages installed with the same transaction ID.

For example:

$ ./rpmtran tcl

itcl-3.2-74

tclx-8.3-74

tcl-8.3.3-74

tix-8.2.0b1-74

tkinter-2.2.1-17

14.6.2. Reading HTML documentation for a package

You can combine the rpm command with other commands as well. For example, the rpm –qd command lists the documentation files with a package. If this documentation is in HTML format, you can display this documentation in a Web browser such as Mozilla. Furthermore, by convention, the starting page for HTML documentation should be a file named index.php. Listing 15-5 combines all these factors:

Listing 15-5: rpmmoz

#!/bin/sh

html_file=`rpm -qd $* | grep index.php | head -n 1 `

echo "Launching Web browser with $html_file"

htmlview $html_file &

This script searches for the documentation for a given package name, finds the first file named index.php, and launches the Web browser in the background to display this file, using the htmlview command which will likely run mozilla or your configured Web browser. When you run this command, you should see output like the following; then the Web browser should appear:

$ ./rpmmoz rpm-devel

Launching Web browser with /usr/share/doc/rpm-devel-4.1/apidocs/html/index.php

Note

This script does not check for errors. If there are no files named index.php, the script launches the Web browser anyway. You could fix this by changing the script to validate the html_file variable prior to launching the Web browser.

displayFooter('$Date: 2005/11/02 19:30:06 $'); ?>