Blog

How to create a RPM from source package(Creating CSF RPM)

Tags: cPanelcsfcsf rpmrpmrpm for csf

Published on: August 24, 2010 by Faheem P.

How to create a RPM from source package(Creating CSF RPM)

Scenario:

We are here explaining about how to create RPM package from the Source. As an initial step, compile and install the source using normal procedures just to confirm all necessary libraries/dependencies are met.

Here I am explaining the whole process to create RPM package for CSF that could be  installed on cPanel servers.

Getting ready with the Source Files:

Download Latest CSF from here : http://www.configserver.com/free/csf.tgz

Extract the tarball.

[root@server new]# tar -xvf csf.tgz
[root@server new]# ls
csf  csf.tgz

Install to check all libraries/dependencies are met.

[root@server csf]# cd csf
[root@server csf]# sh install.cpanel.sh
*WARNING* TESTING mode is enabled - do not forget to disable it in the configuration
Installation Completed

We confirmed all libraries/dependencies are met for installing CSF.  We need to rename the tarball to define a version so that it could be used in the SPEC file.

[root@server csf]# cd ..
[root@server new]# ls
csf  csf.tgz
[root@server new]#mv csf csf-0.0.1
[root@server new]# tar -cvf csf-0.0.1.tar.gz csf-0.0.1

0.0.1 defines the version. (Can assign any). Now we are ready with the source file for CSF csf-0.0.1.tar.gz that could be used to generate RPM.

Building the RPM:

Install RPMBUILD tool:

[root@server ~]# yum install rpm-build

We never build RPM’s as ‘root’ users, but as normal users, because root can alter any file on the system, it was easy to inadvertently alter a running system by adding extraneous files or removing important files during interim builds of an RPM. Earlier RPM’s were build as root user but recently the RPM system changed to allow any user to build RPMs in a home directory. Building an RPM without the privileges of root prevents changes to core system files and hence we are on the safer side.

Initial Set-up:

To create RPM package we need to create a directory hierarchy for the rpm build tool to work with. To begin with, create a directory under your home directory which will act as the root directory for the build process. Lets make a directory ‘csfrpm’ under home directory for this purpose.

[sage@server ~]$ mkdir -p /home/your_username/csfrpm
[sage@server ~]$ cd /home/your_username/csfrpm

Create Five sub-directories under csfrpm.

[sage@server csfrpm]$ mkdir BUILD RPMS SOURCES SPECS SRPMS
  • BUILD: BUILD is used as a space to compile the software.
  • RPMS: RPMS contains the binary RPM that rpmbuild builds.
  • SOURCES: SOURCES is for source code.
  • SPECS: SPECS contains your spec file or files—one spec file per RPM you want to build.
  • SRPMS: SRPMS contains the source RPM built during the process.
[sage@server csfrpm]$ ls
BUILD  RPMS  SOURCES  SPECS  SRPMS

Copy the source code that we have created(csf-0.0.1.tar.gz) to the SOURCES folder. Make sure that the owner  for source file is your_username.

[sage@server ~]$ cp csf-0.0.1.tar.gz /home/your_username/csfrpm/SOURCES/

Create the SPEC file:

SPEC file is noting but the configuration for rpmbuild tool.

[sage@server csfrpm]$ vi SPECS/csf.spec
# This is a sample spec file for csf

%define _topdir         /home/your_username/csfrpm
%define name            csf
%define release         0
%define version         0.0.1
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Summary:                GNU csf
License:                GPL
Name:                   %{name}
Version:                %{version}
Release:                %{release}
Source:                 %{name}-%{version}.tar.gz
Group:                  Security/Tools

%description
A Stateful Packet Inspection (SPI) firewall, Login/Intrusion Detection and Security application for Linux servers.

%prep
%setup -q

%install
./install.cpanel.sh prefix=$RPM_BUILD_ROOT/usr/local

%clean
%{__rm} -rf %{buildroot}

%files
%defattr(-,root,root,0755)

Finally Build the RPM:

[sage@server csfrpm]$ rpmbuild -v -bb --clean SPECS/csf.spec

You can see the result if everything went fine:

Processing files: csf-0.0.1-0
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/csf-0.0.1-root
Wrote: /home/your_username/csfrpm/RPMS/i386/csf-0.0.1-0.i386.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.84469
+ umask 022
+ cd /home/your_username/csfrpm/BUILD
+ cd csf-0.0.1
+ /bin/rm -rf /var/tmp/csf-0.0.1-root
+ exit 0
Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.84469
+ umask 022
+ cd /home/yuor_username/csfrpm/BUILD
+ rm -rf csf-0.0.1
+ exit 0

The RPM is written to /home/your_username/csfrpm/RPMS/i386/csf-0.0.1-0.i386.rpm

Category : Howtos, Linux, Security

Faheem P.

Faheem P.

Faheem enjoys learning new technologies and loves to implement cutting edge solutions. He is one of the most active member in various technical forums and is a familiar face in various brain storming sessions. He takes great pride in being an explorer and the best thing you can be sure about in his room is the backpack!!

You may also read:

Comments

Add new commentSIGN IN

Let's Connect

Categories

Your Cart

Cart is empty.

Subtotal
₹0.00
APPLY
0
Send this to a friend