SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler offline
Software Packaging with RPM
Andrew Ford
<a.ford@ford-mason.co.uk>
18 April 2013
Copyright © 2013 Ford & Mason Ltd
About this talk
● Covers package building –
not package management
● Material was collected for a book:
“The RPM Handbook”
● Warning: this talk is not exhaustive!
Outline of talk
● What is RPM?
● Building RPMs
– Dependencies and capabilities
– Macros
– Running rpmbuild
– Anatomy of a specfile
– Build scripts
– Management scripts and triggers
– Evolution of RPM
● Sources of further information
What is the
significance of packaging?
● Ian Murdoch, founder of Debian,
suggested in 2007 that:
[Package management is] the biggest
advancement Linux has brought to the
industry
● Debian and RPM packages evolved at roughly
the same time and are comparable in
functionality
Why is RPM relevant?
● Provides a straightforward, consistent way to manage
software and resources –
directly or through higher-level tools
● The fundamental building block of distros
● Widespread use:
– RPM-based distros (RHEL, Fedora, SLE, openSUSE)
– Independent Software Vendors (ISVs)
– Packages for internal use
● Well-constructed packages give a professional impression
RPM design goals
● Upgradability
(easy to install, upgrade and remove packages)
● Powerful querying
● System verification
● Pristine sources
(start with original, “upstream” source code)
● Reproducible builds
Issues with RPM
● Poorly documented
● Shows signs of age – but it is evolving
● Enterprise distributions lag behind latest developments
(newer features often not available for several years)
● Many packaging details are distribution-specific
(see Fedora, openSUSE and Mandriva packaging
guidelines)
● Information and misinformation on the internet
Versions of RPM in use
Version Date Used by (EOL)
4.4.2 2005-07-21 SUSE 10
4.4.2.3 2008-04-01 RHEL 5 (2017/2020), SUSE 11
4.8.0 2010-01-08 RHEL 6 (2020/2023)
4.9.1.2 2011-09-29 OpenSUSE 12.2 (2014)
4.9.1.3 2012-04-03 Fedora 17 (2013)
4.10.1 2012-10-03 Fedora 18 (2014)
4.11.1 2013-02-01
● These are just the versions still in use by major distributions.
● Prior to 2005 RPM development languished.
● Version 4.4.2 is the first version of the relaunched rpm.org
● In 2006 RPM was forked by the previous developer – rpm5 is only
used by Mandriva
What does RPM consist of?
● Package file format (.rpm and .srpm)
contains metadata and payload
● Package database (/var/lib/rpm/*)
information on installed packages
● Configuration files
(/etc/rpm/* and /usr/lib/rpm/*)
● Run-time admin tools (rpm command)
● Build tools (rpmbuild command)
● Libraries used by tools such as yum
and the rpm tools themselves
What does RPM do?
● Installs, erases and updates packages
● Reports on what packages are installed
● Verifies installed packages
● Checks dependencies within sets of packages being
installed, upgraded or removed
● Underpins higher-level packaging tools –
e.g. YUM, PackageKit, Zypper
(these resolve dependencies, as well as checking)
● Provides a package build tool (rpmbuild)
Building RPM packages
● Dependencies
● Macros
● The build environment
● The build process
● Scriptlets, Scripts, and Triggers
Dependencies
● Dependency tracking is fundamental to
packaging systems
● Ensures that software being installed has all its
prerequisites
● Ensures that packages aren't inadvertently
removed while other packages depend on them
● Differentiate between dependency checking and
dependency solving
Dependencies (2)
● Packages provide “capabilities” (text strings)
● One automatic capability is the name of the package
● Special capabilities:
– rpmlib(feature)
– interp(Module) – e.g. perl(Class::Accessor)
● Requirements can specify versions of capability:
op [epoch:]version[-release]
Version comparison rules
● Epoch - integer comparison
● Version and release:
– Split into numeric and alpha substrings and
compared substring by substring (separators ignored)
– Leading zeroes ignored
– Longer substring or sequence is newer
– e.g.:
● 1.0010 > 1.9
● 1a > 1B
● 3:1.0 > 2:99.999
● 1.2.3abc = 1_2_3_abc
RPM macros
● Macro values control all rpm tools
(rpmbuild, rpm, etc) e.g.:
– %_topdir defines build directory (~/rpmbuild)
– %_binary_payload defines payload format and
compression
● Defaults defined in /usr/lib/rpm/macros
● About 250 macros – another 80 commented out
RPM macros (2)
Can be defined:
● In macro files
(/usr/lib/rpm/macros, /etc/rpm/*, ~/.rpmmacros)
● On the command line – for all commands
(-D 'name definition')
● In spec files
– %global name[(args)] expansion
– %define name[(args)] expansion
● By rpmbuild internally – e.g. Name tag causes %name macro to
be defined with the tag's value
Note: parameterized macros definitions are evaluated twice (on
definition and use), simple macros are evaluated once (on definition)
RPM macros (3)
● Usage %name or %{name} – note: if the macro is
not defined you get literal string in output
● Conditionals:
– %{?name[:expansion]}
– %{!name:expansion}
– %if expr ... %else ... %endif
– %ifarch / %ifnarch / %ifos / %ifnos
● Shell escape: %(command arg ...)
● Messages: %{echo: msg}
(also warn and error)
● Dump all definitions: %dump
Building RPMs
● Packages are normally built from sources and patches
● Aimed at software that follows GNU Coding Standard
(autoconf/automake, etc) – works best if you don't fight it
● RPM packages built with rpmbuild command
(-ba option to build everything)
● Controlled by “spec file”
(which may be located within tar file – use -ta)
● Spec file can define multiple packages
● Spec file specifies build requirements
(can be installed with yum-builddep – from yum-utils)
Build process
● rpmbuild initializes itself from macro files
(/etc/rpm/*, /usr/lib/rpm/macros, ~/.rpmmacros)
● Reads spec file, expanding macros as it goes
● Steps through build stages specified by spec file
● Determines dependencies and capabilities provided
● Constructs binary RPM and/or source SRPM
● Note:
– never build as root!
– always test RPMs on a clean system or with mock to identify
unspecified dependencies (which may be satisified by s/w
installed on the build system)
Build environment
● Build area is a directory hierarchy –
location specified by %_topdir (~/rpmbuild)
– SPECS/ (%__specdir)
– SOURCES/ (%__sourcedir)
– BUILD/ (%__builddir)
– BUILDROOT/ (%__buildroot)
– RPMS/ (%__rpmdir)
– SRPMS/ (%__srcrpmdir)
● Setup directories under $HOME with
rpmdev-setuptree (from rpmdevtools package)
Spec files
● Complete specification of package
● Defines meta data for package
(name, version, release, license, etc)
● Specifies dependency information
● Describes software build process
● Provides a manifest of the files to be installed
● Provides scripts for package install/erase
● Note: clumsy syntax – %thing may be a macro, a spec
file section or an file attribute depending on context
● Comments are marked with “#”, but macros within
comments are expanded – which can cause problems
Spec file sections
● Preamble (subpackage preambles introduced by %package)
● Package description (%description)
● Build script sections (%prep, %build, %install, %check,
%clean)
● Run-time scripts (%pre, %post, %preun, %postun, %pretrans,
%posttrans, %verify)
● Trigger scripts (%triggerprein, %triggerin, %triggerun,
%triggerpostun)
● Files manifest (%files)
● Change log (%changelog)
Subpackages have separate description, run-time scripts, triggers and
manifests (sections qualified with subpackage suffix or full name)
~/rpmbuild/ (%_topdir)
RPMS/
pkg.spec
SPECS/
SOURCES/
BUILD/
BUILDROOT/
Name: pkg
Version: 1.0
Release: 1
%prep
%setup -q
%build
configure
make
%install
make install
%files
Example spec file
Name: hello
Version: 2.7
Release: 1%{?dist}
Summary: GNU 'hello world' program
Group: Miscellany
Vendor: Free Software Foundation
License: GPLv3
URL: http://www.gnu.org/software/hello/
BuildRoot: %{_tmppath}/%{name}-root-%(%{__id_u} -n)
Requires: info
Source0: %{name}-%version.tar.gz
%description
GNU Hello produces a familiar, friendly greeting. The practical purpose
Of GNU Hello is to serve as a minimal example of a GNU package.
%prep
%setup -q
%build
%configure
make
%install
make install DESTDIR=$RPM_BUILD_ROOT
ExamplesSpec file (continued)
%clean
rm -rf $RPM_BUILD_ROOT
%post
/sbin/install-info %{_infodir}/hello.info.gz %{_infodir}/dir || :
%preun
if [ $1 = 0 ]; then
/sbin/install-info --delete %{_infodir}/hello.info.gz %{_infodir}/dir || :
fi
%files
%defattr(-,root,root,-)
%doc README
/usr/bin/hello
%exclude /usr/share/info/dir
%doc /usr/share/info/hello.info.gz
/usr/share/locale/*/LC_MESSAGES/hello.mo
%doc /usr/share/man/man1/hello.1.gz
%changelog
* Fri Apr 29 2011 <andrew@ford-mason.co.uk> - 2.7-1
- Initial packaging
Spec file preamble
● Consists of key-value records before first section
– Name: name of the software package
– Version: version number of the upstream source code
– Release: number of this release of the software package
– Summary: short, one-line description of the package
– URL: web site URL for software
– License: licence for the software
– Group: category the software falls in
– Source0: file containing the N'th source file
● Preamble for subpackages specified with %package section
● Info corresponds to output from rpm --query –info
● %description section provides more detailed description
Specifying dependencies
● Automatic and manual dependencies
(scripts %__find_requires and %__find_provides)
● Packages provide “capabilities”
(including one with the name of the package)
● Specify capabilities provided with Provides tag
● Required packages/capabilities with Requires tag
● PreReqs tag is deprecated – use Requires(pre)
● Conflicts specified with Conflicts tag
● SUSE has “soft” dependencies (Suggests and
Recommends) – these may come to later versions of rpm
Specifying dependencies (2)
● Dependencies and capabilities provided can be
– Automatically determined by rpmbuild
(and helpers)
– Manually specified (%requires, %provides, etc)
● Automatic dependency generators run by
rpmbuild after %install section
● Also need to specify build dependencies
Build process in detail – %prep
● Unpacks source files and applies patches, e.g.:
● Process often acheived with two “pseudo”-macros:
– %setup – unpacks (compressed) tar files into build dir
– %patchN – applies patch N
%prep
%setup -q
%patch0
Build drocess in detail – %build
● Configures and builds software e.g.:
● %configure runs GNU configure
● make is standard Linux make command
%build
%configure
make
Build process in detail – %install
● Installs to the “build root” - a staging area
(proxy for the real root directory)
● Installs into build root (proxy for the filesystem
root)
● Configure-generated makefiles support
$DESTDIR
%install
make install DESTDIR=$RPM_BUILD_ROOT
Debugging RPM build scripts
● rpmbuild creates temporary script files
● Build can be executed up to a certain stage
– -bp – stop after %prep
– -bc – stop after %build (compile stage
– -bi – stop after %install
– -bl – do “list check”
(expand %files and check everything exists)
● --short-circuit option to skip to stage specified with -bc, -bi or -bb
(but makes generated RPM essentially unusable)
● shortrpm program can be used to create installable RPMs skipping prep
and build stages – but should only be used in development
● Alternatively “exit 1” to build or install script,
and examine and debug the script left in /var/tmp
Management scripts
● Scripts run before/after package installation, upgrade and erasure
– %pretrans – run at start of transaction
– %pre – before package installed
– %post – after package installs
– %preun – before package uninstalled
– %postun – after package uninstalled
– %posttrans – at end of transaction
– %verifyscript – run by rpm -V
● On upgrade install scripts are run from new version of package,
then uninstall scripts from old version
●
Install scripts are not interactive – we're not on Debian here!
Management scripts (2)
● Uses:
– Set up users and groups
– Install services and cron jobs, set up alternatives
– Refresh dynamic linker bindings (ldconfig)
● Scripts receive argument $1 – says how many
instances left at end of operation:
– 1 after first install
– 2 for install of new version on upgrade
– 1 for uninstall of previous version on upgrade
– 0 for final uninstall
Management scripts (3)
● Scripts can be provided for subpackages (specify
name after script tag)
● Interpreter specified with -p program
– Default interpreter is /bin/sh
– <lua> for built-in lua interpreter
(all that is available on %pretrans of first-stage install)
– Can specify /sbin/ldconfig if that is all that needs to
run
– Creates an automatic dependency on interpreter
Triggers
● Scripts that run when a target package is installed or
uninstalled:
– %triggerin – run when target or source package
installed/upgraded
– %triggerun – run when target or source package is uninstalled
– %triggerpostun – run after target package is uninstalled
● e.g.: %triggerin -p /bin/sh – postfix
● Trigger scripts invoked with two arguments:
– $1 gives number of instances of source package remaining when
trigger completes
– $2 gives number of instances of target package remaining
File lists
● List of files in package(s) specified by %files
● List can be read from file with -f file
● Attributes specified with %defattr, %attr
● Configuration files marked with %config
● Documentation flagged with %doc
(collected and placed in /var/share/doc)
● 4.11 introduces %license to mark license files
● Error if there are unpackaged files in build root
Repeatable builds
● BuildRequires specifies packages needed
for building
● Building under mock can ensure unspecified
dependencies are identified – basic usage:
mock –-init chroot-name
mock –-root chroot-name 
–-rebuild package.src.rpm
● Should also test installation of built packages
RPM evolves
Just a couple of examples (remember RHEL5 uses 4.4.2.3):
● 4.6.0
– BuildRoot tag now silently ignored
– Group tag no longer mandatory
– %_topdir now $HOME/rpmbuild (was /usr/src/redhat)
– New macros %patches and %sources
● 4.7.0
– Support for XZ compression
– Group tag in subpackage inherits from main package
– New macros %getenv and %getconfdir
More changes
● 4.8.0 (used by RHEL6)
– Deprecated Copyright tag no longer recognized
– PreReq and BuildPreReq are deprecated
– New BugUrl tag and %_bugurl macro
– New %make_install macro
– Macros %PACKAGE_VERSION and %PACKAGE_RELEASE removed
(use %version and %release)
● 4.9.0
– New Requires(pretrans) and Requires(posttrans) tags
– New OrderWithRequires tag
– --sign option to rpmbuild no longer supported
(now is a separate command – rpmsign)
Release notes on rpm.org have the details
And there's more...
● Multilib
● SE Linux policies
● POSIX capabilities
● Software collections
●
●
●
Sources of further information
● Man pages for rpm, rpmbuild, etc
● rpm.org
● fedoraproject.org/wiki/
Category:Package_Maintainers
● opensuse.org/Portal:Packaging
● wiki.linuxfoundation.org/en/LSB
(Linux Standards Base)
● Classic Shell Scripting, Robbins & Beebe (O'Reilly)
● AUTOTOOLS, John Calcote (No Starch Press)
● GNU Coding Standards (Free Software Foundation)
● rpmhandbook.com (coming soon)
Thank you

Mais conteúdo relacionado

Mais procurados

101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package managementAcácio Oliveira
 
RPM: Speed up your deploy
RPM: Speed up your deployRPM: Speed up your deploy
RPM: Speed up your deployfcrippa
 
101 2.4 use debian package management
101 2.4 use debian package management101 2.4 use debian package management
101 2.4 use debian package managementAcácio Oliveira
 
101 3.3 perform basic file management
101 3.3 perform basic file management101 3.3 perform basic file management
101 3.3 perform basic file managementAcácio Oliveira
 
101 2.1 design hard disk layout
101 2.1 design hard disk layout101 2.1 design hard disk layout
101 2.1 design hard disk layoutAcácio Oliveira
 
Kernel module programming
Kernel module programmingKernel module programming
Kernel module programmingVandana Salve
 
CASPUR Staging System II
CASPUR Staging System IICASPUR Staging System II
CASPUR Staging System IIAndrea PETRUCCI
 
Linea de comandos bioface zem800
Linea de comandos bioface zem800Linea de comandos bioface zem800
Linea de comandos bioface zem800thomaswarnerherrera
 
Linux training
Linux trainingLinux training
Linux trainingartisriva
 
A beginners introduction to unix
A beginners introduction to unixA beginners introduction to unix
A beginners introduction to unixzafarali1981
 
Introduction to Biz Talk - Part 2
Introduction to Biz Talk - Part 2Introduction to Biz Talk - Part 2
Introduction to Biz Talk - Part 2Adi Dancu
 
Commands guide apache hadoop
Commands guide   apache hadoopCommands guide   apache hadoop
Commands guide apache hadoopSaum
 
General apache command for hadoop
General apache  command for hadoop  General apache  command for hadoop
General apache command for hadoop Saum
 
Linux device driver
Linux device driverLinux device driver
Linux device driverchatsiri
 

Mais procurados (20)

Linux
LinuxLinux
Linux
 
File systems for Embedded Linux
File systems for Embedded LinuxFile systems for Embedded Linux
File systems for Embedded Linux
 
101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management
 
RPM: Speed up your deploy
RPM: Speed up your deployRPM: Speed up your deploy
RPM: Speed up your deploy
 
101 2.4 use debian package management
101 2.4 use debian package management101 2.4 use debian package management
101 2.4 use debian package management
 
101 3.3 perform basic file management
101 3.3 perform basic file management101 3.3 perform basic file management
101 3.3 perform basic file management
 
101 2.1 design hard disk layout
101 2.1 design hard disk layout101 2.1 design hard disk layout
101 2.1 design hard disk layout
 
UNIX/Linux training
UNIX/Linux trainingUNIX/Linux training
UNIX/Linux training
 
Yum (Linux)
Yum (Linux) Yum (Linux)
Yum (Linux)
 
Kernel module programming
Kernel module programmingKernel module programming
Kernel module programming
 
CASPUR Staging System II
CASPUR Staging System IICASPUR Staging System II
CASPUR Staging System II
 
Linux redhat final
Linux redhat finalLinux redhat final
Linux redhat final
 
Linea de comandos bioface zem800
Linea de comandos bioface zem800Linea de comandos bioface zem800
Linea de comandos bioface zem800
 
Linux training
Linux trainingLinux training
Linux training
 
A beginners introduction to unix
A beginners introduction to unixA beginners introduction to unix
A beginners introduction to unix
 
Introduction to Biz Talk - Part 2
Introduction to Biz Talk - Part 2Introduction to Biz Talk - Part 2
Introduction to Biz Talk - Part 2
 
Commands guide apache hadoop
Commands guide   apache hadoopCommands guide   apache hadoop
Commands guide apache hadoop
 
101 1.2 boot the system
101 1.2 boot the system101 1.2 boot the system
101 1.2 boot the system
 
General apache command for hadoop
General apache  command for hadoop  General apache  command for hadoop
General apache command for hadoop
 
Linux device driver
Linux device driverLinux device driver
Linux device driver
 

Semelhante a OSDC 2013 | Software Packaging with RPM Demystified by Andrew Ford

Semelhante a OSDC 2013 | Software Packaging with RPM Demystified by Andrew Ford (20)

Rpm cheatbook
Rpm cheatbookRpm cheatbook
Rpm cheatbook
 
2.5 use rpm and yum package management
2.5 use rpm and yum package management2.5 use rpm and yum package management
2.5 use rpm and yum package management
 
101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management
 
101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management
 
RPM Packaging 101 (Old)
RPM Packaging 101 (Old)RPM Packaging 101 (Old)
RPM Packaging 101 (Old)
 
Asian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On UblAsian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On Ubl
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentation
 
Rpm Introduction
Rpm IntroductionRpm Introduction
Rpm Introduction
 
Bringing-it-all-together-overview-of-rpm-packaging-in-fedora
Bringing-it-all-together-overview-of-rpm-packaging-in-fedoraBringing-it-all-together-overview-of-rpm-packaging-in-fedora
Bringing-it-all-together-overview-of-rpm-packaging-in-fedora
 
OpenWRT guide and memo
OpenWRT guide and memoOpenWRT guide and memo
OpenWRT guide and memo
 
Setting up LAMP for Linux newbies
Setting up LAMP for Linux newbiesSetting up LAMP for Linux newbies
Setting up LAMP for Linux newbies
 
(Practical) linux 104
(Practical) linux 104(Practical) linux 104
(Practical) linux 104
 
PHP Development Tools
PHP  Development ToolsPHP  Development Tools
PHP Development Tools
 
package mangement
package mangementpackage mangement
package mangement
 
RPM Building
RPM BuildingRPM Building
RPM Building
 
Oracle11g On Fedora14
Oracle11g On Fedora14Oracle11g On Fedora14
Oracle11g On Fedora14
 
Oracle11g on fedora14
Oracle11g on fedora14Oracle11g on fedora14
Oracle11g on fedora14
 
Linux
LinuxLinux
Linux
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Unix Administration 2
Unix Administration 2Unix Administration 2
Unix Administration 2
 

Último

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durbanmasabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationShrmpro
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 

Último (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 

OSDC 2013 | Software Packaging with RPM Demystified by Andrew Ford

  • 1. Software Packaging with RPM Andrew Ford <a.ford@ford-mason.co.uk> 18 April 2013 Copyright © 2013 Ford & Mason Ltd
  • 2. About this talk ● Covers package building – not package management ● Material was collected for a book: “The RPM Handbook” ● Warning: this talk is not exhaustive!
  • 3. Outline of talk ● What is RPM? ● Building RPMs – Dependencies and capabilities – Macros – Running rpmbuild – Anatomy of a specfile – Build scripts – Management scripts and triggers – Evolution of RPM ● Sources of further information
  • 4. What is the significance of packaging? ● Ian Murdoch, founder of Debian, suggested in 2007 that: [Package management is] the biggest advancement Linux has brought to the industry ● Debian and RPM packages evolved at roughly the same time and are comparable in functionality
  • 5. Why is RPM relevant? ● Provides a straightforward, consistent way to manage software and resources – directly or through higher-level tools ● The fundamental building block of distros ● Widespread use: – RPM-based distros (RHEL, Fedora, SLE, openSUSE) – Independent Software Vendors (ISVs) – Packages for internal use ● Well-constructed packages give a professional impression
  • 6. RPM design goals ● Upgradability (easy to install, upgrade and remove packages) ● Powerful querying ● System verification ● Pristine sources (start with original, “upstream” source code) ● Reproducible builds
  • 7. Issues with RPM ● Poorly documented ● Shows signs of age – but it is evolving ● Enterprise distributions lag behind latest developments (newer features often not available for several years) ● Many packaging details are distribution-specific (see Fedora, openSUSE and Mandriva packaging guidelines) ● Information and misinformation on the internet
  • 8. Versions of RPM in use Version Date Used by (EOL) 4.4.2 2005-07-21 SUSE 10 4.4.2.3 2008-04-01 RHEL 5 (2017/2020), SUSE 11 4.8.0 2010-01-08 RHEL 6 (2020/2023) 4.9.1.2 2011-09-29 OpenSUSE 12.2 (2014) 4.9.1.3 2012-04-03 Fedora 17 (2013) 4.10.1 2012-10-03 Fedora 18 (2014) 4.11.1 2013-02-01 ● These are just the versions still in use by major distributions. ● Prior to 2005 RPM development languished. ● Version 4.4.2 is the first version of the relaunched rpm.org ● In 2006 RPM was forked by the previous developer – rpm5 is only used by Mandriva
  • 9. What does RPM consist of? ● Package file format (.rpm and .srpm) contains metadata and payload ● Package database (/var/lib/rpm/*) information on installed packages ● Configuration files (/etc/rpm/* and /usr/lib/rpm/*) ● Run-time admin tools (rpm command) ● Build tools (rpmbuild command) ● Libraries used by tools such as yum and the rpm tools themselves
  • 10. What does RPM do? ● Installs, erases and updates packages ● Reports on what packages are installed ● Verifies installed packages ● Checks dependencies within sets of packages being installed, upgraded or removed ● Underpins higher-level packaging tools – e.g. YUM, PackageKit, Zypper (these resolve dependencies, as well as checking) ● Provides a package build tool (rpmbuild)
  • 11. Building RPM packages ● Dependencies ● Macros ● The build environment ● The build process ● Scriptlets, Scripts, and Triggers
  • 12. Dependencies ● Dependency tracking is fundamental to packaging systems ● Ensures that software being installed has all its prerequisites ● Ensures that packages aren't inadvertently removed while other packages depend on them ● Differentiate between dependency checking and dependency solving
  • 13. Dependencies (2) ● Packages provide “capabilities” (text strings) ● One automatic capability is the name of the package ● Special capabilities: – rpmlib(feature) – interp(Module) – e.g. perl(Class::Accessor) ● Requirements can specify versions of capability: op [epoch:]version[-release]
  • 14. Version comparison rules ● Epoch - integer comparison ● Version and release: – Split into numeric and alpha substrings and compared substring by substring (separators ignored) – Leading zeroes ignored – Longer substring or sequence is newer – e.g.: ● 1.0010 > 1.9 ● 1a > 1B ● 3:1.0 > 2:99.999 ● 1.2.3abc = 1_2_3_abc
  • 15. RPM macros ● Macro values control all rpm tools (rpmbuild, rpm, etc) e.g.: – %_topdir defines build directory (~/rpmbuild) – %_binary_payload defines payload format and compression ● Defaults defined in /usr/lib/rpm/macros ● About 250 macros – another 80 commented out
  • 16. RPM macros (2) Can be defined: ● In macro files (/usr/lib/rpm/macros, /etc/rpm/*, ~/.rpmmacros) ● On the command line – for all commands (-D 'name definition') ● In spec files – %global name[(args)] expansion – %define name[(args)] expansion ● By rpmbuild internally – e.g. Name tag causes %name macro to be defined with the tag's value Note: parameterized macros definitions are evaluated twice (on definition and use), simple macros are evaluated once (on definition)
  • 17. RPM macros (3) ● Usage %name or %{name} – note: if the macro is not defined you get literal string in output ● Conditionals: – %{?name[:expansion]} – %{!name:expansion} – %if expr ... %else ... %endif – %ifarch / %ifnarch / %ifos / %ifnos ● Shell escape: %(command arg ...) ● Messages: %{echo: msg} (also warn and error) ● Dump all definitions: %dump
  • 18. Building RPMs ● Packages are normally built from sources and patches ● Aimed at software that follows GNU Coding Standard (autoconf/automake, etc) – works best if you don't fight it ● RPM packages built with rpmbuild command (-ba option to build everything) ● Controlled by “spec file” (which may be located within tar file – use -ta) ● Spec file can define multiple packages ● Spec file specifies build requirements (can be installed with yum-builddep – from yum-utils)
  • 19. Build process ● rpmbuild initializes itself from macro files (/etc/rpm/*, /usr/lib/rpm/macros, ~/.rpmmacros) ● Reads spec file, expanding macros as it goes ● Steps through build stages specified by spec file ● Determines dependencies and capabilities provided ● Constructs binary RPM and/or source SRPM ● Note: – never build as root! – always test RPMs on a clean system or with mock to identify unspecified dependencies (which may be satisified by s/w installed on the build system)
  • 20. Build environment ● Build area is a directory hierarchy – location specified by %_topdir (~/rpmbuild) – SPECS/ (%__specdir) – SOURCES/ (%__sourcedir) – BUILD/ (%__builddir) – BUILDROOT/ (%__buildroot) – RPMS/ (%__rpmdir) – SRPMS/ (%__srcrpmdir) ● Setup directories under $HOME with rpmdev-setuptree (from rpmdevtools package)
  • 21. Spec files ● Complete specification of package ● Defines meta data for package (name, version, release, license, etc) ● Specifies dependency information ● Describes software build process ● Provides a manifest of the files to be installed ● Provides scripts for package install/erase ● Note: clumsy syntax – %thing may be a macro, a spec file section or an file attribute depending on context ● Comments are marked with “#”, but macros within comments are expanded – which can cause problems
  • 22. Spec file sections ● Preamble (subpackage preambles introduced by %package) ● Package description (%description) ● Build script sections (%prep, %build, %install, %check, %clean) ● Run-time scripts (%pre, %post, %preun, %postun, %pretrans, %posttrans, %verify) ● Trigger scripts (%triggerprein, %triggerin, %triggerun, %triggerpostun) ● Files manifest (%files) ● Change log (%changelog) Subpackages have separate description, run-time scripts, triggers and manifests (sections qualified with subpackage suffix or full name)
  • 23. ~/rpmbuild/ (%_topdir) RPMS/ pkg.spec SPECS/ SOURCES/ BUILD/ BUILDROOT/ Name: pkg Version: 1.0 Release: 1 %prep %setup -q %build configure make %install make install %files
  • 24. Example spec file Name: hello Version: 2.7 Release: 1%{?dist} Summary: GNU 'hello world' program Group: Miscellany Vendor: Free Software Foundation License: GPLv3 URL: http://www.gnu.org/software/hello/ BuildRoot: %{_tmppath}/%{name}-root-%(%{__id_u} -n) Requires: info Source0: %{name}-%version.tar.gz %description GNU Hello produces a familiar, friendly greeting. The practical purpose Of GNU Hello is to serve as a minimal example of a GNU package. %prep %setup -q %build %configure make %install make install DESTDIR=$RPM_BUILD_ROOT
  • 25. ExamplesSpec file (continued) %clean rm -rf $RPM_BUILD_ROOT %post /sbin/install-info %{_infodir}/hello.info.gz %{_infodir}/dir || : %preun if [ $1 = 0 ]; then /sbin/install-info --delete %{_infodir}/hello.info.gz %{_infodir}/dir || : fi %files %defattr(-,root,root,-) %doc README /usr/bin/hello %exclude /usr/share/info/dir %doc /usr/share/info/hello.info.gz /usr/share/locale/*/LC_MESSAGES/hello.mo %doc /usr/share/man/man1/hello.1.gz %changelog * Fri Apr 29 2011 <andrew@ford-mason.co.uk> - 2.7-1 - Initial packaging
  • 26. Spec file preamble ● Consists of key-value records before first section – Name: name of the software package – Version: version number of the upstream source code – Release: number of this release of the software package – Summary: short, one-line description of the package – URL: web site URL for software – License: licence for the software – Group: category the software falls in – Source0: file containing the N'th source file ● Preamble for subpackages specified with %package section ● Info corresponds to output from rpm --query –info ● %description section provides more detailed description
  • 27. Specifying dependencies ● Automatic and manual dependencies (scripts %__find_requires and %__find_provides) ● Packages provide “capabilities” (including one with the name of the package) ● Specify capabilities provided with Provides tag ● Required packages/capabilities with Requires tag ● PreReqs tag is deprecated – use Requires(pre) ● Conflicts specified with Conflicts tag ● SUSE has “soft” dependencies (Suggests and Recommends) – these may come to later versions of rpm
  • 28. Specifying dependencies (2) ● Dependencies and capabilities provided can be – Automatically determined by rpmbuild (and helpers) – Manually specified (%requires, %provides, etc) ● Automatic dependency generators run by rpmbuild after %install section ● Also need to specify build dependencies
  • 29. Build process in detail – %prep ● Unpacks source files and applies patches, e.g.: ● Process often acheived with two “pseudo”-macros: – %setup – unpacks (compressed) tar files into build dir – %patchN – applies patch N %prep %setup -q %patch0
  • 30. Build drocess in detail – %build ● Configures and builds software e.g.: ● %configure runs GNU configure ● make is standard Linux make command %build %configure make
  • 31. Build process in detail – %install ● Installs to the “build root” - a staging area (proxy for the real root directory) ● Installs into build root (proxy for the filesystem root) ● Configure-generated makefiles support $DESTDIR %install make install DESTDIR=$RPM_BUILD_ROOT
  • 32. Debugging RPM build scripts ● rpmbuild creates temporary script files ● Build can be executed up to a certain stage – -bp – stop after %prep – -bc – stop after %build (compile stage – -bi – stop after %install – -bl – do “list check” (expand %files and check everything exists) ● --short-circuit option to skip to stage specified with -bc, -bi or -bb (but makes generated RPM essentially unusable) ● shortrpm program can be used to create installable RPMs skipping prep and build stages – but should only be used in development ● Alternatively “exit 1” to build or install script, and examine and debug the script left in /var/tmp
  • 33. Management scripts ● Scripts run before/after package installation, upgrade and erasure – %pretrans – run at start of transaction – %pre – before package installed – %post – after package installs – %preun – before package uninstalled – %postun – after package uninstalled – %posttrans – at end of transaction – %verifyscript – run by rpm -V ● On upgrade install scripts are run from new version of package, then uninstall scripts from old version ● Install scripts are not interactive – we're not on Debian here!
  • 34. Management scripts (2) ● Uses: – Set up users and groups – Install services and cron jobs, set up alternatives – Refresh dynamic linker bindings (ldconfig) ● Scripts receive argument $1 – says how many instances left at end of operation: – 1 after first install – 2 for install of new version on upgrade – 1 for uninstall of previous version on upgrade – 0 for final uninstall
  • 35. Management scripts (3) ● Scripts can be provided for subpackages (specify name after script tag) ● Interpreter specified with -p program – Default interpreter is /bin/sh – <lua> for built-in lua interpreter (all that is available on %pretrans of first-stage install) – Can specify /sbin/ldconfig if that is all that needs to run – Creates an automatic dependency on interpreter
  • 36. Triggers ● Scripts that run when a target package is installed or uninstalled: – %triggerin – run when target or source package installed/upgraded – %triggerun – run when target or source package is uninstalled – %triggerpostun – run after target package is uninstalled ● e.g.: %triggerin -p /bin/sh – postfix ● Trigger scripts invoked with two arguments: – $1 gives number of instances of source package remaining when trigger completes – $2 gives number of instances of target package remaining
  • 37. File lists ● List of files in package(s) specified by %files ● List can be read from file with -f file ● Attributes specified with %defattr, %attr ● Configuration files marked with %config ● Documentation flagged with %doc (collected and placed in /var/share/doc) ● 4.11 introduces %license to mark license files ● Error if there are unpackaged files in build root
  • 38. Repeatable builds ● BuildRequires specifies packages needed for building ● Building under mock can ensure unspecified dependencies are identified – basic usage: mock –-init chroot-name mock –-root chroot-name –-rebuild package.src.rpm ● Should also test installation of built packages
  • 39. RPM evolves Just a couple of examples (remember RHEL5 uses 4.4.2.3): ● 4.6.0 – BuildRoot tag now silently ignored – Group tag no longer mandatory – %_topdir now $HOME/rpmbuild (was /usr/src/redhat) – New macros %patches and %sources ● 4.7.0 – Support for XZ compression – Group tag in subpackage inherits from main package – New macros %getenv and %getconfdir
  • 40. More changes ● 4.8.0 (used by RHEL6) – Deprecated Copyright tag no longer recognized – PreReq and BuildPreReq are deprecated – New BugUrl tag and %_bugurl macro – New %make_install macro – Macros %PACKAGE_VERSION and %PACKAGE_RELEASE removed (use %version and %release) ● 4.9.0 – New Requires(pretrans) and Requires(posttrans) tags – New OrderWithRequires tag – --sign option to rpmbuild no longer supported (now is a separate command – rpmsign) Release notes on rpm.org have the details
  • 41. And there's more... ● Multilib ● SE Linux policies ● POSIX capabilities ● Software collections ● ● ●
  • 42. Sources of further information ● Man pages for rpm, rpmbuild, etc ● rpm.org ● fedoraproject.org/wiki/ Category:Package_Maintainers ● opensuse.org/Portal:Packaging ● wiki.linuxfoundation.org/en/LSB (Linux Standards Base) ● Classic Shell Scripting, Robbins & Beebe (O'Reilly) ● AUTOTOOLS, John Calcote (No Starch Press) ● GNU Coding Standards (Free Software Foundation) ● rpmhandbook.com (coming soon)