### Create and install a base image manifest Source: https://rpm.org/docs/6.1.x/man/rpm-manifest.5 This example shows how to create a manifest file of currently installed packages and then install it to an alternative system root. ```bash rpm -qa --qf '/mnt/Packages/%{nevra}.rpm\n' > mymanifest.mft rpm -Uv --root /srv/test mymanifest.mft ``` -------------------------------- ### Manage Alternatives in a Subpackage Source: https://rpm.org/docs/6.1.x/man/rpm-scriptlets.7 This example demonstrates managing alternatives for a subpackage. It installs an alternative on package installation and removes it on package removal. ```bash %post myimpl update-alternatives --install /usr/bin/frobber \ frobber /usr/bin/frobber.myimpl 10 %preun myimpl if [ $1 -eq 0]; then # Package removal, not upgrade update-alternatives --remove frobber /usr/bin/frobber.myimpl 10 fi ``` -------------------------------- ### Manage Alternatives in a Subpackage Source: https://rpm.org/docs/6.1.x/manual/file_triggers.html This example demonstrates how to manage alternatives for a command using update-alternatives within a subpackage. It installs an alternative on package installation (%post) and removes it on package removal (%preun). ```bash Name: frobber [...] %package myimpl [...] %post myimpl update-alternatives --install /usr/bin/frobber \ frobber /usr/bin/frobber.myimpl 10 %preun myimpl if [ $1 -eq 0]; then # Package removal, not upgrade update-alternatives --remove frobber /usr/bin/frobber.myimpl 10 fi ``` -------------------------------- ### %install with %make_install for Autotools Source: https://rpm.org/docs/6.1.x/manual/spec.html Demonstrates the standard way to install compiled autotools projects using %install and %make_install. ```spec %install %make_install ``` -------------------------------- ### Apply Patches with %autopatch (Range >= 100) Source: https://rpm.org/docs/latest/manual/autosetup.html This example shows how to apply patches starting from a specific number using the -m option with %autopatch. ```rpm %autopatch -m 100 ``` -------------------------------- ### Using %setup macro with options Source: https://rpm.org/docs/latest/manual/spec.html The %setup macro unpacks sources and can be configured with various options to control the process. ```spec %setup -q -n %{name}-%{version} ``` -------------------------------- ### %setup Macro Options Source: https://rpm.org/docs/6.1.x/manual/spec.html Explains the various options available for the %setup macro, used for unpacking sources and managing the build directory. ```spec %setup [options] ``` -------------------------------- ### Installation with %make_install Source: https://rpm.org/docs/latest/manual/spec.html Prepares the installation layout and copies built software into the build root. %make_install is common for autotools. ```spec %install %make_install ``` -------------------------------- ### Example: Get Magic Tokens for File Analysis Source: https://rpm.org/docs/6.1.x/man/rpm-dependency-generators.7 This command demonstrates how to use the 'file' utility with specific options to extract magic tokens from a file, which can be used to determine compatible magic regex for RPM dependency generators. ```bash file -z -e tokens /some/file ``` -------------------------------- ### Example RPM Version Breakdown Source: https://rpm.org/docs/6.1.x/manual/dependencies.html Shows the breakdown of the example dependency into epoch, version, and release components. ```text epoch=9 version=5.00502 release=3 ``` -------------------------------- ### Display Package Name and Installation Date Source: https://rpm.org/docs/6.1.x/man/rpm-queryformat.7 Prints the specified package name followed by its installation date. Useful for tracking when a particular package was installed. ```bash rpm -q --queryformat "%{NAME} %{INSTALLTIME:date}\n" fileutils ``` -------------------------------- ### Macro to Check for Install Prerequisite Source: https://rpm.org/docs/6.1.x/api/rpmds_8h.html Checks if a dependency is marked for installation. ```c #define isInstallPreReq | ( | | __x_| ) | ((_x) & _INSTALL_ONLY_MASK) ``` -------------------------------- ### Print Package Installation File List using Scriptlet Source: https://rpm.org/docs/6.1.x/man/rpm-queryformat.7 This scriptlet, executed after package installation, iterates through the list of installed filenames provided by the '%{instfilenames}' query format and prints each filename on a new line. Note the required trailing space within the square brackets for proper expansion. ```bash %post -q for f in [%%{instfilenames} ]; do echo $f done ``` -------------------------------- ### Mark Files as Documentation with %doc Source: https://rpm.org/docs/6.1.x/manual/spec.html Use %doc to install files as documentation. The special form installs files relative to the build directory. ```spec %doc /usr/share/doc/myprogram/README ``` ```spec %doc path/to/docfile ``` -------------------------------- ### Dependency Generator Output Example 2 Source: https://rpm.org/docs/6.1.x/manual/more_dependencies.html Example output from a dependency generator, listing package names with version information. ```spec Foo-0.9 perl(Widget)-0-1 ``` -------------------------------- ### Enable Systemd Preset on Upgrade with %triggerun Source: https://rpm.org/docs/6.1.x/manual/triggers.html Use %triggerun to enable a systemd preset for a service when upgrading a package from an older version. This example ensures the 'mydb-migrate' service is preset if the installed version is less than 3.0. ```bash Name: my Version: 3.0 [...] # On update from 2.x %triggerun -- my < 3.0-1 if [ -x /usr/bin/systemctl ]; then systemctl --no-reload preset mydb-migrate ||: fi ``` -------------------------------- ### Install Jekyll and Plugins Source: https://rpm.org/docs/6.1.x/manual/devel_documentation.html Install the Jekyll static site generator and necessary plugins for rendering the documentation locally. This can be done using distribution package managers or Ruby's gem command. ```bash gem install jekyll gem install jekyll-titles-from-headings jekyll-relative-links ``` -------------------------------- ### Example RPM Dependency Specification Source: https://rpm.org/docs/6.1.x/manual/dependencies.html An example of a Requires line specifying epoch, version, and release for a dependency. ```text Requires: perl >= 9:5.00502-3 ``` -------------------------------- ### Runtime Queryformat Expansion for Installed Filenames Source: https://rpm.org/docs/6.1.x/man/rpm-scriptlets.7 Iterate over installed filenames using runtime queryformat expansion in the %post scriptlet. This reflects file policies like --nodocs applied during installation. ```bash %post -q for f in [%%{instfilenames} ]; do echo $f done ``` -------------------------------- ### Mark Files as Documentation with %doc Source: https://rpm.org/docs/latest/manual/spec.html Use %doc to mark files as documentation. They can be installed normally or stripped down to the last path component if installed relative to the build directory. Documentation can also be filtered out during installations. ```spec %doc /usr/share/doc/myprogram/README ``` ```spec %doc path/to/manual.txt ``` -------------------------------- ### List All Installed Packages Source: https://rpm.org/docs/6.1.x/man/rpm.8 Lists all installed RPM packages on the system using the default formatting. This is a fundamental command for inventorying installed software. ```bash rpm -qa ``` -------------------------------- ### Install RPM Source Package Source: https://rpm.org/docs/6.1.x/api/rpmlib_8h.html Installs an RPM source package from a file descriptor. Outputs the spec file and cookie if successful. ```c rpmRC rpmInstallSourcePackage (rpmts ts, FD_t fd, char **specFilePtr, char **cookie); ``` -------------------------------- ### Shell Expansion Example Source: https://rpm.org/docs/6.1.x/man/rpm-macros.7 An example demonstrating shell expansion, using 'tr' to replace hyphens with periods in a string. ```shell %(echo aa-bb-cc | tr '-' '.') ``` -------------------------------- ### rpmspecQuery Function Example Source: https://rpm.org/docs/latest/api/rpmspec_8h.html Example of how to use the rpmspecQuery function to query RPM package information. ```c int rpmspecQuery (rpmts ts, QVA_t qva, const char *arg); ``` -------------------------------- ### Manage alternatives for a subpackage on install Source: https://rpm.org/docs/6.1.x/manual/scriptlet_expansion.html This scriptlet runs after a subpackage is installed. It uses 'update-alternatives' to manage the 'frobber' command, pointing it to the implementation provided by this subpackage. ```bash %post myimpl update-alternatives --install /usr/bin/frobber \ frobber /usr/bin/frobber.myimpl 10 ``` -------------------------------- ### Dependency Generator Output Example 1 Source: https://rpm.org/docs/6.1.x/manual/more_dependencies.html Example output from a per-interpreter dependency generator, showing a mix of packages and language-specific modules with version specifiers. ```spec Mail-Header >= 1.01 perl(Carp) >= 3.2 perl(IO-Wrap) == 4.5 or perl(IO-Wrap)-4.5 ``` -------------------------------- ### Install RPM Source Package Source: https://rpm.org/docs/6.1.x/api/rpmlib_8h_source.html Installs an RPM source package. This function handles the process of setting up a source package for building. ```c rpmRC rpmInstallSourcePackage(rpmts ts, FD_t fd, char ** specFilePtr, char ** cookie) ``` -------------------------------- ### RPM Conflict Example Source: https://rpm.org/docs/6.1.x/manual/dependencies.html A basic example of a Conflicts tag in a spec file, preventing installation if a specified package is already present. ```text Conflicts: sendmail ``` -------------------------------- ### Install or Upgrade Package Source: https://rpm.org/docs/6.1.x/man/rpm.8 Installs or upgrades a specified RPM package with verbose output and progress meters. This is a very common operation. ```bash rpm -Uvh hello-2.0-1.noarch.rpm ``` -------------------------------- ### Execute Install Stage Only Source: https://rpm.org/docs/6.1.x/man/rpmbuild.1 Executes only the %install stage of a spec file, skipping previous stages. Assumes a preceding build up to the %build stage. ```bash rpmbuild -bi --short-circuit hello.spec ``` -------------------------------- ### Serve Reference Manual Locally Source: https://rpm.org/docs/6.1.x/manual/devel_documentation.html Use 'jekyll serve' in the 'docs' directory to start a local web server, allowing you to preview the rendered Reference Manual on localhost. ```bash jekyll serve ``` -------------------------------- ### Scriptlet Dependencies Example Source: https://rpm.org/docs/6.1.x/manual/more_dependencies.html Specifies dependencies required only during package installation or erasure, such as for scriptlets. Ensures correct installation order and allows for removal of dependency packages if no other package requires them. ```spec Requires(pre): /usr/sbin/useradd ``` -------------------------------- ### Automated Patch Application with Git Integration Source: https://rpm.org/docs/6.1.x/manual/autosetup.html This example shows how %autosetup can be used with Git to unpack sources and apply patches using individual git apply commands and commits. ```rpm %autosetup -S git ``` -------------------------------- ### Failed Dependencies Message Source: https://rpm.org/docs/6.1.x/manual/more_dependencies.html Example error message indicating that required dependencies are not met during package installation or upgrade. ```text failed dependencies: libICE.so.6 is needed by somepackage-2.11-1 libSM.so.6 is needed by somepackage-2.11-1 libc.so.5 is needed by somepackage-2.11-1 ``` -------------------------------- ### Build Reference Manual Locally Source: https://rpm.org/docs/6.1.x/manual/devel_documentation.html Navigate to the 'docs' directory and execute 'jekyll build' to generate the static website for the Reference Manual in the 'docs/_site' directory. ```bash jekyll build ``` -------------------------------- ### Autotools Build System Macros Source: https://rpm.org/docs/6.1.x/manual/buildsystem.html Example of defining macros to support the autotools build system. These macros define the configuration, build, and install steps. ```spec %buildsystem_autotools_conf() %configure %* %buildsystem_autotools_build() %make_build %* %buildsystem_autotools_install() %make_install %* ``` -------------------------------- ### Verbose Source Unpacking with %autosetup Source: https://rpm.org/docs/6.1.x/manual/autosetup.html Use the -v option with %autosetup for verbose output during source unpacking. ```rpm %autosetup -v ``` -------------------------------- ### RPM Callback Type Enumeration Source: https://rpm.org/docs/6.1.x/api/rpmcallback_8h.html Enumerates the different types of callbacks that can be triggered during RPM operations, including progress, start, stop, and error events for installation, transaction, repackaging, and verification. ```c typedef enum rpmCallbackType_e { RPMCALLBACK_UNKNOWN = 0, RPMCALLBACK_INST_PROGRESS = (1 << 0), RPMCALLBACK_INST_START = (1 << 1), RPMCALLBACK_INST_OPEN_FILE = (1 << 2), RPMCALLBACK_INST_CLOSE_FILE = (1 << 3), RPMCALLBACK_TRANS_PROGRESS = (1 << 4), RPMCALLBACK_TRANS_START = (1 << 5), RPMCALLBACK_TRANS_STOP = (1 << 6), RPMCALLBACK_UNINST_PROGRESS = (1 << 7), RPMCALLBACK_UNINST_START = (1 << 8), RPMCALLBACK_UNINST_STOP = (1 << 9), RPMCALLBACK_REPACKAGE_PROGRESS = (1 << 10), RPMCALLBACK_REPACKAGE_START = (1 << 11), RPMCALLBACK_REPACKAGE_STOP = (1 << 12), RPMCALLBACK_UNPACK_ERROR = (1 << 13), RPMCALLBACK_CPIO_ERROR = (1 << 14), RPMCALLBACK_SCRIPT_ERROR = (1 << 15), RPMCALLBACK_SCRIPT_START = (1 << 16), RPMCALLBACK_SCRIPT_STOP = (1 << 17), RPMCALLBACK_INST_STOP = (1 << 18), RPMCALLBACK_ELEM_PROGRESS = (1 << 19), RPMCALLBACK_VERIFY_PROGRESS = (1 << 20), RPMCALLBACK_VERIFY_START = (1 << 21), RPMCALLBACK_VERIFY_STOP = (1 << 22) } rpmCallbackType_e; ``` -------------------------------- ### Global rpmInstall Source: https://rpm.org/docs/6.1.x/api/todo.html Installs RPM packages. ```APIDOC ## Global rpmInstall ### Description Installs RPM packages. ### Parameters - **ts** (rpmts) - The transaction set. - **ia** (struct rpmInstallArguments_s *) - Structure containing installation arguments. - **fileArgv** (ARGV_t) - Argument list of files to install. Note: This argument is modified on errors and should ideally be ARGV_const_t. ``` -------------------------------- ### Example: Get MIME Type for File Analysis Source: https://rpm.org/docs/6.1.x/man/rpm-dependency-generators.7 This command shows how to use the 'file' utility to determine the MIME type of a file, which can be used to find a compatible MIME regex for RPM dependency generators. ```bash file --mime /some/file ``` -------------------------------- ### Example of ISA Dependency Expansion (i386 Target) Source: https://rpm.org/docs/6.1.x/manual/arch_dependencies.html This illustrates the expansion of the %{?_isa} macro when targeting an i386 architecture, demonstrating how it selects the 32-bit version of the dependency. ```rpm Requires: libbar-devel(x86-32) >= 2.2 ``` -------------------------------- ### Verifying User and Group Creation After Installation Source: https://rpm.org/docs/6.1.x/man/rpm-sysusers.7 These commands verify that the 'dnsmasq' user and group were created correctly after the RPM package is installed, and that the specified directory is owned by the correct group. ```bash $ getent passwd dnsmasq dnsmasq:x:999:999:Dnsmasq DHCP and DNS server:/var/lib/dnsmasq:/usr/sbin/nologin ``` ```bash $ getent group dnsmasq dnsmasq:x:999: ``` ```bash $ stat -c '%G:%g' /var/lib/dnsmasq dnsmasq:999 ``` -------------------------------- ### Get file status information Source: https://rpm.org/docs/6.1.x/man/rpm-lua.7 Retrieves file status information (stat(3)) for a given path. If a selector is provided, it returns a specific value; otherwise, it returns a table with all fields. The second example shows a comparison of inode and device numbers. ```lua print(posix.stat('/tmp', 'mode')) ``` ```lua s1 = posix.stat('f1') s2 = posix.stat('f2') if s1.ino == s2.ino and s1.dev == s2.dev then ... end ``` -------------------------------- ### rpmInstall Source: https://rpm.org/docs/6.1.x/api/group__rpmcli.html Performs the installation of packages based on the provided arguments and file list. ```APIDOC ## Function Documentation ## ◆ rpmInstall int rpmInstall (rpmts ts, struct rpmInstallArguments_s *ia, ARGV_t fileArgv) ``` -------------------------------- ### RPM Installation Functions Source: https://rpm.org/docs/6.1.x/api/globals_r.html Functions for installing packages and managing installation flags. ```APIDOC ## RPM Installation Functions ### Description Functions for installing RPM packages and specifying installation options. ### Functions - **rpmInstall()**: Installs an RPM package. - **rpmInstallFlags_e**: Enumeration for installation flags. - **rpmInstallSource()**: Installs an RPM package from a source. - **rpmInstallSourcePackage()**: Installs a source package. ### Header rpmcli.h, rpmlib.h ``` -------------------------------- ### Install Package Quietly Source: https://rpm.org/docs/6.1.x/man/rpm.8 Installs an RPM package quietly. This is often used for installing kernel packages to allow parallel installations without erasing older versions. ```bash rpm -i kernel-6.15.4-200.x86_64.rpm ``` -------------------------------- ### Query Format Example Source: https://rpm.org/docs/latest/manual/queryformat.html Illustrates a simple query format string, showing how literal text can be combined with placeholders to extract specific package information. ```text %{NAME}-%{VERSION}-%{RELEASE} ``` -------------------------------- ### RPM Install Function Source: https://rpm.org/docs/6.1.x/api/group__rpmcli.html Installs RPM packages based on the provided transaction set and arguments. It takes a transaction set, install arguments, and a list of files to install. ```c int rpmInstall (rpmts ts, struct rpmInstallArguments_s *ia, ARGV_t fileArgv) ``` -------------------------------- ### RPM ExclusiveOS Example Source: https://rpm.org/docs/6.1.x/manual/spec.html Specifies operating systems on which the package is buildable. ```spec ExclusiveOS: linux ``` -------------------------------- ### RPM Install Function Source: https://rpm.org/docs/latest/api/rpmcli_8h_source.html This function installs RPM packages using provided transaction set and installation arguments. ```c int rpmInstall(rpmts ts, struct rpmInstallArguments_s *ia, ARGV_t fileArgv); ``` -------------------------------- ### Dependency Generator Output Example Source: https://rpm.org/docs/latest/manual/more_dependencies.html Illustrates the output format from a per-interpreter dependency generator, showing version comparisons and module requirements. ```text Mail-Header >= 1.01 perl(Carp) >= 3.2 perl(IO-Wrap) == 4.5 or perl(IO-Wrap)-4.5 ``` ```text Foo-0.9 perl(Widget)-0-1 ``` -------------------------------- ### RPM Install Flags Source: https://rpm.org/docs/latest/api/rpmcli_8h.html Defines flags for controlling the installation process, such as enabling progress display, handling upgrades, or specifying installation type. ```c #define UNINSTALL_NONE INSTALL_NONE #define UNINSTALL_NODEPS INSTALL_NODEPS #define UNINSTALL_ALLMATCHES INSTALL_ALLMATCHES enum rpmInstallFlags_e { INSTALL_NONE = 0 , INSTALL_PERCENT = (1 << 0) , INSTALL_HASH = (1 << 1) , INSTALL_NODEPS = (1 << 2) , INSTALL_NOORDER = (1 << 3) , INSTALL_LABEL = (1 << 4) , INSTALL_UPGRADE = (1 << 5) , INSTALL_FRESHEN = (1 << 6) , INSTALL_INSTALL = (1 << 7) , INSTALL_ERASE = (1 << 8) , INSTALL_ALLMATCHES = (1 << 9) , INSTALL_REINSTALL = (1 << 10) , INSTALL_RESTORE = (1 << 11) } ``` -------------------------------- ### RPM Lead Package Name Example Source: https://rpm.org/docs/latest/manual/format_lead.html Displays the bytes corresponding to the package name, typically in 'name-version-release' format, padded with null bytes. ```text 00000010: 31 2e 32 2d 31 00 00 00 1.2-1... 00000018: 00 00 00 00 00 00 00 00 ........ 00000020: 00 00 00 00 00 00 00 00 ........ 00000028: 00 00 00 00 00 00 00 00 ........ 00000030: 00 00 00 00 00 00 00 00 ........ 00000038: 00 00 00 00 00 00 00 00 ........ 00000040: 00 00 00 00 00 00 00 00 ........ 00000048: 00 00 00 00 00 01 00 05 ........ ``` -------------------------------- ### RPM Header Data Section Example (Strings) Source: https://rpm.org/docs/latest/manual/format_header.html A snippet from the data section, showing null-terminated strings for package name, version, and description. ```text 00000210: 72 70 6d 00 32 2e 31 2e 32 00 31 00 52 65 64 20 rpm.2.1.2.1.Red 00000220: 48 61 74 20 50 61 63 6b 61 67 65 20 4d 61 6e 61 Hat Package Mana 00000230: 67 65 72 00 31 e7 cb b4 73 63 68 72 6f 65 64 65 ger.1...schroede 00000240: 72 2e 72 65 64 68 61 74 2e 63 6f 6d 00 00 00 00 r.redhat.com.... ...00000970: 6c 69 62 63 2e 73 6f 2e 35 00 6c 69 62 64 2e libc.so.5.libdb. 00000980: 73 6f 2e 32 00 00 so.2.. ``` -------------------------------- ### RPM Installation Functions Source: https://rpm.org/docs/6.1.x/api/globals_func_r.html Functions for installing RPM packages. ```APIDOC ## rpmInstall() ### Description Installs an RPM package. ### Method Not applicable (function signature) ### Endpoint Not applicable (function signature) ### Parameters None ### Request Example None ### Response None #### Success Response (200) None #### Response Example None ``` ```APIDOC ## rpmInstallSource() ### Description Installs an RPM source package. ### Method Not applicable (function signature) ### Endpoint Not applicable (function signature) ### Parameters None ### Request Example None ### Response None #### Success Response (200) None #### Response Example None ``` ```APIDOC ## rpmInstallSourcePackage() ### Description Installs an RPM source package (alternative). ### Method Not applicable (function signature) ### Endpoint Not applicable (function signature) ### Parameters None ### Request Example None ### Response None #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Basic BuildRequires and Requires for -devel Packages Source: https://rpm.org/docs/6.1.x/manual/arch_dependencies.html This example shows the basic syntax for specifying build and runtime dependencies on -devel packages. It highlights a limitation on multiarch systems where a 32-bit package might incorrectly satisfy a dependency for a 64-bit package and vice-versa. ```rpm Name: foo ... BuildRequires: libbar-devel >= 2.2 %package devel Requires: libbar-devel >= 2.2 ... ``` -------------------------------- ### Verifying User and Group Creation After Installation Source: https://rpm.org/docs/6.1.x/manual/users_and_groups.html Shows how to verify that RPM has correctly created the user and group, and set ownership on a directory as defined in the sysusers.d file. ```bash $ getent passwd dnsmasq dnsmasq:x:999:999:Dnsmasq DHCP and DNS server:/var/lib/dnsmasq:/usr/sbin/nologin $ getent group dnsmasq dnsmasq:x:999: $ stat -c '%G:%g' /var/lib/dnsmasq dnsmasq:999 ``` -------------------------------- ### RPM Install Flags Typedef Source: https://rpm.org/docs/latest/api/rpmcli_8h_source.html Typedef for rpmFlags, aliasing it to rpmInstallFlags for clarity in installation contexts. ```c typedef rpmFlags rpmInstallFlags; ``` -------------------------------- ### rpmcliInit Source: https://rpm.org/docs/latest/api/rpmcli_8h_source.html Initializes the RPM CLI environment with the given arguments and options table. Returns a popt context for managing options. ```APIDOC ## rpmcliInit ### Description Initializes the RPM CLI environment. ### Signature `poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable);` ### Parameters - **argc**: The number of arguments. - **argv**: The array of arguments. - **optionsTable**: The popt options table. ``` -------------------------------- ### rpmInstallSource Source: https://rpm.org/docs/6.1.x/api/group__rpmcli.html Installs packages from a specified source. This function is a core part of the RPM installation process. ```APIDOC ## Function Documentation ## ◆ rpmInstallSource int rpmInstallSource (rpmts ts, const char *arg, char **specFilePtr, char **cookie) ``` -------------------------------- ### Example sysusers.d Entry Source: https://rpm.org/docs/6.1.x/man/rpm-sysusers.7 A sample entry in the sysusers.d format for creating a user. ```shell u dnsmasq - "Dnsmasq DHCP and DNS server" /var/lib/dnsmasq ``` -------------------------------- ### Example Summary Tag Source: https://rpm.org/docs/latest/manual/spec.html Provides a short description of the package's functionality. Keep the summary under 70 characters. ```spec Summary: Utility for converting mumbles into giggles ``` -------------------------------- ### Example of ISA Dependency Expansion (x86_64) Source: https://rpm.org/docs/6.1.x/manual/arch_dependencies.html This shows how the %{?_isa} macro expands when building a native package on an x86_64 system, resulting in a specific architecture and bitness requirement. ```rpm Requires: libbar-devel(x86-64) >= 2.2 ``` -------------------------------- ### Automated Patch Application with %autosetup Source: https://rpm.org/docs/6.1.x/manual/autosetup.html The %autosetup macro automates the application of all patches declared in the spec file, ordered by patch number. ```rpm %prep %autosetup ``` -------------------------------- ### RPM Header Data Section Example (Strings) Source: https://rpm.org/docs/6.1.x/manual/format_header.html A snippet showing the beginning of the data section, including null-terminated strings for package name, version, and other fields. ```hex 00000210: 72 70 6d 00 32 2e 31 2e 32 00 31 00 52 65 64 20 rpm.2.1.2.1.Red 00000220: 48 61 74 20 50 61 63 6b 61 67 65 20 4d 61 6e 61 Hat Package Mana 00000230: 67 65 72 00 31 e7 cb b4 73 63 68 72 6f 65 64 65 ger.1...schroede 00000240: 72 2e 72 65 64 68 61 74 2e 63 6f 6d 00 00 00 00 r.redhat.com.... ``` -------------------------------- ### RPM Install Arguments Global Variable Source: https://rpm.org/docs/latest/api/rpmcli_8h_source.html Global variable holding the default installation arguments for the RPM CLI. ```c extern struct rpmInstallArguments_s rpmIArgs; ``` -------------------------------- ### rpmInstall Source: https://rpm.org/docs/latest/api/group__rpmcli.html Installs, upgrades, or freshens binary RPM packages. This function handles the installation process for RPM packages. ```APIDOC ## rpmInstall() ### Description Install/upgrade/freshen/reinstall binary rpm package. ### Parameters * **ts** (rpmts) - transaction set * **ia** (struct rpmInstallArguments_s *) - mode flags and parameters * **fileArgv** (ARGV_t) - array of package file names (NULL terminated) ### Returns 0 on success ``` -------------------------------- ### RPM CLI Initialization Source: https://rpm.org/docs/latest/api/rpmcli_8h_source.html Initializes the RPM CLI with command-line arguments and a specific options table. Returns a popt context. ```c poptContext rpmcliInit(int argc, char *const argv[], struct poptOption *optionsTable); ``` -------------------------------- ### RPM Install Only Mask Macro Source: https://rpm.org/docs/6.1.x/api/rpmds_8h.html Defines a bitmask for dependencies that are only relevant during installation. Excludes script and transaction-related flags. ```c #define _INSTALL_ONLY_MASK _notpre(RPMSENSE_SCRIPT_PRE|RPMSENSE_SCRIPT_POST|RPMSENSE_RPMLIB|RPMSENSE_KEYRING|RPMSENSE_PRETRANS|RPMSENSE_POSTTRANS) ``` -------------------------------- ### Conditional Configuration with %configure and %{?with_foo} Source: https://rpm.org/docs/latest/manual/conditionalbuilds.html Shows how to conditionally pass arguments to the %configure script based on build conditionals like 'with_static'. ```rpm %configure \ %{?with_static:--enable-static} \ %{!?with_static:--disable-static} ``` -------------------------------- ### rpmInstallSource Source: https://rpm.org/docs/latest/api/group__rpmcli.html Installs a source RPM package. This function is used to install the source code and related files for an RPM package. ```APIDOC ## rpmInstallSource() ### Description Install source rpm package. ### Parameters * **ts** (rpmts) - transaction set * **arg** (const char *) - source rpm file name * **specFilePtr** (char **) - [out] (installed) spec file name * **cookie** (char **) - [out] ### Returns 0 on success ``` -------------------------------- ### rpmtxnRebuildKeystore() Source: https://rpm.org/docs/6.1.x/api/group__rpmts.html Rebuilds the key store using current settings and populates it with keys from the keyring. ```APIDOC ## rpmtxnRebuildKeystore() ### Description Rebuild key store using current settings and fill it with keys form keyring. ### Parameters * **kxn** (rpmtxn) - keystore handle * **from** (const char *) - backend to get the keys from ### Returns * RPMRC_OK on success ``` -------------------------------- ### RPM Query Format Example Source: https://rpm.org/docs/6.1.x/man/rpm-queryformat.7 Illustrates a basic query format string with literal text and a placeholder for the package name. ```text %{NAME} ``` -------------------------------- ### Inspecting Installed sysusers.d File Source: https://rpm.org/docs/6.1.x/manual/users_and_groups.html This snippet shows how to locate and view the content of a sysusers.d file that has been installed by an RPM package. ```bash $ rpm -ql dnsmasq | grep sysusers /usr/lib/sysusers.d/dnsmasq.conf $ cat /usr/lib/sysusers.d/dnsmasq.conf u dnsmasq - "Dnsmasq DHCP and DNS server" /var/lib/dnsmasq ``` -------------------------------- ### Complex Architecture Dependencies with Conditional Macros Source: https://rpm.org/docs/latest/manual/arch_dependencies.html An example demonstrating how to handle multiple architecture families and their specific flavors using conditional macros and regular expressions in dependencies. ```spec %ifarch %ix86 Requires: %{name}.(i?86|athlon|geode) %endif %ifarch x86_64 amd64 ia32e Requires: %{name}.(x86_64|amd64|ia32e) %endif ... ``` -------------------------------- ### RPM Installation Flags Source: https://rpm.org/docs/6.1.x/api/rpmcli_8h.html Defines flags for controlling the installation process, such as progress display, dependency handling, and upgrade behavior. ```c #define UNINSTALL_NONE INSTALL_NONE #define UNINSTALL_NODEPS INSTALL_NODEPS #define UNINSTALL_ALLMATCHES INSTALL_ALLMATCHES ``` ```c enum rpmInstallFlags_e { INSTALL_NONE = 0, INSTALL_PERCENT = (1 << 0), INSTALL_HASH = (1 << 1), INSTALL_NODEPS = (1 << 2), INSTALL_NOORDER = (1 << 3), INSTALL_LABEL = (1 << 4), INSTALL_UPGRADE = (1 << 5), INSTALL_FRESHEN = (1 << 6), INSTALL_INSTALL = (1 << 7), INSTALL_ERASE = (1 << 8), INSTALL_ALLMATCHES = (1 << 9), INSTALL_REINSTALL = (1 << 10), INSTALL_RESTORE = (1 << 11) } ``` -------------------------------- ### List Package Names and Prein Scriptlet Programs Source: https://rpm.org/docs/6.1.x/man/rpm-queryformat.7 Prints a table of installed package names and the programs used for their 'prein' scriptlets. Displays 'no' if no 'prein' scriptlet exists. Useful for identifying scriptlet execution environments. ```bash rpm -qa --queryformat "%-30{NAME} %|PREINPROG?{ %{PREINPROG}}:{ no}|\n" ``` -------------------------------- ### Package Summary Example Source: https://rpm.org/docs/6.1.x/manual/spec.html Provides a brief, human-readable summary of the package's purpose. Keep the summary short. ```spec Summary: Utility for converting mumbles into giggles ``` -------------------------------- ### Example RPM Tags and Types Source: https://rpm.org/docs/6.1.x/manual/queryformat.html Sample output showing common RPM tags, their internal numbers, and data types (e.g., string, int32, argv). ```text BASENAMES 1117 argv BUILDHOST 1007 string BUILDTIME 1006 int32 DESCRIPTION 1005 i18nstring EPOCH 1003 int32 INSTALLTIME 1008 int32 NAME 1000 string RELEASE 1002 string SIZE 1009 int32 SUMMARY 1004 i18nstring VERSION 1001 string ``` -------------------------------- ### RPM Install Popt Table Source: https://rpm.org/docs/latest/api/rpmcli_8h_source.html An array of poptOption structures used for parsing command-line arguments specifically for RPM installation commands. ```c extern struct poptOption rpmInstallPoptTable[]; ``` -------------------------------- ### Inspecting Packaged sysusers.d File Source: https://rpm.org/docs/6.1.x/man/rpm-sysusers.7 This command lists the files installed by the RPM package and shows the content of the installed sysusers.d file. ```bash $ rpm -ql dnsmasq | grep sysusers /usr/lib/sysusers.d/dnsmasq.conf ``` ```bash $ cat /usr/lib/sysusers.d/dnsmasq.conf u dnsmasq - "Dnsmasq DHCP and DNS server" /var/lib/dnsmasq ``` -------------------------------- ### rpmKeyringNew Source: https://rpm.org/docs/6.1.x/api/group__rpmkeyring.html Creates and returns a handle to a new, empty RPM keyring. This is the initial step before adding any keys. ```APIDOC ## rpmKeyringNew() ### Description Creates a new, empty keyring. ### Returns A handle to the new keyring. ``` -------------------------------- ### rpmdsSingle() Source: https://rpm.org/docs/6.1.x/api/group__rpmds.html Creates, loads, and initializes a dependency set of size 1. It requires the dependency type, name, epoch:version-release, and comparison flags. ```APIDOC ## rpmdsSingle() ### Description Create, load and initialize a dependency set of size 1. ### Parameters - **tagN** (rpmTagVal) - Type of dependency - **N** (const char *) - Name - **EVR** (const char *) - Epoch:version-release - **Flags** (rpmsenseFlags) - Comparison flags ### Returns - new dependency set ``` -------------------------------- ### rpmInstallSourcePackage Source: https://rpm.org/docs/6.1.x/api/rpmlib_8h_source.html Installs an RPM source package. This function handles the process of installing a source package, potentially generating a spec file. ```APIDOC ## rpmInstallSourcePackage ### Description Installs an RPM source package. This function handles the process of installing a source package, potentially generating a spec file. ### Method rpmRC ### Parameters * **ts** (rpmts) - The transaction set. * **fd** (FD_t) - The file descriptor of the source package. * **specFilePtr** (char **) - Pointer to store the generated spec file content. * **cookie** (char **) - Pointer to store a cookie value. ``` -------------------------------- ### rpmdsInit() Source: https://rpm.org/docs/6.1.x/api/group__rpmds.html Initializes a dependency set iterator. ```APIDOC ## rpmdsInit() ### Description Initialize dependency set iterator. ### Parameters * `ds` (rpmds) - dependency set ### Returns * `rpmds` - dependency set ``` -------------------------------- ### Example Source Tags Source: https://rpm.org/docs/latest/manual/spec.html Declares the source files used to build the package. Multiple sources can be declared using numbered tags. ```spec Source0: mysoft-1.0.tar.gz Source1: mysoft-data-1.0.zip ``` -------------------------------- ### rpmdsSingle() Source: https://rpm.org/docs/latest/api/group__rpmds.html Creates, loads, and initializes a dependency set of size 1 with specified dependency type, name, version-release, and comparison flags. ```APIDOC ## rpmdsSingle() ### Description Create, load and initialize a dependency set of size 1. ### Parameters - **tagN** (rpmTagVal) - Type of dependency - **N** (const char *) - Name - **EVR** (const char *) - epoch:version-release - **Flags** (rpmsenseFlags) - Comparison flags ### Returns - new dependency set ``` -------------------------------- ### Get Dependency Name Source: https://rpm.org/docs/latest/api/rpmds_8h_source.html Retrieves the name of a dependency from a dependency set. This function is used to get the package name associated with a dependency. ```c const char * rpmdsN(const rpmds ds); ``` -------------------------------- ### Apply Patches with %autopatch (Range <= 400) Source: https://rpm.org/docs/latest/manual/autosetup.html This example shows how to apply patches up to a specific number using the -M option with %autopatch. ```rpm %autopatch -M 400 ``` -------------------------------- ### RPM Install Flags Enum Source: https://rpm.org/docs/latest/api/rpmcli_8h_source.html Enumeration defining flags for RPM installation operations, such as setting progress indicators or specifying dependency handling. ```c enum rpmInstallFlags_e { INSTALL_NONE = 0, INSTALL_PERCENT = (1 << 0), INSTALL_HASH = (1 << 1), INSTALL_NODEPS = (1 << 2), INSTALL_NOORDER = (1 << 3), INSTALL_LABEL = (1 << 4), INSTALL_UPGRADE = (1 << 5), INSTALL_FRESHEN = (1 << 6), INSTALL_INSTALL = (1 << 7), INSTALL_ERASE = (1 << 8), INSTALL_ALLMATCHES = (1 << 9), INSTALL_REINSTALL = (1 << 10), INSTALL_RESTORE = (1 << 11), }; ``` -------------------------------- ### List Package Names and Human-Readable Sizes Source: https://rpm.org/docs/6.1.x/man/rpm-queryformat.7 Prints a table of all installed package names and their human-readable sizes. Use this to quickly see disk space usage per package. ```bash rpm -qa --queryformat "%-30{NAME} %{SIZE:humaniec}\n" ``` -------------------------------- ### RPM Lead Version and Type Example Source: https://rpm.org/docs/latest/manual/format_lead.html Shows the bytes representing the major and minor RPM file format version, followed by the package type (binary or source). ```text 00000008: 00 01 72 70 6d 2d 32 2e ..rpm-2. ``` -------------------------------- ### RPM Install Source Function Source: https://rpm.org/docs/latest/api/rpmcli_8h_source.html This function installs RPM packages from a specified source. It can also return the spec file path and a cookie. ```c int rpmInstallSource(rpmts ts, const char *arg, char **specFilePtr, char **cookie); ``` -------------------------------- ### RPM Install Arguments Structure Source: https://rpm.org/docs/latest/api/rpmcli_8h_source.html Structure to hold arguments for RPM installation, including transaction flags, probability filters, and interface flags. ```c struct rpmInstallArguments_s { rpmtransFlags transFlags; rpmprobFilterFlags probFilter; rpmInstallFlags installInterfaceFlags; int numRelocations; int noDeps; int incldocs; rpmRelocation * relocations; char * prefix; }; ``` -------------------------------- ### rpmcliInit Source: https://rpm.org/docs/6.1.x/api/group__rpmcli.html Initializes the necessary components for an RPM CLI executable context, setting up argument parsing and options. ```APIDOC ## rpmcliInit() ### Description Initializes most everything needed by an rpm CLI executable context. ### Parameters * **argc** (int) - The number of arguments. * **argv** (char *const[]) - The argument array. * **optionsTable** (struct poptOption *) - The popt option table. ### Returns A popt context (or NULL on failure). ``` -------------------------------- ### Apply Specific Patches with %autopatch Source: https://rpm.org/docs/latest/manual/autosetup.html This example shows how to apply a list of specific patch numbers using %autopatch. ```rpm %autopatch 1 4 6 ``` -------------------------------- ### RPMFILE_IS_INSTALLED Macro Source: https://rpm.org/docs/6.1.x/api/rpmfiles_8h.html Checks if a file is in a normal or net-shared state, indicating it is considered installed. This macro is used to determine the installation status of a file. ```c #define RPMFILE_IS_INSTALLED | ( | | __x_| ) | ((_x) == RPMFILE_STATE_NORMAL || (_x) == RPMFILE_STATE_NETSHARED) ``` -------------------------------- ### Initialize Macro Context Source: https://rpm.org/docs/latest/api/rpmmacro_8h_source.html Shows the initialization of a macro context using rpmInitMacros. This sets up the macro system, optionally with a specific set of macro files. ```c #include #include int main() { // Initialize with default macro files rpmMacroContext mc_default = NULL; rpmInitMacros(mc_default, NULL); // Initialize with a specific macro file (example) rpmMacroContext mc_specific = NULL; rpmInitMacros(mc_specific, "/etc/rpm/macros"); // Note: rpmInitMacros typically operates on a global context or requires a pre-allocated context. // For explicit context management, rpmMacroContextInit is often preferred. // This example is illustrative of the function signature. // Example using rpmMacroContextInit for explicit context management: rpmMacroContext mc = rpmMacroContextInit(NULL); if (mc) { printf("Macro context initialized successfully.\n"); rpmFreeMacros(mc); } return 0; } ``` -------------------------------- ### RPM File Installed Macro Source: https://rpm.org/docs/6.1.x/api/rpmfiles_8h_source.html A macro to check if a file is considered installed based on its state. It returns true for normal or net-shared states. ```c #define RPMFILE_IS_INSTALLED(_x) ((_x) == RPMFILE_STATE_NORMAL || (_x) == RPMFILE_STATE_NETSHARED) ``` -------------------------------- ### rpmteSetDBInstance() Source: https://rpm.org/docs/6.1.x/api/group__rpmte.html Sets the last installed database instance for a transaction element. This is important for tracking package installations across different database instances. ```APIDOC ## rpmteSetDBInstance() ### Description Set last instance installed to the database. ### Parameters * **te** (rpmte) - transaction element * **instance** (unsigned int) - Database instance of last install element. ### Returns * void ``` -------------------------------- ### Create a New RPM Keyring Source: https://rpm.org/docs/6.1.x/api/rpmkeyring_8h_source.html Initializes and returns a new, empty RPM keyring. Call rpmKeyringFree when done. ```c rpmKeyring rpmKeyringNew(void); ``` -------------------------------- ### Mark Files as Licenses with %license Source: https://rpm.org/docs/6.1.x/manual/spec.html Use %license to mark and install files as licenses. These must always be present in packages. ```spec %license /usr/share/licenses/myprogram/LICENSE ``` -------------------------------- ### Post-installation script to add a shell Source: https://rpm.org/docs/6.1.x/manual/scriptlet_expansion.html This scriptlet runs after a package is installed. It checks if the shell is already present and adds it to /etc/shells if it's a new installation. ```bash %post if [ $1 -eq 1 ]; then # Initial install grep -q '^/bin/mysh$' /etc/shells || echo '/bin/mysh' >> /etc/shells fi ``` -------------------------------- ### RPM Header Immutable Region Tag Example Source: https://rpm.org/docs/latest/manual/format_header.html Example of an index entry for an immutable region, specifying tag (HEADERIMMUTABLE or HEADERSIGNATURES) and type BIN. ```text 00000240: 72 2e 72 65 64 68 61 74 2e 63 6f 6d 00 00 00 00 r.redhat.com.... 00000250: 00 09 9b 31 52 65 64 20 48 61 74 20 4c 69 6e 75 ....Red Hat Linu ``` -------------------------------- ### XZ Compression Level 7 with 16 Threads Source: https://rpm.org/docs/6.1.x/man/rpm-payloadflags.7 Example of configuring xz compression with level 7 and specifying 16 threads. ```bash w7T16.xzdio ``` -------------------------------- ### RPM Header Index Entry Example Source: https://rpm.org/docs/6.1.x/manual/format_header.html An example of an index entry, showing tag, type, offset, and count. This entry represents the package name. ```assembly 00000010: 00 00 03 e8 00 00 00 06 00 00 00 00 00 00 00 01 ................ ```