This shows you the differences between two versions of the page.
rpm [2012/04/11 17:39] k2patel [MOCK] |
rpm [2020/08/10 02:35] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== RPM ====== | ||
- | |||
- | Package management system few tips / trick to build / modify / work with packages. \\ | ||
- | Many hints information taken from original site [[http://rpm.org/ | RPM]] | ||
- | |||
- | ==== How to Print .spec file from RPM ==== | ||
- | |||
- | <code bash> | ||
- | rpm --scripts -qp <rpmfile> | ||
- | </code> | ||
- | |||
- | ==== First RPM ==== | ||
- | |||
- | Name of Package : libtorrent\\ | ||
- | Building it in folder "/usr/local/src/libtorrent"\\ | ||
- | <code bash> | ||
- | mkdir /usr/local/src/libtorrent | ||
- | cd /usr/local/src/libtorrent | ||
- | mkdir BUILD RPMS SOURCES SPECS SRPMS | ||
- | </code> | ||
- | |||
- | Creating macro not bad idea. | ||
- | <code bash | /usr/local/src/libtorrent/.rpmmacros> | ||
- | %packager Ketan Patel | ||
- | </code> | ||
- | |||
- | Get Sources from [[http://libtorrent.rakshasa.no/ | libtorrent]]\\ | ||
- | Place it in "/usr/local/src/libtorrent/SOURCES"\\ | ||
- | I have used following method. | ||
- | <code bash> | ||
- | 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 | ||
- | </code> | ||
- | Considering building rtorrent at non standard location. | ||
- | |||
- | NOTE : **Please make sure code below has some SUSE Based Customization** | ||
- | |||
- | <code bash | /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 | ||
- | </code> | ||
- | |||
- | == Building Actual RPM == | ||
- | <code bash> | ||
- | cd /usr/local/src/libtorrent | ||
- | </code> | ||
- | <code bash> | ||
- | rpmbuild -v -bb --clean SPECS/libtorrent.spec | ||
- | </code> | ||
- | OR | ||
- | <code bash> | ||
- | rpmbuild -ba SPECS/libtorrent.spec | ||
- | </code> | ||
- | == Test Your RPM == | ||
- | <code bash> | ||
- | rpm -Vp RPMS/x86_64/libtorrent-1-1.x86_64.rpm | ||
- | </code> | ||
- | |||
- | ==== Sample RPM ==== | ||
- | <code bash | 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 | ||
- | </code> | ||
- | |||
- | === changelog === | ||
- | You can use following one liner for changelog. | ||
- | <code bash> | ||
- | awk '{print "*", $1, $2, $3, $6, "Jason Thomas <jason@lithiumfox.com>","-", "%{version}""\n""- initial rpm creation"}' <(date) | ||
- | </code> | ||
- | |||
- | |||
- | ==== Good Reading ==== | ||
- | |||
- | [[http://fedoraproject.org/wiki/How_to_create_an_RPM_package | Fedora Package]]\\ | ||
- | [[http://en.opensuse.org/openSUSE:Build_Service_Tutorial | OpenSUSE Build Service]]\\ | ||
- | [[http://rpm.org/wiki/Docs#PackagerDocumentation | RPM Official]] | ||
- | |||
- | ==== General RPM Command ==== | ||
- | |||
- | === List Content === | ||
- | <code bash> | ||
- | rpm -qpl file.rpm | ||
- | </code> | ||
- | |||
- | ==== 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 [[ http://fedoraproject.org/wiki/Projects/Mock | 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 == | ||
- | <code bash> | ||
- | yum install mock | ||
- | </code> | ||
- | |||
- | == Add user to group == | ||
- | I am using rpmbuild user. | ||
- | <code bash> | ||
- | usermod -a -G mock rpmbuild | ||
- | </code> | ||
- | |||
- | == 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. | ||
- | |||
- | <code bash> | ||
- | mock --init -r epel-5-x86_64 | ||
- | </code> | ||
- | |||
- | === su to user === | ||
- | You can not run mock as root so .... | ||
- | <code bash> | ||
- | su rpmbuild | ||
- | </code> | ||
- | |||
- | == 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. | ||
- | |||
- | <code bash> | ||
- | /usr/bin/mock --install -r epel-5-x86_64 perl-libwww-perl.noarch | ||
- | </code> | ||
- | |||
- | ==== Copying Files ==== | ||
- | <note important>Dont scratch over --copyin check spelling one more time</note> | ||
- | <code bash> | ||
- | /usr/bin/mock -r epel-5-x86_64 --copyin pgpool-II-3.1.2.tar.gz /tmp/ | ||
- | </code> | ||
- | |||
- | |||
- | == Get SRPM == | ||
- | <code bash> | ||
- | cd ~ | ||
- | wget http://ftp.arix.com/cpan2rpm-2.028-1.src.rpm | ||
- | </code> | ||
- | |||
- | == 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> | ||
- | |||
- | <code bash> | ||
- | /usr/bin/mock --rebuild --no-clean --no-cleanup-after -r epel-5-x86_64 cpan2rpm-2.028-1.src.rpm | ||
- | </code> | ||
- | |||
- | In general case result will be stored in '/var/lib/mock/epel-5-x86_64/result/' | ||
- | |||