How to create or build RPM Package
Introduction –
* “rpmbuild” tool is used to build both…
1) Binary Package ~ used to install the software and supporting scripts. It contains the files that comprise the application, along with any additional information needed to install and erase it.
2) Source Package ~ contains the original compressed tar file of source code, patches and Specification File.
* What is RPM & RPM package Manager?
The RPM Package Manager (RPM) is a powerful command line package management system capable of installing, uninstalling, verifying, querying, and updating software packages.
RPM package consists of an archive of files and meta-data used to install and erase the archive files. The meta-data includes helper scripts, file attributes, and descriptive information about the package.
* To build RPM package you need to specify three things ~
1) Source of application – In any case, you should not modify the sources used in the package building process.
2) Patches – RPM gives you the ability to automatically apply patches to them. The patch addresses an issue specific to the target system. This could include changing makefiles to install the application into the appropriate directories, or resolving cross-platform conflicts. Patches create the environment required for proper compilation.
3) Specification File – The specification file is at the heart of RPM package building process. It contains information required by RPM to build the package, as well as instructions telling RPM how to build it. The specification file also dictates exactly what files are a part of the package, and where they should be installed.
** Specification File ~ is divided in to 8 sections as shown below
a) Preamble ~ contains information that will be displayed when users request information about the package. This would include a description of the package’s function, the version number of the software etc.
b) Preparation ~ where the actual work of building a package starts. As the name implies, this section is where the necessary preparations are made prior to the actual building of the software. In general, if anything needs to be done to the sources prior to building the software, it needs to happen in the preparation section. The contents of this section are an ordinary shell script. However, RPM does provide two macros to make life easier. One macro can unpack a compressed tar file and cd into the source directory. The other macro easily applies patches to the unpacked sources.
c) Build ~ This section consists of a shell script. It is used to perform whatever commands are required to actually compile the sources like single make command, or be more complex if the build process requires it. There are no macros available in this section.
d) Install ~ This section also containing a shell script, the install section is used to perform the commands required to actually install the software.
e) Install and Uninstall Scripts ~ It consists of scripts that will be run, on the user’s system, when the package is actually installed or removed. RPM can execute a script pre/post installation/removal of package.
f) Verify Script ~ script that is executed on the user’s system. It is executed when RPM verifies the package’s proper installation.
g) Clean Section ~ script that can clean things up after the build. This script is rarely used, since RPM normally does a good job of clean-up in most build environments.
h) File List ~ consists of a list of files that will comprise the package. Additionally, a number of macros can be used to control file attributes when installed, as well as to denote which files are documentation, and which contain configuration information. The file list is very important.
*** RPM’s requirement for build environment ~
A] RPM requires a set of directories to perform the build. While the directories’ locations and names can be changed. Default layout is shown below –
root@arunsb:~# ls -l /usr/src/redhat/
drwxr-xr-x 2 root root 4096 Aug 25 2007 SOURCES => Contains the original sources, patches, and icon files
drwxr-xr-x 2 root root 4096 Aug 25 2007 SPECS => Contains the specification files
drwxr-xr-x 2 root root 4096 Aug 25 2007 BUILD => Directory in which the sources are unpacked, & software is built
drwxr-xr-x 8 root root 4096 May 28 2008 RPMS => Contains the binary package files created by the build process
drwxr-xr-x 2 root root 4096 Aug 25 2007 SRPMS => Contains the source package files created by the build process
root@arunsb:~#
B] Need to export few global variables used by RPM –
root@arunsb:~# export RPM_BUILD_DIR=/usr/src/redhat/BUILD/
root@arunsb:~# export RPM_SOURCE_DIR=/usr/src/redhat/SOURCES/
Step 1] Create Specification (spec) File ~
root@arunsb:~# head -n 50 /usr/src/redhat/SPECS/openlsm.spec
# Authority: Arun Bagul
#RPM_BUILD_DIR /usr/src/redhat/BUILD/
#RPM_SOURCE_DIR /usr/src/redhat/SOURCES/
%define MY_PREFIX /usr/local/openlsm/
## Preamble Section-
Name: openlsm
Version: 0.99
Vendor: IndianGNU.org & openlsm
Release: r45
Group: System Environment/Daemons
Packager: IndianGNU.org (http://www.indiangnu.org)
URL: http://openlsm.sourceforge.net/
Summary: openlsm Admin Server
License: GPL
%description
openlsm Admin Server is free & open source web based control panel for Linux,Unix systems.
## Preparation Section-
%prep
rm -rf ${RPM_BUILD_DIR}/openlsm-0.99-r45/
tar xvfz ${RPM_SOURCE_DIR}/openlsm-0.99-r45.tar.gz -C ${RPM_BUILD_DIR}
## Build Section-
%build
cd ./openlsm-0.99-r45/
./configure –prefix=/usr/local/openlsm –with-mysql=/usr/bin/mysql_config –enable-internal-pcre –with-geoip=/usr –with-ldap=/usr –enable-trace
make
## Install Section-
%install
cd ./openlsm-0.99-r45/
make install
## Files Section-
%files
/usr/local/openlsm
/usr/local/openlsm/etc/openlsm/openlsm.conf
/usr/local/openlsm/etc/openlsm/openlsm.conf.perf_sample
/usr/local/openlsm/etc/openlsm/ssl/
/usr/local/openlsm/bin/openlsm-config
….
…..
….. list of files installed by pkg
root@arunsb:~#
* How do you create the File List?
Creating the file list is manual process. What I did is I took the file list from my manual installed prefix directory with find command as shown below…
root@arunsb:~# find /usr/local/openlsm/ -type f -or -type d
Step 2] Starting the Build ~
root@arunsb:~# cd /usr/src/redhat/SPECS
root@arunsb:/usr/src/redhat/SPECS# ls -l openlsm.spec
-rw-r–r– 1 root root 12938 Dec 2 17:21 openlsm.spec
root@arunsb:/usr/src/redhat/SPECS#
root@arunsb:/usr/src/redhat/SPECS# rpmbuild -ba openlsm.spec
…
….
…..
Checking for unpackaged file(s): /usr/lib/rpm/check-files %{buildroot}
Wrote: /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
Wrote: /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
root@arunsb:/usr/src/redhat/SPECS# echo $?
0
root@arunsb:/usr/src/redhat/SPECS# ls -l /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
-rw-r–r– 1 root root 3206 Dec 2 17:50 /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
root@arunsb:/usr/src/redhat/SPECS# ls -l /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
-rw-r–r– 1 root root 3052868 Dec 2 17:50 /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
root@arunsb:/usr/src/redhat/SPECS#
* Source and Binary package created !!
** Let’s see what happened in “/usr/src/redhat/” directory
root@arunsb:/usr/src/redhat# pwd
/usr/src/redhat
root@arunsb:/usr/src/redhat# ls
BUILD RPMS SOURCES SPECS SRPMS
root@arunsb:/usr/src/redhat# ls BUILD/
openlsm-0.99-r45 <== Source extracted here as part of build instructions from specification file ie “openlsm.spec”
root@arunsb:/usr/src/redhat# ls SOURCES/
openlsm-0.99-r45.tar.gz <== original ‘openlsm-0.99-r45.tar.gz’ source file copied by me
root@arunsb:/usr/src/redhat# ls RPMS/
athlon i386 i486 i586 i686 noarch
root@arunsb:/usr/src/redhat# ls RPMS/i386/
openlsm-0.99-r45.i386.rpm <== Binary rpm package created!
root@arunsb:/usr/src/redhat# ls SRPMS/
openlsm-0.99-r45.src.rpm <== Source rpm package created!
root@arunsb:/usr/src/redhat#
Step 3] Now install the package and test it ~
root@arunsb:/usr/src/redhat# cp RPMS/i386/openlsm-0.99-r45.i386.rpm /home/arunsb/
root@arunsb:/usr/src/redhat# cd /home/arunsb/
root@arunsb:~# ls
openlsm-0.99-r45.i386.rpm
root@arunsb:~# rpm -ivh openlsm-0.99-r45.i386.rpm
Preparing… ########################################### [100%]
1:openlsm ########################################### [100%]
root@arunsb:~# ls /usr/local/openlsm/
bin contrib etc include lib sbin scripts share var
root@arunsb:~#
** Starting the openlsm server ~
root@arunsb:~# /usr/local/openlsm/contrib/openlsm-redhat start
* Starting openlsm admin server: openlsm
. [ OK ]
root@arunsb:~#
root@arunsb:~# /usr/local/openlsm/contrib/openlsm-redhat status
openlsm (pid 21607) is running…
root@arunsb:~#
root@arunsb:~# rpm -q openlsm-0.99-r45
openlsm-0.99-r45
root@arunsb:~#
root@arunsb:~# rpm -ql openlsm-0.99-r45
..
…
root@arunsb:~# rpm -qiv openlsm-0.99-r45
Name : openlsm Relocations: (not relocatable)
Version : 0.99 Vendor: IndianGNU.org & openlsm
Release : r45 Build Date: Wed 02 Dec 2009 05:50:54 PM IST
Install Date: Wed 02 Dec 2009 06:06:23 PM IST Build Host: alongseveral-dr.eglbp.corp.yahoo.com
Group : System Environment/Daemons Source RPM: openlsm-0.99-r45.src.rpm
Size : 14877918 License: GPL
Signature : (none)
Packager : IndianGNU.org (http://www.indiangnu.org)
URL : http://openlsm.sourceforge.net/
Summary : openlsm Admin Server
Description :
openlsm Admin Server is free & open source web based control panel for Linux,Unix systems.
root@arunsb:~#
** NOTE ~ This article does not contain information on how to define micros,how to copy docs,man pages to default location, how to set permision and ownership etc. I will cover this topics in next article on RPM.
Regards,
Arun Bagul
|| How to create or build RPM Package ||
Introduction –
* “rpmbuild” tool is used to build both…
1) Binary Package ~ used to install the software and supporting scripts. It contains the files that comprise the application, along with any additional information needed to install and erase it.
2) Source Package ~ contains the original compressed tar file of source code, patches and Specification File.
* What is RPM & RPM package Manager?
The RPM Package Manager (RPM) is a powerful command line package management system capable of installing, uninstalling, verifying, querying, and updating software packages.
RPM package consists of an archive of files and meta-data used to install and erase the archive files. The meta-data includes helper scripts, file
attributes, and descriptive information about the package.
* To build RPM package you need to specify three things ~
1) Source of application – In any case, you should not modify the sources used in the package building process.
2) Patches – RPM gives you the ability to automatically apply patches to them. The patch addresses an issue specific to the target system. This could include changing makefiles to install the application into the appropriate directories, or resolving cross-platform conflicts. Patches create the environment required for proper compilation.
3) Specification File – The specification file is at the heart of RPM package building process. It contains information required by RPM to build the package, as well as instructions telling RPM how to build it. The specification file also dictates exactly what files are a part of the package, and where they should be installed.
** Specification File ~ is divided in to 8 sections as shown below
a) Preamble ~ contains information that will be displayed when users request information about the package. This would include a description of the package’s function, the version number of the software etc.
b) Preparation ~ where the actual work of building a package starts. As the name implies, this section is where the necessary preparations are made prior to the actual building of the software. In general, if anything needs to be done to the sources prior to building the software, it needs to happen in the preparation section. The contents of this section are an ordinary shell script. However, RPM does provide two macros to make life easier. One macro can unpack a compressed tar file and cd into the source directory. The other macro easily applies patches to the unpacked sources.
c) Build ~ This section consists of a shell script. It is used to perform whatever commands are required to actually compile the sources like single make command, or be more complex if the build process requires it. There are no macros available in this section.
d) Install ~ This section also containing a shell script, the install section is used to perform the commands required to actually install the software.
e) Install and Uninstall Scripts ~ It consists of scripts that will be run, on the user’s system, when the package is actually installed or removed. RPM can execute a script pre/post installation/removal of package.
f) Verify Script ~ script that is executed on the user’s system. It is executed when RPM verifies the package’s proper installation.
g) Clean Section ~ script that can clean things up after the build. This script is rarely used, since RPM normally does a good job of clean-up in most build environments.
h) File List ~ consists of a list of files that will comprise the package. Additionally, a number of macros can be used to control file attributes when installed, as well as to denote which files are documentation, and which contain configuration information. The file list is very important.
*** RPM’s requirement for build environment ~
A] RPM requires a set of directories to perform the build. While the directories’ locations and names can be changed. Default layout is shown below –
root@arunsb:~# ls -l /usr/src/redhat/
drwxr-xr-x 2 root root 4096 Aug 25 2007 SOURCES => Contains the original sources, patches, and icon files
drwxr-xr-x 2 root root 4096 Aug 25 2007 SPECS => Contains the specification files
drwxr-xr-x 2 root root 4096 Aug 25 2007 BUILD => Directory in which the sources are unpacked, and the software is built
drwxr-xr-x 8 root root 4096 May 28 2008 RPMS => Contains the binary package files created by the build process
drwxr-xr-x 2 root root 4096 Aug 25 2007 SRPMS => Contains the source package files created by the build process
root@arunsb:~#
B] Need to export few global variables used by RPM –
root@arunsb:~# export RPM_BUILD_DIR=/usr/src/redhat/BUILD/
root@arunsb:~# export RPM_SOURCE_DIR=/usr/src/redhat/SOURCES/
Step 1] Create Specification (spec) File ~
root@arunsb:~# head -n 50 /usr/src/redhat/SPECS/openlsm.spec
# Authority: Arun Bagul
#RPM_BUILD_DIR /usr/src/redhat/BUILD/
#RPM_SOURCE_DIR /usr/src/redhat/SOURCES/
%define MY_PREFIX /usr/local/openlsm/
## Preamble Section-
Name: openlsm
Version: 0.99
Vendor: IndianGNU.org & openlsm
Release: r45
Group: System Environment/Daemons
Packager: IndianGNU.org (http://www.indiangnu.org)
URL: http://openlsm.sourceforge.net/
Summary: openlsm Admin Server
License: GPL
%description
openlsm Admin Server is free & open source web based control panel for Linux,Unix systems.
## Preparation Section-
%prep
rm -rf ${RPM_BUILD_DIR}/openlsm-0.99-r45/
tar xvfz ${RPM_SOURCE_DIR}/openlsm-0.99-r45.tar.gz -C ${RPM_BUILD_DIR}
## Build Section-
%build
cd ./openlsm-0.99-r45/
./configure –prefix=/usr/local/openlsm –with-mysql=/usr/bin/mysql_config –enable-internal-pcre –with-geoip=/usr –with-ldap=/usr –enable-trace
make
## Install Section-
%install
cd ./openlsm-0.99-r45/
make install
## Files Section-
%files
/usr/local/openlsm
/usr/local/openlsm/etc/openlsm/openlsm.conf
/usr/local/openlsm/etc/openlsm/openlsm.conf.perf_sample
/usr/local/openlsm/etc/openlsm/ssl/
/usr/local/openlsm/bin/openlsm-config
….
…..
….. list of files installed by pkg
root@arunsb:~#
* How do you create the File List?
Creating the file list is manual process. What I did is I took the file list from my manual installed prefix directory with find command as shown below…
root@arunsb:~# find /usr/local/openlsm/ -type f -or -type d
Step 2] Starting the Build ~
root@arunsb:~# cd /usr/src/redhat/SPECS
root@arunsb:/usr/src/redhat/SPECS# ls -l openlsm.spec
-rw-r–r– 1 root root 12938 Dec 2 17:21 openlsm.spec
root@arunsb:/usr/src/redhat/SPECS#
root@arunsb:/usr/src/redhat/SPECS# rpmbuild -ba openlsm.spec
…
….
…..
Checking for unpackaged file(s): /usr/lib/rpm/check-files %{buildroot}
Wrote: /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
Wrote: /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
root@arunsb:/usr/src/redhat/SPECS# echo $?
0
root@arunsb:/usr/src/redhat/SPECS# ls -l /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
-rw-r–r– 1 root root 3206 Dec 2 17:50 /usr/src/redhat/SRPMS/openlsm-0.99-r45.src.rpm
root@arunsb:/usr/src/redhat/SPECS# ls -l /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
-rw-r–r– 1 root root 3052868 Dec 2 17:50 /usr/src/redhat/RPMS/i386/openlsm-0.99-r45.i386.rpm
root@arunsb:/usr/src/redhat/SPECS#
* Source and Binary package created !!
** Let’s see what happened in “/usr/src/redhat/” directory
root@arunsb:/usr/src/redhat# pwd
/usr/src/redhat
root@arunsb:/usr/src/redhat# ls
BUILD RPMS SOURCES SPECS SRPMS
root@arunsb:/usr/src/redhat# ls BUILD/
openlsm-0.99-r45 <== Source extracted here as part of build instructions from specification file ie “openlsm.spec”
root@arunsb:/usr/src/redhat# ls SOURCES/
openlsm-0.99-r45.tar.gz <== original ‘openlsm-0.99-r45.tar.gz’ source file copied by me
root@arunsb:/usr/src/redhat# ls RPMS/
athlon i386 i486 i586 i686 noarch
root@arunsb:/usr/src/redhat# ls RPMS/i386/
openlsm-0.99-r45.i386.rpm <== Binary rpm package created!
root@arunsb:/usr/src/redhat# ls SRPMS/
openlsm-0.99-r45.src.rpm <== Source rpm package created!
root@arunsb:/usr/src/redhat#
Step 3] Now install the package and test it ~
root@arunsb:/usr/src/redhat# cp RPMS/i386/openlsm-0.99-r45.i386.rpm /home/arunsb/
root@arunsb:/usr/src/redhat# cd /home/arunsb/
root@arunsb:~# ls
openlsm-0.99-r45 openlsm-0.99-r45.i386.rpm openlsm-0.99-r45.tar.gz thttpd-2.25b-3.dag.src.rpm thttpd-2.25b-dag.spec
root@arunsb:~# rpm -ivh openlsm-0.99-r45.i386.rpm
Preparing… ########################################### [100%]
1:openlsm ########################################### [100%]
root@arunsb:~# ls /usr/local/openlsm/
bin contrib etc include lib sbin scripts share var
root@arunsb:~#
** Starting the openlsm server ~
root@arunsb:~# /usr/local/openlsm/contrib/openlsm-redhat start
* Starting openlsm admin server: openlsm
. [ OK ]
root@arunsb:~#
root@arunsb:~# /usr/local/openlsm/contrib/openlsm-redhat status
openlsm (pid 21607) is running…
root@arunsb:~#
root@arunsb:~# rpm -q openlsm-0.99-r45
openlsm-0.99-r45
root@arunsb:~#
root@arunsb:~# rpm -lq openlsm-0.99-r45
..
…
root@arunsb:~# rpm -qiv openlsm-0.99-r45
Name : openlsm Relocations: (not relocatable)
Version : 0.99 Vendor: IndianGNU.org & openlsm
Release : r45 Build Date: Wed 02 Dec 2009 05:50:54 PM IST
Install Date: Wed 02 Dec 2009 06:06:23 PM IST Build Host: alongseveral-dr.eglbp.corp.yahoo.com
Group : System Environment/Daemons Source RPM: openlsm-0.99-r45.src.rpm
Size : 14877918 License: GPL
Signature : (none)
Packager : IndianGNU.org (http://www.indiangnu.org)
URL : http://openlsm.sourceforge.net/
Summary : openlsm Admin Server
Description :
openlsm Admin Server is free & open source web based control panel for Linux,Unix systems.
root@arunsb:~#
** NOTE ~ This article does not contain information on how to define micros,how to copy docs,man pages to default location, how to set permision and ownership etc. I will cover this topics in next article on RPM.
Regards,
Arun Bagul