rpm
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rpm [2012/04/12 18:34] – [RPM Spec File Information] k2patel | rpm [2020/08/10 02:35] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== RPM ====== | ====== RPM ====== | ||
+ | |||
+ | * [[ Python packages to rpm ]] | ||
Package management system few tips / trick to build / modify / work with packages. \\ | Package management system few tips / trick to build / modify / work with packages. \\ | ||
Many hints information taken from original site [[http:// | Many hints information taken from original site [[http:// | ||
+ | ==== RPM Common Command ==== | ||
+ | |||
+ | ^ Syntax ^Description^ | ||
+ | | rpm -ivh {rpm-file} | Install the package | | ||
+ | | rpm -Uvh {rpm-file} | Upgrade package | | ||
+ | | rpm -ev {package} | Erase/ | ||
+ | | rpm -ev --nodeps {package} | Erase/ | ||
+ | | rpm -qa | Display list all installed packages | | ||
+ | | rpm -qi {package} | Display installed information along with package version and short description | | ||
+ | | rpm -qf {/ | ||
+ | | rpm -qc {pacakge-name} | Display list of configuration file(s) for a package | | ||
+ | | rpm -qcf {/ | ||
+ | | rpm -qa --last | Display list of all recently installed RPMs | | ||
+ | | rpm -qpR {.rpm-file} | Find out what dependencies a rpm file has | | ||
+ | | rpm -qR {package} | ::: | | ||
+ | | rpm -qR bash | ::: | | ||
==== How to Print .spec file from RPM ==== | ==== How to Print .spec file from RPM ==== | ||
Line 125: | Line 143: | ||
</ | </ | ||
+ | ==== Something i come across ==== | ||
+ | If you wanna override marco from OS you can define value at '' | ||
+ | <code bash> | ||
+ | %define _mandir /usr/man | ||
+ | </ | ||
==== Sample RPM ==== | ==== Sample RPM ==== | ||
<code bash | sample.spec> | <code bash | sample.spec> | ||
Line 216: | Line 239: | ||
[[http:// | [[http:// | ||
+ | ==== Scriptlets ==== | ||
+ | |||
+ | Normally, rpm has scriptlets inside the spec file that are | ||
+ | ran at install time. These are: | ||
+ | <code bash> | ||
+ | %pre - Run before rpm files are installed. | ||
+ | %post | ||
+ | %preun | ||
+ | %postun | ||
+ | | ||
+ | %triggerun | ||
+ | %triggerpostun | ||
+ | </ | ||
+ | The scripts are normally bash scripts, but you can change the interpreter | ||
+ | with the -p option. | ||
+ | |||
+ | Also, as they are bash scripts you can call external scripts from these. | ||
==== General RPM Command ==== | ==== General RPM Command ==== | ||
Line 223: | Line 263: | ||
</ | </ | ||
+ | |||
+ | ==== Error on Building ==== | ||
+ | === module: command not found === | ||
+ | Try running following command and then execute rpmbuild will resolve the issue. | ||
+ | <code bash> | ||
+ | source / | ||
+ | </ | ||
==== MOCK ==== | ==== MOCK ==== | ||
Line 267: | Line 314: | ||
</ | </ | ||
+ | == Building SRPM == | ||
+ | <code bash> | ||
+ | mock -r epel-6-x86_64 --spec icinga-web.spec --sources=../ | ||
+ | </ | ||
==== Copying Files ==== | ==== Copying Files ==== | ||
<note important> | <note important> | ||
Line 292: | Line 343: | ||
In general case result will be stored in '/ | In general case result will be stored in '/ | ||
- | ==== RPM Spec File Information | + | ==== SPEC file Overview |
This is mostly from following URL [[http:// | This is mostly from following URL [[http:// | ||
<code text> | <code text> | ||
- | SPEC file overview | ||
Other useful guides: | Other useful guides: | ||
Line 387: | Line 437: | ||
See the %prep section below for more. | See the %prep section below for more. | ||
- | %build: Script commands to " | + | %build: Script commands to " |
+ | The program should come with instructions on how to do this. See the %build section below for more. | ||
- | %check: Script commands to " | + | %check: Script commands to " |
+ | so place it there if you have this section. Often it simply contains "make test" or "make check" | ||
+ | This is separated from %build so that people can skip the self-test if they desire. | ||
- | %install: Script commands to " | + | %install: Script commands to " |
+ | The commands should copy the files from the BUILD directory %{_builddir} into the buildroot directory, | ||
+ | %{buildroot}. See the %install section below for more. | ||
- | %clean: Instructions to clean out the build root. Note that this section is now redundant in Fedora and is only necessary for EPEL. Typically this contains only: | + | %clean: Instructions to clean out the build root. Note that this section is now redundant in Fedora and is only necessary for EPEL. |
+ | Typically this contains only: | ||
rm -rf %{buildroot} | rm -rf %{buildroot} | ||
Line 415: | Line 471: | ||
Do not create a " | Do not create a " | ||
</ | </ | ||
+ | |||
+ | ==== SPEC file sections explained ==== | ||
+ | |||
+ | <code text> | ||
+ | %prep section | ||
+ | The %prep section describes how to unpack the compressed packages so that they can be built. | ||
+ | Typically, this includes the " | ||
+ | (and Source1 etc.) lines. See the Maximum RPM section on %setup and %patch for more details. | ||
+ | |||
+ | The %{patches} and %{sources} macros are available since RPM 4.4.2 and are useful | ||
+ | if you have a large list of patches or sources: | ||
+ | |||
+ | for p in %{patches}; do | ||
+ | ... | ||
+ | done | ||
+ | However, keep in mind that using these will make your SPEC incompatible with RPMS | ||
+ | used in RHEL and other RPM-based dirstributions. | ||
+ | |||
+ | %prep section: %setup command | ||
+ | The " | ||
+ | |||
+ | -q : Suppress unecessary output. This is commonly used. | ||
+ | |||
+ | -n name : If the Source tarball unpacks into a directory whose name is not the RPM name, | ||
+ | |||
+ | this switch can be used to specify the correct directory name. For example, | ||
+ | if the tarball unpacks into the directory FOO, use " | ||
+ | |||
+ | -c name : If the Source tarball unpacks into multiple directories instead of a single directory, | ||
+ | this switch can be used to create a directory named name and then unpack into it. | ||
+ | There are more %spec options if you are unpacking multiple files, | ||
+ | which is primarily useful if you are creating subpackages (see below). The key ones are: | ||
+ | |||
+ | -a number Only unpack the Source directive of the given number after changing directory | ||
+ | (e.g. "–a 0" for Source0). | ||
+ | -b number Only unpack the Source directive of the given number before changing directory | ||
+ | (e.g. "–b 0" for Source0). | ||
+ | -D Do not delete the directory before unpacking. | ||
+ | -T Disable the automatic unpacking of the archives. | ||
+ | |||
+ | %prep section: %patch commands | ||
+ | The " | ||
+ | Patches are the normal method of making necessary changes to the source code for packaging. | ||
+ | The usual " | ||
+ | |||
+ | Patch file names often look like " | ||
+ | which is the format %{name} - %{version} - REASON.patch" | ||
+ | Patch files are typically the result of "diff -u"; | ||
+ | if you do this from the subdirectory of ~/ | ||
+ | |||
+ | This is a typical procedure for creating a patch for a single file: | ||
+ | |||
+ | cp foo/bar foo/ | ||
+ | vim foo/bar | ||
+ | diff -u foo/ | ||
+ | If editing many files, one easy method is to copy the | ||
+ | whole subdirectory underneath BUILD and then do subdirectory diffs. | ||
+ | After you have changed directory to " | ||
+ | |||
+ | cp -pr ./ ../ | ||
+ | ... many edits ... | ||
+ | diff -u ../ | ||
+ | If you edit many files in one patch, you can also copy the original files | ||
+ | using some consistent ending such as " | ||
+ | Then, you can use " | ||
+ | |||
+ | Try to ensure that your patch match the context exactly. | ||
+ | The default " | ||
+ | You can work around this by adding " | ||
+ | to revert to the value found in older versions of RPM in Fedora, | ||
+ | but it is generally recommended to avoid doing this. | ||
+ | |||
+ | As explained in Packaging/ | ||
+ | all patches should have a comment above them in the SPEC file about their upstream status. | ||
+ | This should document the upstream bug/email that includes it (including the date). | ||
+ | If it is unique to Fedora, you should mention why it is unique. | ||
+ | The Fedora Project tries not to deviate from upstream; | ||
+ | see PackageMaintainers/ | ||
+ | |||
+ | %prep section: Unmodified files | ||
+ | Sometimes, one or more of the Source files do not need to be uncompressed. | ||
+ | You can " | ||
+ | |||
+ | cp -p %SOURCE1 . | ||
+ | | ||
+ | The " | ||
+ | here you configure and compile/ | ||
+ | |||
+ | Many programs follow the GNU configure approach (or some variation). | ||
+ | By default, they will install to a prefix of "/ | ||
+ | However, since you are packaging it, change the prefix to "/ | ||
+ | Libraries should be installed to either /usr/lib or /usr/lib64 depending on the architecture. | ||
+ | |||
+ | Since GNU configure is so common, the macro " | ||
+ | invoke the correct options (e.g. change the prefix to /usr). Some variation of this often works: | ||
+ | |||
+ | | ||
+ | make %{? | ||
+ | To override makefile variables, pass them as parameters to make: | ||
+ | |||
+ | make %{? | ||
+ | More more information, | ||
+ | | ||
+ | "Open Source Development Tools: An Introduction to Make, Configure, Automake, Autoconf" | ||
+ | |||
+ | Some programs use cmake. See Packaging/ | ||
+ | |||
+ | | ||
+ | If self-tests are available, it is generally a good idea to include them. | ||
+ | They should be placed in the %check section (which immediately follows the %build section) | ||
+ | instead of within the %build section itself, so that they can be easily skipped when necessary. | ||
+ | |||
+ | Often, this section contains: | ||
+ | |||
+ | make test | ||
+ | | ||
+ | This section involves script commands to " | ||
+ | copying the relevant files from %{_builddir} to %{buildroot} | ||
+ | (which usually means from ~/ | ||
+ | and creating directories inside %{buildroot} as necessary. | ||
+ | |||
+ | Some of the terminology can be misleading: | ||
+ | |||
+ | The "build directory", | ||
+ | also known as %{buildroot}. Compilation occurs in the former directory, | ||
+ | while files to be packaged are copied from the former to the latter. | ||
+ | |||
+ | During the %build section, the current directory will start at %{buildsubdir}, | ||
+ | which is the subdirectory within %{_builddir} that was created during %prep stage. | ||
+ | This is usually something like ~/ | ||
+ | The %install section is not run when the binary RPM package is installed by the end-user, | ||
+ | but is only run when creating a package. | ||
+ | Normally, some variation of "make install" | ||
+ | |||
+ | %install | ||
+ | rm -rf %{buildroot} | ||
+ | make DESTDIR=%{buildroot} install | ||
+ | Removal of %{buildroot} is no longer necessary, except for EPEL 5. | ||
+ | |||
+ | Ideally you should use DESTDIR=%{buildroot} if the program supports it, | ||
+ | as it redirects file installations to the specified directory and is exactly | ||
+ | what we want to happen during the %install section. | ||
+ | |||
+ | If the program does not support DESTDIR (and only if), | ||
+ | you can workaround it in one of several (inferior) ways: | ||
+ | |||
+ | Patch the makefile so that is supports DESTDIR. | ||
+ | Create directories inside DESTDIR where necessary and submit the patch upstream. | ||
+ | |||
+ | Use the " | ||
+ | It expands to something like | ||
+ | "make prefix=%{buildroot}%{_prefix} bindir=%{buildroot}%{_bindir} ... install", | ||
+ | which can result in some programs failing to work properly. | ||
+ | Create directories inside %{buildroot} where necessary. | ||
+ | |||
+ | Consider using the auto-destdir package. This requires | ||
+ | " | ||
+ | This only works well if the installation uses only certain common commands to install files, | ||
+ | like cp and install. | ||
+ | |||
+ | Perform the installation by hand. This would involve creating the necessary directories under | ||
+ | %{buildroot} and copying files from %{_builddir} to %{buildroot}. | ||
+ | Be especially careful with updates, which often contain new or changed filenames. | ||
+ | An example of this procedure: | ||
+ | |||
+ | %install | ||
+ | rm -rf %{buildroot} | ||
+ | mkdir -p %{buildroot}%{_bindir}/ | ||
+ | cp -p mycommand %{buildroot}%{_bindir}/ | ||
+ | As noted in Packaging: | ||
+ | try to preserve timestamps if the makefile lets you override commands: | ||
+ | |||
+ | make INSTALL=" | ||
+ | |||
+ | | ||
+ | This section declares which files and directories are owned by the package, | ||
+ | and thus which files and directories will be placed into the binary RPM. | ||
+ | |||
+ | | ||
+ | The %defattr set the default file permissions, | ||
+ | Note that this is no longer necessary unless the permissions need to be altered. The format of this is: | ||
+ | |||
+ | %defattr(< | ||
+ | The fourth parameter is often omitted. | ||
+ | Usually one uses %defattr(-, | ||
+ | |||
+ | You should then list all the files and directories to be owned by the package. | ||
+ | Use macros for directory names where possible, | ||
+ | which can be viewed at Packaging: | ||
+ | If the pattern begins with a "/" | ||
+ | then it is taken from the %{buildroot} directory. Otherwise, | ||
+ | the file is presumed to be in the current directory (e.g. inside %{_builddir} | ||
+ | (such as documentation files that you wish to include). | ||
+ | If your package only installs a single file / | ||
+ | then the %files section can simply be: | ||
+ | |||
+ | %files | ||
+ | %{_sbindir}/ | ||
+ | To make your package less sensitive to upstream changes, | ||
+ | declare all files within a directory to be owned by the package with a pattern match: | ||
+ | |||
+ | %{_bindir}/ | ||
+ | To include a single directory: | ||
+ | |||
+ | %{_datadir}/ | ||
+ | Note that %{_bindir}/ | ||
+ | but only the files contained within. If you list a directory, | ||
+ | then you are claiming that the package owns that directory and | ||
+ | all files and subdirectories contained within. Thus, do not list %{_bindir} and | ||
+ | be careful of directories that may be shared with other packages. | ||
+ | |||
+ | An error will occur if: | ||
+ | |||
+ | a pattern match does not match any file or directory | ||
+ | a file or directory is listed or matched more than once | ||
+ | a file or directory in the %{buildroot} has not been listed | ||
+ | It is also possible to exclude files from a previous match by using the %exclude glob. | ||
+ | This can be useful for including almost all of the files included by a different pattern match, | ||
+ | but note that it will also fail if it does not match anything. | ||
+ | |||
+ | | ||
+ | You may need to add one or more prefixes to lines in the %files section; | ||
+ | seperate them with a space. See Max RPM section on %files directives. | ||
+ | |||
+ | Usually, " | ||
+ | %{_builddir} that were not copied to %{buildroot}. | ||
+ | A README and INSTALL file is usually included. | ||
+ | They will be placed in the directory / | ||
+ | whose ownership does not need to be declared. | ||
+ | |||
+ | Note: If specifying a %doc entry, | ||
+ | then you can't copy files into the documentation directory during the %install section. | ||
+ | If, for example, you want an " | ||
+ | don't use %doc, but instead create the directories and copy files over manually | ||
+ | into %{buildroot}%{_defaultdocdir}/ | ||
+ | They will be correctly marked as documentation. | ||
+ | Make sure you include %{_defaultdocdir}/ | ||
+ | |||
+ | Configuration files should be placed in /etc and are normally specified like this | ||
+ | (which makes sure user changes aren't overwritten on update): | ||
+ | |||
+ | %config(noreplace) %{_sysconfdir}/ | ||
+ | If the update uses a non-backwards-compatible configuration format, then specify them like this: | ||
+ | |||
+ | %config %{_sysconfdir}/ | ||
+ | " | ||
+ | where a " | ||
+ | |||
+ | %attr(0644, root, root) FOO.BAR | ||
+ | If a file is in particular natural language, use %lang to note that: | ||
+ | |||
+ | %lang(de) %{_datadir}/ | ||
+ | Programs using Locale files should follow the recommended method of handling i18n files: | ||
+ | |||
+ | find the filenames in the %install step: %find_lang ${name} | ||
+ | add the required build dependencies: | ||
+ | use the found filenames: %files -f ${name}.lang | ||
+ | These prefixes are not valid in Fedora: %license and %readme. | ||
+ | |||
+ | | ||
+ | You should follow the Filesystem Hierarchy Standard (FHS). | ||
+ | Executables go in /usr/bin, global configuration files go in /etc, | ||
+ | libraries go into /usr/lib (or /usr/lib64) and so on. | ||
+ | There is one exception: executables that should not normally be executed | ||
+ | directly by users or administrators should go in a subdirectory of / | ||
+ | which is referred to as %{_libexecdir}/ | ||
+ | |||
+ | Do not install files into /opt or /usr/local. | ||
+ | |||
+ | Unfortunately, | ||
+ | In particular, architecture-independent libraries get placed in /usr/lib instead of /usr/share. | ||
+ | The former is for architecture-dependent libraries, | ||
+ | while the latter is for architecture-independent libraries, | ||
+ | which means that systems with different CPU architectures can share /usr/share. | ||
+ | There are many exceptions in Fedora (such as Python and Perl), | ||
+ | but Fedora applies this rule more strictly than some distributions. | ||
+ | rpmlint will generally complain if you put anything other than ELF files into /usr/lib. | ||
+ | |||
+ | | ||
+ | Here's a simple example of a %files section: | ||
+ | |||
+ | %files | ||
+ | %doc README LICENSE | ||
+ | %{_bindir}/ | ||
+ | %{_sbindir}/ | ||
+ | %{_datadir}/ | ||
+ | %config(noreplace) %{_sysconfdir}/ | ||
+ | Finding duplicates | ||
+ | You can list any duplicates of two binary packages by doing: | ||
+ | |||
+ | cd ~/ | ||
+ | rpm -qlp PACKAGE1.*.rpm | sort > ,1 | ||
+ | rpm -qlp PACKAGE2.*.rpm | sort > ,2 | ||
+ | comm -12 ,1 ,2 | ||
+ | Scriptlets | ||
+ | When an end-user installs the RPM, you may want some commands to be run. | ||
+ | This can be achieved through scriptlets. See Packaging/ | ||
+ | |||
+ | Scriptlets can be run: | ||
+ | |||
+ | before (%pre) or after (%post) a package is installed | ||
+ | before (%preun) or after (%postun) a package is uninstalled | ||
+ | at the start (%pretrans) or end (%posttrans) of a transaction | ||
+ | For example, every binary RPM package that stores shared library files | ||
+ | in any of the dynamic linker' | ||
+ | If the package has multiple subpackages with libraries, | ||
+ | each subpackage should also perform the same actions. | ||
+ | |||
+ | %post -p / | ||
+ | %postun -p / | ||
+ | If only running a single command, then the " | ||
+ | command without invoking the shell. However, for several commands, | ||
+ | omit this option and include the shell commands beneath. | ||
+ | |||
+ | If you run any programs within the scriptlets, then you must specify any | ||
+ | requirements in the form " | ||
+ | |||
+ | %pre, %post, %preun, and %postun provide the argument $1, | ||
+ | which is the number of packages of this name which will be left on the system | ||
+ | when the action completes. Don't compare for equality with 2, | ||
+ | but instead check if they are greater than or equal to 2. | ||
+ | For %pretrans and %posttrans, $1 is always 0. | ||
+ | |||
+ | For example, if the package installs an info manual, | ||
+ | then the info manual index must be updated with install-info from the info package. | ||
+ | Firstly, there is no guarantee that the info package will be available unless | ||
+ | we explicitly declare it as required, and secondly, | ||
+ | we don't want to fail completely if install-info fails: | ||
+ | |||
+ | Requires(post): | ||
+ | Requires(preun): | ||
+ | ... | ||
+ | %post | ||
+ | / | ||
+ | %preun | ||
+ | if [ $1 = 0 ] ; then | ||
+ | / | ||
+ | fi | ||
+ | There is one other glitch related to installing info manuals. | ||
+ | The install-info command will update the info directory, | ||
+ | so we should delete the useless empty directory from the %{buildroot} during the %install section: | ||
+ | |||
+ | rm -f %{buildroot}%{_infodir}/ | ||
+ | Another scriptlet-like abilility are " | ||
+ | which can be run for your package when other packages are installed or uninstalled. | ||
+ | See RPM Triggers. | ||
+ | |||
+ | Macros | ||
+ | Macros are text in the format %{string}. Typical macros: | ||
+ | </ | ||
+ | |||
+ | |||
+ | ^ Macro ^ Typical Expansion ^ Meaning ^ | ||
+ | | %{_bindir} | /usr/bin | Binary directory: where executables are usually stored. | | ||
+ | | %{_builddir} | ~/ | ||
+ | | %{buildroot} | ~/ | ||
+ | | %{buildsubdir} | %{_builddir}/ | ||
+ | | %{_datadir} | /usr/share | Share directory. | | ||
+ | | %{_defaultdocdir} | / | ||
+ | | %{dist} | .fcNUMBER | Distribution+version short name (e.g. " | ||
+ | | %{fedora} | NUMBER | Number of fedora release (e.g. " | ||
+ | | %{_includedir} | / | ||
+ | | %{_infodir} | / | ||
+ | | %{_initrddir} | / | ||
+ | | %{_libdir} | /usr/lib | | | ||
+ | | %{_libexecdir} | / | ||
+ | | %{_localstatedir} | /var | | | ||
+ | | %{_mandir} | / | ||
+ | | %{name} | | Name of package, set by Name: tag | | ||
+ | | %{_sbindir} | /usr/sbin | | | ||
+ | | %{_sharedstatedir} | /var/lib | | | ||
+ | | %{_sysconfdir} | /etc | | | ||
+ | | %{version} | | Version of package, set by Version: tag | | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | <code text> | ||
+ | Learn more about macros by looking in /etc/rpm/* and / | ||
+ | Also use rpm --showrc to show values that RPM will use for macros (altered by rpmrc and macro configuration files). | ||
+ | |||
+ | You can set your own macro values using %global, | ||
+ | but be sure to define them before you use them. | ||
+ | (Macro definitions can also refer to other macros.) For example: | ||
+ | |||
+ | %global date 2012-02-08 | ||
+ | Use the " | ||
+ | |||
+ | rpmbuild -E ' | ||
+ | Also see Packaging/ | ||
+ | </ | ||
+ | |||
+ | ==== Custom Built RPM ==== | ||
+ | |||
+ | [[http:// |
rpm.1334255690.txt.gz · Last modified: 2020/08/10 02:29 (external edit)