User Tools

Site Tools


rpm

This is an old revision of the document!


RPM

Package management system few tips / trick to build / modify / work with packages.
Many hints information taken from original site RPM

How to Print .spec file from RPM

rpm --scripts -qp <rpmfile>

First RPM

Name of Package : libtorrent
Building it in folder “/usr/local/src/libtorrent”

mkdir /usr/local/src/libtorrent
cd /usr/local/src/libtorrent
mkdir BUILD RPMS SOURCES SPECS SRPMS

Creating macro not bad idea.

| /usr/local/src/libtorrent/.rpmmacros
%packager Ketan Patel

Get Sources from libtorrent
Place it in “/usr/local/src/libtorrent/SOURCES”
I have used following method.

cd /usr/local/src/libtorrent/SOURCES
svn co svn://rakshasa.no/libtorrent/trunk/libtorrent libtorrent
tar -cvf /usr/local/src/libtorrent/SOURCES/libtorrent.tar.gz libtorrent

Considering building rtorrent at non standard location.

NOTE : Please make sure code below has some SUSE Based Customization

| /usr/local/src/libtorrent/SPECS/libtorrent.spec
%define name libtorrent
%define srcdir /usr/local/src
%define _topdir %{srcdir}/libtorrent
 
 
summary: rTorrent
name: libtorrent
Source: libtorrent.tar.gz
License: GPL
version: 1
release: 1
Group: System/Utils
Prefix: /opt/libtorrent
buildarch: x86_64
BuildRoot: %{prefix}/%{name}-%{version}-%{release}-%{buildarch}-root
%define lib %{prefix}/lib64
%define include %{prefix}/include
Provides: libtorrent
Requires: ncurses, libcppunit-devel
AutoReqProv: no
 
 
%description
libtorrent is a BitTorrent client for ncurses, using
the libtorrent library. The client and library is
written in C++ with emphasis on speed and efficiency, while delivering
equivalent features to those found in GUI based clients in an ncurses
client.
 
%prep
%setup -q -n libtorrent
 
 
%build
chmod 755 autogen.sh
./autogen.sh
%{suse_update_config -f}
autoreconf -fiv
./configure --prefix=%{prefix} --libdir=%{lib}
make prefix=$RPM_BUILD_ROOT
 
%install
rm -rf %{buildroot}
make DESTDIR=$RPM_BUILD_ROOT install
rm -rf $RPM_BUILD_ROOT/%{prefix}/usr
 
 
%clean
make clean
rm -rf %{buildroot}
 
%files
%defattr(-,root,root,-)
%doc README
/opt/libtorrent/lib64/*
/opt/libtorrent/include/*
 
%post
echo "/opt/libtorrent/lib64/" > /etc/ld.so.conf.d/libtorrent.conf
ldconfig
 
%postun
rm -rf %{prefix}
rm /etc/ld.so.conf.d/libtorrent.conf
ldconfig
 
%Changelog
* Mon Nov 08 2010 Seriously, Check release son!!
Initial Build
Building Actual RPM
cd /usr/local/src/libtorrent
rpmbuild -v -bb --clean SPECS/libtorrent.spec

OR

rpmbuild -ba SPECS/libtorrent.spec
Test Your RPM
rpm -Vp RPMS/x86_64/libtorrent-1-1.x86_64.rpm

Sample RPM

| sample.spec
Name:      xgauguin-support
Summary:   xGauguin support metapackage
Version:   20110513
Release:   1.blip
Vendor:    lithiumfox
License:   none
Group:     Applications
URL:       http://lithiumfox.com
BuildRoot: %{_tmppath}/%{name}-%{version}-%(id -u -n)
BuildArch: noarch
Requires:  nginx, perl(Image::Size), perl(Params::Validate), perl(DateTime::Locale), perl(Class::Load), perl(parent), perl(DateTime::TimeZone), perl(Class::Singleton), perl(Test::Exception), perl(DateTime), perl(Image::Magick), perl(GD), perl(LWP), ImageMagick, gd, yum-utils
 
%description
Gauguin supporting packages
 
%install
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
%{__mkdir_p} %{buildroot}%{_localstatedir}/www/releases
%{__mkdir_p} %{buildroot}%{_localstatedir}/tmp/cache
 
%pretrans
## Force installation of conflicts
# libxml2.i386, perl-Locale-Codes
if $( ! rpm -q libxml2.i386 > /dev/null 2>&1)
  then
 
    yumdownloader libxml2.i386 > /dev/null 2>&1
    %{__rm} /var/lib/rpm/__db.000 > /dev/null 2>&1
    rpm --force -ivh libxml2*.rpm 
    %{__rm} libxml2*.rpm > /dev/null 2>&1
fi
 
if $( ! rpm -q perl-Locale-Codes > /dev/null 2>&1)
  then
    set -m
    yumdownloader perl-Locale-Codes > /dev/null 2>&1
    %{__rm} /var/lib/rpm/__db.000 > /dev/null 2>&1
    rpm --force -ivh perl-Locale-Codes*.rpm > /dev/null 2>&1
    %{__rm} libxml2*.rpm > /dev/null 2>&1
fi
 
%pre
## Check if vlad user exists, if not add them
if $( ! id vlad >/dev/null 2>&1) 
   then
     groupadd -g 1029 vlad > /dev/null 2>&1 ||: 
     useradd -u 1029 -g 1029 -d /home/vlad -s /bin/bash -p '$1asdf0' -m vlad > /dev/null 2>&1
fi
 
##Add user to sudoers
if $( ! grep vlad /etc/sudoers >/dev/null 2>&1)
  then
    echo "vlad ALL=NOPASSWD: /etc/init.d/nginx" >> /etc/sudoers
fi
 
%post
##Add nginx to startup
chkconfig --level 345 nginx on
 
##Create symlink for nginx.conf
if [ ! -h /etc/nginx/nginx.conf ]
  then
   ln -f -s %{_localstatedir}/www/prod/gauguin/current/conf/nginx-prod.conf %{_sysconfdir}/nginx/nginx.conf
fi 
 
 
%files
%defattr(-,root,root)
%attr(-,vlad,-) %{_localstatedir}/www/prod/xgauguin
%attr(777,-,-) %{_localstatedir}/tmp/xgauguin-cache
 
%changelog
* Fri May 13 2010 Jason Thomas <jason@lithiumfox.com> - %{version}
- Initial package creation

changelog

You can use following one liner for changelog.

awk '{print "*", $1, $2, $3, $6, "Jason Thomas <jason@lithiumfox.com>","-", "%{version}""\n""- initial rpm creation"}' <(date)

Good Reading

General RPM Command

List Content

rpm -qpl file.rpm

MOCK

Mock is a really nice tool to generate RPM cleanly.
I used KVM / MOCK to build RPM for my own reasons but you can use just mock and clean env. after every build.

General Details Available at Mock Project Page

Rather then guessing i have pasted all the command i have used to build RPM from srpm.
Using / Generating Spec require another tutorial this is strictly about some work around and keeping env. between transaction.

Install Mock
yum install mock
Add user to group

I am using rpmbuild user.

usermod -a -G mock rpmbuild
Initialize Mock

Before you work on anything Please initialize the environment.
It is good practice to initialize Environment between every build cycle to clean any possible left over or unforeseen issue.

mock --init -r epel-5-x86_64

su to user

You can not run mock as root so ….

su rpmbuild
Install required packages

I found that installed package stays installed during cycles.
So you do not require to install packages every time unless you initialize env.

/usr/bin/mock --install -r epel-5-x86_64 perl-libwww-perl.noarch

Copying Files

<note important>Dont scratch over –copyin check spelling one more time</note>

/usr/bin/mock -r epel-5-x86_64 --copyin pgpool-II-3.1.2.tar.gz /tmp/
Get SRPM
cd ~
wget http://ftp.arix.com/cpan2rpm-2.028-1.src.rpm
Finally Building RPM

<note> –no-clean : this will keep your files intact in build env.
–no-cleanup-after : i wanted to keep all work file so i used this just incase. </note>

/usr/bin/mock --rebuild --no-clean --no-cleanup-after -r epel-5-x86_64 cpan2rpm-2.028-1.src.rpm

In general case result will be stored in '/var/lib/mock/epel-5-x86_64/result/'

rpm.1334165943.txt.gz · Last modified: 2020/08/10 02:29 (external edit)