Oracle 8i | Oracle 9i | Oracle 10g | Oracle 11g | Oracle 12c | Miscellaneous | PL/SQL | SQL | Oracle RAC | Oracle Apps | Linux

Build Simple Linux RPM Packages

This article describes how to build simple RPM packages for Linux, with specific reference to the information needed for the RHCE EX300 certification exam.

Remember, the exams are hands-on, so it doesn't matter which method you use to achieve the result, so long as the end product is correct.

Related articles.

Installation

Perform the following installation from a Yum repository.

# yum install rpmdevtools

Create a user to perform the builds.

# useradd rpmbuilder
# passwd rpmbuilder

Log in as this user to perform the subsequent actions.

# su - rpmbuilder
$

Create RPM Package

Create a directory tree for the package.

$ rpmdev-setuptree
$ ls
rpmbuild
$ cd rpmbuild
$ ls
BUILD  RPMS  SOURCES  SPECS  SRPMS
$

Create a test file in the package.

$ mkdir mytest-1.0
$ echo "echo \"This is a test\"" > mytest-1.0/mytest.sh
$ tar -czvf SOURCES/mytest-1.0.tar.gz mytest-1.0/
mytest-1.0/
mytest-1.0/mytest.sh
$

Create a spec file.

$ rpmdev-newspec SPECS/mytest.spec
Skeleton specfile (minimal) has been created to "SPECS/mytest.spec".
$

Edit the spec file. Any entries you are not planning to use should be commented out. The edited spec file for this RPM is shown below.

Name:           mytest
Version:        1.0
Release:        1%{?dist}
Summary:        A test script

Group:          Utilities
License:        GPL
URL:            http://oracle-base.com/articles/linux/linux-build-simple-rpm-packages.php
Source0:        mytest-1.0.tar.gz
BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)


#BuildRequires: 
#Requires:      

%description
A test script inside a simple RPM package


%prep
%setup -q


%build


%install
rm -rf $RPM_BUILD_ROOT
install -d $RPM_BUILD_ROOT/opt/mytest
install mytest.sh $RPM_BUILD_ROOT/opt/mytest/mytest.sh


%clean
rm -rf $RPM_BUILD_ROOT


%files
%dir /opt/mytest
%defattr(-,root,root,-)
/opt/mytest/mytest.sh

%post
chmod 755 -R /opt/mytest

Be careful how you comment out the "%" macros. The following example shows how the comments work.

# Normal macro. Not commented out.
%configure

# Badly commented out macro.
#%configure

# Properly commented out macro.
#%%configure

Build the package.

$ rpmbuild -bb -v SPECS/mytest.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.naRMPW
+ umask 022
+ cd /home/rpmbuilder/rpmbuild/BUILD
+ cd /home/rpmbuilder/rpmbuild/BUILD
+ rm -rf mytest-1.0
+ /bin/tar -xf -
+ /bin/gzip -dc /home/rpmbuilder/rpmbuild/SOURCES/mytest-1.0.tar.gz
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd mytest-1.0
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.Ws3V7p
+ umask 022
+ cd /home/rpmbuilder/rpmbuild/BUILD
+ cd mytest-1.0
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.w8wSCT
+ umask 022
+ cd /home/rpmbuilder/rpmbuild/BUILD
+ cd mytest-1.0
+ rm -rf /home/rpmbuilder/rpmbuild/BUILDROOT/mytest-1.0-1.el6.x86_64
+ install -d /home/rpmbuilder/rpmbuild/BUILDROOT/mytest-1.0-1.el6.x86_64/opt/mytest
+ install mytest.sh /home/rpmbuilder/rpmbuild/BUILDROOT/mytest-1.0-1.el6.x86_64/opt/mytest/mytest.sh
+ /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-strip
+ /usr/lib/rpm/brp-strip-static-archive
+ /usr/lib/rpm/brp-strip-comment-note
Processing files: mytest-1.0-1.el6.noarch
Requires(interp): /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(post): /bin/sh
Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/rpmbuilder/rpmbuild/BUILDROOT/mytest-1.0-1.el6.x86_64
Wrote: /home/rpmbuilder/rpmbuild/RPMS/noarch/mytest-1.0-1.el6.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.Rk3kLV
+ umask 022
+ cd /home/rpmbuilder/rpmbuild/BUILD
+ cd mytest-1.0
+ rm -rf /home/rpmbuilder/rpmbuild/BUILDROOT/mytest-1.0-1.el6.x86_64
+ exit 0
$

You can now see the completed RPM.

$ ls RPMS/noarch/*
RPMS/noarch/mytest-1.0-1.el6.noarch.rpm
$

Test It

You can now try installing the package as the "root" user.

# cd /home/rpmbuilder/rpmbuild/RPMS/noarch
# rpm -Uvh mytest-1.0-1.el6.noarch.rpm
Preparing...                ########################################### [100%]
   1:mytest                 ########################################### [100%]
#

We can see the file has been installed in the requested location.

# ls -al /opt/mytest/
total 12
drwxr-xr-x. 2 root root 4096 Jan 26 15:11 .
drwxr-xr-x. 4 root root 4096 Jan 26 15:11 ..
-rwxr-xr-x. 1 root root   22 Jan 26 15:02 mytest.sh
#

We can also run the script, as expected.

# /opt/mytest/mytest.sh
This is a test
#

For more information see:

Hope this helps. Regards Tim...

Back to the Top.