Differences
This shows you the differences between two versions of the page.
linux_wiki:rpm_building [2015/10/23 16:43] billdozor [Mock to Test Dependencies] |
linux_wiki:rpm_building [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== RPM Building ====== | ||
- | **General Information** | ||
- | |||
- | How to create RPM packages from source files. | ||
- | |||
- | **Checklist** | ||
- | * Distro: Enterprise Linux 6.x | ||
- | |||
- | ---- | ||
- | |||
- | ====== Setup Build Environment ====== | ||
- | |||
- | * Add the [[linux_wiki: | ||
- | |||
- | * Install packages | ||
- | <code bash> | ||
- | yum install rpm-build rpmdevtools gcc make | ||
- | </ | ||
- | |||
- | * Create a user that will build rpms (regular user) | ||
- | <code bash> | ||
- | useradd builder | ||
- | passwd builder | ||
- | </ | ||
- | |||
- | * Login as user, create rpm build tree | ||
- | <code bash> | ||
- | su - builder | ||
- | rpmdev-setuptree | ||
- | </ | ||
- | * This creates a tree structure like: ~/rpmbuild/ | ||
- | * BUILD | ||
- | * RPMS | ||
- | * SOURCES | ||
- | * SPECS | ||
- | * SRPMS | ||
- | |||
- | ---- | ||
- | |||
- | ====== Source Files ====== | ||
- | |||
- | The source files are copied into ~/ | ||
- | |||
- | ===== Source Example: Custom Scripts ===== | ||
- | |||
- | Follow the " | ||
- | |||
- | Create your directory structure: | ||
- | <code bash> | ||
- | mkdir -p ~/ | ||
- | </ | ||
- | * Note: Everything under " | ||
- | |||
- | Copy scripts into the directory | ||
- | <code bash> | ||
- | cp ~/ | ||
- | </ | ||
- | |||
- | Create " | ||
- | <code bash> | ||
- | tar -czvf ~/ | ||
- | </ | ||
- | |||
- | Copy source archive to rpmbuild/ | ||
- | <code bash> | ||
- | cp ~/ | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Source Example: Xymon ===== | ||
- | |||
- | Follow the " | ||
- | |||
- | Download source files, place a copy in rpmbuild' | ||
- | * Download the Xymon tar file | ||
- | * <code bash> | ||
- | * Extract | ||
- | * <code bash>tar -zxvf xymon-4.3.21.tar.gz</ | ||
- | * Copy the original tar file into rpmbuild' | ||
- | * <code bash>cp ~/ | ||
- | * Copy all files but " | ||
- | * <code bash>cp ~/ | ||
- | cp ~/ | ||
- | cp ~/ | ||
- | * NOTE: All of the above files were copied into the SOURCES directory due to the spec file listing them all in the SOURCES section. | ||
- | |||
- | ---- | ||
- | |||
- | ====== SPEC File ====== | ||
- | |||
- | The spec (specification) file tells rpmbuild how the packages will be built. | ||
- | |||
- | The sections of a spec file are: | ||
- | * Preamble => Contains name, version, release, summary, group, license, url, vendor, source, prefix, packager, and buildroot information. | ||
- | * description => Longer description of the application. | ||
- | * prep => applies any patches from the source directory into a sub build directory. Previous build files are removed to ensure a new clean build. | ||
- | * build => compiles files underneath the build directory (./ | ||
- | * install => reads files under the build directory and writes them to the build root directory (make install) | ||
- | * files => contains a list of files that are part of the package. Only files listed will be included in the package. File permissions and ownership are set here too. | ||
- | * clean => removes files from the build root directory that are not needed anymore. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Spec File Default Template ===== | ||
- | |||
- | Vim creates a template for a spec file any time a file is created with a " | ||
- | <code bash> | ||
- | vim myapp.spec | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Spec Example: Custom Scripts ===== | ||
- | |||
- | This simplified package is to distribute custom scripts via a RPM. | ||
- | |||
- | Create spec file: vim ~/ | ||
- | <code bash> | ||
- | # Package information | ||
- | Name: myscripts | ||
- | Version: 1.0.0 | ||
- | Release: 1%{?dist} | ||
- | Summary: My Custom Scripts | ||
- | License: GPL+ | ||
- | URL: www.mysite.com | ||
- | SOURCE0: %{name}-%{version}.tar.gz | ||
- | |||
- | %description | ||
- | These are my custom scripts used for fun things. | ||
- | |||
- | # Don't create debug package | ||
- | %define | ||
- | |||
- | # prep => remove previous build and extract source file (.tar.gz) to the builddir | ||
- | %prep | ||
- | %setup -q | ||
- | |||
- | # build => ./configure && make files in builddir; No building for shell scripts required | ||
- | %build | ||
- | |||
- | # install => make install ; read files from builddir, write to buildrootdir. | ||
- | # Nothing to make install, so do a manual clean, mkdir, and copy. | ||
- | %install | ||
- | rm -rf %{buildroot} | ||
- | mkdir -p %{buildroot} | ||
- | cp -a * %{buildroot} | ||
- | |||
- | # files => set file permissions, | ||
- | # %attr(< | ||
- | %files | ||
- | %attr(755, root, root) / | ||
- | |||
- | # changelog => RPM itself, not software' | ||
- | %changelog | ||
- | * Thu Oct 22 2015 Robert Jones < | ||
- | - Initial custom scripts packaging | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Spec Example: Xymon ===== | ||
- | |||
- | This spec file is from Xymon' | ||
- | |||
- | \\ | ||
- | Copy xymon.spec into SPECS | ||
- | <code bash> | ||
- | cp ~/ | ||
- | </ | ||
- | |||
- | \\ | ||
- | Modify the spec file so the version section works correctly: | ||
- | <code bash> | ||
- | vim ~/ | ||
- | |||
- | Version: 4.3.21 | ||
- | |||
- | Source: xymon-%version.tar.gz | ||
- | </ | ||
- | |||
- | \\ | ||
- | Original Xymon spec file before mods above | ||
- | <code bash> | ||
- | Name: xymon | ||
- | Version: @VER@ | ||
- | Release: 1 | ||
- | Group: Networking/ | ||
- | URL: http:// | ||
- | License: GPL | ||
- | Source: xymon-@VER@.tar.gz | ||
- | Source1: xymon-init.d | ||
- | Source2: xymon.logrotate | ||
- | Source3: xymon-client.init | ||
- | Source4: xymon-client.default | ||
- | Summary: Xymon network monitor | ||
- | BuildRoot: / | ||
- | # | ||
- | # | ||
- | # | ||
- | # | ||
- | Conflicts: xymon-client | ||
- | |||
- | %description | ||
- | Xymon (previously known as Hobbit) is a system for monitoring | ||
- | your network servers and applications. This package contains | ||
- | the server side of the Xymon package. | ||
- | |||
- | %package client | ||
- | Summary: Xymon client reporting data to the Xymon server | ||
- | Group: Applications/ | ||
- | Conflicts: xymon | ||
- | |||
- | %description client | ||
- | This package contains a client for the Xymon (previously known | ||
- | as Hobbit) monitor. Clients report data about the local system to | ||
- | the monitor, allowing it to check on the status of the system | ||
- | load, filesystem utilisation, | ||
- | |||
- | %prep | ||
- | rm -rf $RPM_BUILD_ROOT | ||
- | |||
- | %setup | ||
- | USEXYMONPING=y \ | ||
- | ENABLESSL=y \ | ||
- | ENABLELDAP=y \ | ||
- | ENABLELDAPSSL=y \ | ||
- | XYMONUSER=xymon \ | ||
- | XYMONTOPDIR=/ | ||
- | XYMONVAR=/ | ||
- | XYMONHOSTURL=/ | ||
- | CGIDIR=/ | ||
- | XYMONCGIURL=/ | ||
- | SECURECGIDIR=/ | ||
- | SECUREXYMONCGIURL=/ | ||
- | HTTPDGID=apache \ | ||
- | XYMONLOGDIR=/ | ||
- | XYMONHOSTNAME=localhost \ | ||
- | XYMONHOSTIP=127.0.0.1 \ | ||
- | MANROOT=/ | ||
- | INSTALLBINDIR=/ | ||
- | INSTALLETCDIR=/ | ||
- | INSTALLWEBDIR=/ | ||
- | INSTALLEXTDIR=/ | ||
- | INSTALLTMPDIR=/ | ||
- | INSTALLWWWDIR=/ | ||
- | ./configure | ||
- | |||
- | %build | ||
- | PKGBUILD=1 make | ||
- | |||
- | %install | ||
- | INSTALLROOT=$RPM_BUILD_ROOT PKGBUILD=1 make install | ||
- | mkdir -p $RPM_BUILD_ROOT/ | ||
- | cp %{SOURCE1} $RPM_BUILD_ROOT/ | ||
- | cp %{SOURCE3} $RPM_BUILD_ROOT/ | ||
- | mkdir -p $RPM_BUILD_ROOT/ | ||
- | cp %{SOURCE2} $RPM_BUILD_ROOT/ | ||
- | mkdir -p $RPM_BUILD_ROOT/ | ||
- | cp %{SOURCE4} $RPM_BUILD_ROOT/ | ||
- | mkdir -p $RPM_BUILD_ROOT/ | ||
- | cd $RPM_BUILD_ROOT/ | ||
- | mkdir -p $RPM_BUILD_ROOT/ | ||
- | mv $RPM_BUILD_ROOT/ | ||
- | rmdir $RPM_BUILD_ROOT/ | ||
- | cd $RPM_BUILD_ROOT/ | ||
- | rmdir $RPM_BUILD_ROOT/ | ||
- | cd $RPM_BUILD_ROOT/ | ||
- | mv $RPM_BUILD_ROOT/ | ||
- | cat / | ||
- | rm / | ||
- | |||
- | %clean | ||
- | rm -rf $RPM_BUILD_ROOT | ||
- | |||
- | |||
- | %pre | ||
- | id xymon 1>/ | ||
- | if [ $? -ne 0 ] | ||
- | then | ||
- | | ||
- | | ||
- | fi | ||
- | if [ -e / | ||
- | then | ||
- | / | ||
- | fi | ||
- | |||
- | %pre client | ||
- | id xymon 1>/ | ||
- | if [ $? -ne 0 ] | ||
- | then | ||
- | | ||
- | | ||
- | fi | ||
- | if [ -e / | ||
- | then | ||
- | / | ||
- | fi | ||
- | |||
- | |||
- | %post | ||
- | chkconfig --add xymon | ||
- | |||
- | %post client | ||
- | chkconfig --add xymon-client | ||
- | |||
- | |||
- | %preun | ||
- | if [ -e / | ||
- | then | ||
- | / | ||
- | fi | ||
- | chkconfig --del xymon | ||
- | |||
- | %preun client | ||
- | if [ -e / | ||
- | then | ||
- | / | ||
- | fi | ||
- | chkconfig --del xymon-client | ||
- | |||
- | |||
- | %files | ||
- | %attr(-, root, root) %doc README README.CLIENT Changes* COPYING CREDITS RELEASENOTES | ||
- | %attr(644, root, root) %doc / | ||
- | %attr(644, root, root) %config / | ||
- | %attr(644, root, root) %config / | ||
- | %attr(755, root, root) %dir /etc/xymon | ||
- | %attr(755, root, root) %dir / | ||
- | %attr(755, root, root) %dir / | ||
- | %attr(755, root, root) %dir / | ||
- | %attr(755, xymon, xymon) %dir / | ||
- | %attr(755, root, root) / | ||
- | %attr(644, root, root) / | ||
- | %attr(-, root, root) / | ||
- | %attr(-, root, root) /usr/bin/* | ||
- | %attr(-, xymon, xymon) / | ||
- | %attr(775, xymon, apache) %dir / | ||
- | %attr(775, xymon, apache) %dir / | ||
- | %attr(644, root, root) %config / | ||
- | %attr(644, root, root) %config / | ||
- | %attr(755, xymon, xymon) %dir / | ||
- | %attr(664, xymon, apache) %config / | ||
- | %attr(664, xymon, apache) %config / | ||
- | %attr(4750, root, xymon) / | ||
- | %attr(750, root, xymon) / | ||
- | %attr(750, root, xymon) / | ||
- | |||
- | %files client | ||
- | %attr(-, root, root) %doc README README.CLIENT Changes* COPYING CREDITS RELEASENOTES | ||
- | %attr(-, root, root) / | ||
- | %attr(755, root, root) / | ||
- | %attr(644, root, root) %config / | ||
- | %attr(755, xymon, xymon) %dir / | ||
- | %attr(755, xymon, xymon) %dir / | ||
- | %attr(750, root, xymon) / | ||
- | %attr(750, root, xymon) / | ||
- | |||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ====== Build The Package ====== | ||
- | |||
- | RPM Build Command | ||
- | <code bash> | ||
- | rpmbuild -ba ~/ | ||
- | </ | ||
- | |||
- | Common Build Methods: | ||
- | * -ba => build binary and source packages | ||
- | * -bb => build binary package only | ||
- | * -bl => check to ensure all file exist that are listed in the spec's " | ||
- | * -bs => build source package only | ||
- | |||
- | ---- | ||
- | |||
- | ===== Build Example: Custom Scripts ===== | ||
- | |||
- | Build the custom scripts RPM | ||
- | <code bash> | ||
- | rpmbuild -ba ~/ | ||
- | </ | ||
- | |||
- | RPMs written to: | ||
- | <code bash> | ||
- | ~/ | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Build Example: Xymon ===== | ||
- | |||
- | Optional: Edit client config file to point to an existing Xymon Server (10.0.0.1 in example) | ||
- | <code bash> | ||
- | vim ~/ | ||
- | |||
- | XYMONSERVERS=" | ||
- | </ | ||
- | |||
- | Build the RPMs | ||
- | <code bash> | ||
- | rpmbuild -ba ~/ | ||
- | </ | ||
- | |||
- | Xymon Server and Client RPMs are written to: | ||
- | <code bash> | ||
- | ~/ | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ====== Mock to Test Dependencies ====== | ||
- | |||
- | Mock is used to rebuild binary RPMs from source RPMs in a clean environment to ensure you are not missing any dependencies in your SPEC file. | ||
- | |||
- | Install mock | ||
- | <code bash>yum install mock</ | ||
- | |||
- | Add user to the mock group | ||
- | <code bash> | ||
- | |||
- | Set default mock config of the type of repos you are building for (ie EPEL 6, Fedora 23, etc) | ||
- | |||
- | Example: Set default config to EPEL 6 x86_64 | ||
- | <code bash> | ||
- | cd /etc/mock | ||
- | ln -sf epel-6-x86_64.cfg default.cfg | ||
- | </ | ||
- | |||
- | Go to where your source RPMs were built and run mock against that package | ||
- | <code bash> | ||
- | cd ~/ | ||
- | mock --rebuild myscripts-1.0.0-1.el6.src.rpm | ||
- | </ | ||
- | |||
- | ---- |