My linux world » Build mock RPM Survival Guide

Build mock RPM Survival Guide


Contents

Prerequistes

Install mock

Configuration

Create tree

runuser -l builder -c "mkdir -p /home/builder/rpmbuild/SPECS"
runuser -l builder -c "mkdir -p /home/builder/rpmbuild/SOURCES"
runuser -l builder -c "mkdir -p /home/builder/rpmbuild/SRPMS"
runuser -l builder -c "mkdir -p /home/builder/rpmbuild/RPMS"

Source

In /home/builder/rpmbuild/SOURCES, we have to create a tar.gz containing all sources.
This tar.gz file must have the parent node ‘myrpm-1.0’.

runuser -l builder -c "mkdir -p /home/builder/rpmbuild/SOURCES/myrpm-1.0"
runuser -l builder -c "touch /home/builder/rpmbuild/SOURCES/myrpm-1.0/helloworld.txt"
runuser -l builder -c "cd /home/builder/rpmbuild/SOURCES && tar cvfz myrpm-1.0.tar.gz myrpm-1.0"

Create spec file

In the spec file, it is recommanded to use macros.
We can find the list of all macros here: /usr/lib/rpm/macros

Let’s create the file /home/builder/rpmbuild/SPECS/myrpm.spec

Name:	        myrpm
Version:        1.0	
Release:	1%{?dist}
Summary:        Summary of %{name}	
Group:	        System Environment/Base	
License:        MIT
Source0:        {name}-%{version}.tar.gz
BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
# Package required on build (under mock)
BuildRequires:  sudo
 
# Package required on install
Requires:       dos2unix	
 
%description
Description of %{name}
 
%prep
# prepare package
 
%setup -q
# unzip package
 
%build
# build
 
%install
%{__rm} -rf %{buildroot}
# create directory : under mock %{buildroot} is empty, so we must create all tree.
%{__mkdir_p} %{buildroot}/opt/rabahi.net/example
# now we can copy the file helloworld.txt (at the root, under {name}-%{version}, of our tar.gz)
%{__cp} -f helloworld.txt %{buildroot}/opt/rabahi.net/example/helloworld.txt
 
%post
# post installation
# we are under the final tree.
# so, we won't use %{buildroot}
dos2unix /opt/rabahi.net/example/helloworld.txt
 
%clean
rm -rf %{buildroot}
 
%files
# In files, we list and set permissions on files.
# Example here: root is the owner
%defattr(-,root,root,-)
%doc
 
%changelog

Generation

Generate src.rpm

# Note: First do a 'su builder' or use 'runuser -l builder -c "<cmd>"
mock -r epel-6-x86_64 
     --spec=/home/builder/rpmbuild/SPECS/myrpm.spec 
     --sources=/home/builder/rpmbuild/SOURCES 
     --resultdir=/home/builder/rpmbuild/SRPMS 
     --buildsrpm

Generate rpm

# Note: First do a 'su builder' or use 'runuser -l builder -c "<cmd>"
setarch x86_64 mock 
        -r epel-6-x86_64 
        rebuild /home/builder/rpmbuild/SRPMS/myrpm-1.0-1.el6.src.rpm 
        --resultdir=/home/builder/rpmbuild/RPMS

Use rpm

  1. Publish it to your repository
  2. Install it:
    yum install myrpm

Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.