include("site.inc"); $template = new Page; $template->initCommon(); $template->displayHeader(); ?>
Popt provides a powerful library and RPM subsystem for handling the very complex RPM command-line options. You can customize your RPM usage by defining popt aliases for complex command-line arguments to the rpm or rpmbuild commands. A popt alias is a command-line option that expands to other command-line options.
This technique is used internally to define quite a few command-line options to the rpm and rpmbuild commands in terms of other, more complex options. Many of these aliases define simple command-line options in place of more complex query format options.
Cross Reference
Chapter 5 covers the query format.
For example, the following entry defines the --requires and –R command-line options to the rpm command:
rpm alias --requires --qf \
"[%{REQUIRENAME} %{REQUIREFLAGS:depflags} %{REQUIREVERSION}\n]" \
--POPTdesc=$"list capabilities required by package(s)"
rpm alias -R --requires
These options are set in the file /usr/lib/rpm/rpmpopt-4.1.
Note
This is specific to RPM 4.1. Other releases of RPM use the same naming format but with the current RPM version number, such as 4.2 and so on.
Defining aliases is pretty easy. The basic syntax is:
command_name alias option expansion
To create an alias for the rpm command, you use rpm for the command_name.
Note
The command_name must be the name passed to the C poptGetContext function, covered in Chapter 16.
Follow this with alias and then the option. You will need separate aliases for the long and short options. The expansion defines the alias in terms of other already-defined command-line parameters.
You can define some complex aliases, such as the following one to display information about a package:
rpm alias --info --qf 'Name : %-27{NAME} Relocations: %|PREFIXES?{[%{PREFIXES} ]}:{(not relocateable)}|\n\
Version : %-27{VERSION} Vendor: %{VENDOR}\n\
Release : %-27{RELEASE} Build Date: %{BUILDTIME:date}\n\
Install date: %|INSTALLTIME?{%-27{INSTALLTIME:date}}:{(not installed) }| Build Host: %{BUILDHOST}\n\
Group : %-27{GROUP} Source RPM: %{SOURCERPM}\n\
Size : %-27{SIZE}%|LICENSE?{ License: %{LICENSE}}|\n\
Signature : %|DSAHEADER?{%{DSAHEADER:pgpsig}}:{%|RSAHEADER?{%{RSAHEADER:pgpsig}}:{%|SIGGPG?{%{SIGGPG:pgpsig}}:{%|SIGPGP?{%{SIGPGP:pgpsig}}:{(none)}|}|}|}|\n\
%|PACKAGER?{Packager : %{PACKAGER}\n}|\
%|URL?{URL : %{URL}\n}|\
Summary : %{SUMMARY}\n\
Description :\n%{DESCRIPTION}\n' \
--POPTdesc=$"list descriptive information from package(s)"
Popt aliases get evaluated into Linux commands, so you can use pipes and other aspects of Linux shells in your aliases.
Cross Reference
Look closely at the examples in the /usr/lib/rpm/rpmpopt-4.1 file. This is the most complete set of popt alias examples for RPM commands.
You can also define aliases that can set RPM macros, such as the following alias for setting the path to the RPM database:
rpm alias --dbpath --define '_dbpath !#:+'
In this example, !#:+ was defined to behave like a shell history-editing command. With popt, this means to grab the next command-line parameter and place it into the command defined for the alias.
To support the --help and --usage options, you can define the --POPTdesc and --POPTargs options to the alias as shown in the previous examples. These options also support internationalization.
All together, the popt alias setting is very close to the popt option table entries used with the C programming API.
Cross Reference
Chapter 16 shows how to program with the popt library.
Like RPM macros and settings, popt aliases are defined in a cascading set of files. The official RPM aliases are defined in /usr/lib/rpm/rpmpopt-4.1 for rpm 4.1.
Note
Do not modify this file! The RPM system depends on this file for proper functioning. Incorrect changes might disable many options to the rpm command.
Store per-system popt aliases in /etc/popt. Store per-user aliases in $HOME/.popt (with a leading period).
Note
These files are shared by all applications that use popt.
For example, you can define an alias for rpm -qa that executes faster than the normal query all packages command, by turning off the tests for digest signature verification. To do so, add the following line to a file named .popt in your home directory:
rpm alias --qall -qa --nodigest --nosignature
Once you set up this alias, you can run the following command in place of rpm -qa:
$ rpm --qall
This should execute about one-third to one-half faster than the normal rpm -qa command.
Warning
Turning off the signature and digest tests means you are ignoring important information that pertains to the integrity of your system. That is why the alias shown here does not override the normal -qa option, and instead defines a new --qall option