Skip to content

Latest commit

 

History

History
355 lines (286 loc) · 11.6 KB

File metadata and controls

355 lines (286 loc) · 11.6 KB

RPM

Books

TODO

  • Signing packages

Setup

Might need to install rpmbuild:

sudo yum install -y rpm-build

Commands

Building packages (ref) with rpmbuild

cd /usr/src/redhat/SPECS

# -ba build binary and source packages 
rpmbuild -ba cdplayer-1.0.spec

# -bb build binary package (after %prep, %build, %install)q
rpmbuild -bb cdplayer-1.0.spec

# Test the build (don't build anything, but parse and check for errors)
rpmbuild -bb --nobuild my.spec

# Clean up - remove the build tree when complete
rpmbuild --clean my.spec

# Use --define='MACRO EXPR' to define MACRO with value EXPR
rpmbuild -bb --define "release ${ARTIFACT_BUILD_NO}" \
  --define "%_topdir ${WORKSPACE}" SPECS/my.spec

# Check the %files list for missing files (because it is manually created and might be incorrect)
rpmbuild -bl -vv cdplayer-1.0.spec

# Check for files over 1 hour old (3600 seconds) 
rpm -bl --timecheck 3600 cdplayer-1.0.spec

Short-circuiting builds (to speed up development of a spec file)

# Just run %build (skipping %prep) from specfile
rpmbuild -bc --short-circuit SPECS/my.spec

# Just run %install (skipping %prep and %build) from specfile
rpmbuild -bi --short-circuit SPECS/my.spec

Installing packages (ref)

rpm -i file.rpm

Uninstalling packages (incl. pre and post) (ref)

rpm -e pgk

Viewing metadata in an .rpm file (ref)

rpm -qp -i /repo/Centos/5.9/APPS/jdk-7u7-linux-x64.rpm 

Listing the files in an .rpm file (SO)

rpm -qlp firefox41-1.0-1.x86_64.rpm

View the lifecycle scriplets within an RPM (ref)

rpm -qp --scripts firefox41-1.0-1.x86_64.rpm

Add a file to a repo

# Copy .rpm into repository directory
# (Make sure it is readable by all, otherwise you'll get 403 Forbidden when accessing it!)
# then:
createrepo --update -s sha1 5.9/STABLE/

Yum

List installed packages (ref)

yum list installed

Show available versions of a package (SO):

yum --showduplicates list jdk

Show the packages that provide a given file (ref)

yum provides /sbin/service

List available repositories

yum listrepos

Add a repository

echo -e "[apps]\n\
enabled=1\n\
baseurl=http://my-repo.com/\n\
gpgcheck=0\n\
name=My yum repo" > /etc/yum.repos.d/my.repo && yum upgrade

Expire the yum repo cache (to see newly added files) (SO)

yum clean expire-cache

Or edit /etc/yum.conf to say metadata_expire=1m (defaults to 90 mins) (SO)

Creation

Directory structure (ref), default parent of /usr/src/redhat:

  • SOURCES - Original sources, patches, and icon files.
  • SPECS - Spec files used to control the build process.
  • BUILD - The directory in which the sources are unpacked, and the software is built.
  • RPMS — Binary package files created by the build process.
  • SRPMS — Source package files created by the build process.

Spec File format

  • Comments: # comment
  • Macro expansion, using %{MACRO_NAME}:
# Where release was defined on the command line as --define "release 3"
Release: %{release}

Preamble (ref):

Only name, version, release, and source actually affect the packaging process - the package name is always: <name>-<version>-<release>

#
# Example spec file
#
Summary: A CD player app that rocks!
Name: cdplayer

# Version of the software being packaged
Version: 1.0

# Package's version umber (how many times the software at its present version has been released,
# start at 1, and reset to 1 when there is a new Version)
Release: 1

Copyright: GPL
Group: Applications/Sound

# Name of the source file (basename of value), and where the source file is obtained
# (though RPM will not download them)
# Specify Source0, Source1, ... if there are more than one source file.
Source: ftp://ftp.gnomovision.com/pub/cdplayer/cdplayer-1.0.tgz

# Documentation of the software being packaged
URL: http://www.gnomovision.com/cdplayer/cdplayer.html
Distribution: WSS Linux
Vendor: White Socks Software, Inc.
Packager: Santa Claus <sclaus@northpole.com>

%description
It slices!  It dices!  It's a CD player app that
can't be beat.  By using the resonant frequency
of the CD itself, it is able to simulate 20X
oversampling.  This leads to sound quality that
cannot be equaled with more mundane software...

Tag reference

Locations:

  • Buildroot - staging area that looks like the final installation directory (which is usually /). Can be overridden by with the --buildroot command-line parameter.
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root

Dependency tags:

Provides: mail-reader
Requires: playmidi >= 2.3
# Packages that cannot be installed (with release number)
Conflicts: playmidi = 2.3-1

Common variables:

RPM_SOURCE_DIR="/usr/src/redhat/SOURCES"
RPM_BUILD_DIR="/usr/src/redhat/BUILD"
RPM_DOC_DIR="/usr/doc"
RPM_OPT_FLAGS="-O2 -m486 -fno-strength-reduce"
RPM_ARCH="i386"
RPM_OS="Linux"
RPM_ROOT_DIR="/tmp/cdplayer"
RPM_BUILD_ROOT="/tmp/cdplayer"
RPM_PACKAGE_NAME="cdplayer"
RPM_PACKAGE_VERSION="1.0"
RPM_PACKAGE_RELEASE="1"

%prep

Remove remnants of any previous builds, and prepare the BUILD directory (as a sh script).

%prep
rm -rf $RPM_BUILD_DIR/cdplayer-1.0
zcat $RPM_SOURCE_DIR/cdplayer-1.0.tgz | tar -xvf -

Setup macro (ref)

  • changes to BUILD, and extracts the source files (tar, zip, gzip, tar-gzip bzip2, pack, compress, lzh).
%prep
%setup

# Create the directory before unpacking (if not in archive)
%setup -c -n name -q

%build

Perform the build as a sh script.

%build
make

%configure macro sets many environment variables (ref), view them with:

rpm --eval '%configure'

%install

Install the application, as a sh script.

%build
make install

%clean

Clean up files that are not part of an application's normal build area (e.g. `/tmp'). e.g. if you set a buildroot (ref):

%clean
rm -rf $RPM_BUILD_ROOT

Install/Erase-time scriptlets ref

Argument $1 is the number of times the package has been installed after the operation has completed (e.g. %pre and %post will have $1=1 for the first installation, and %preun and %postun will have $1=0 for the last uninstallation)

  • %pre - Executes just before the package is to be installed.
  • %post - Executes just after the package has been installed.
  • %preun - Executes just before the package is uninstalled.
  • %postun - Executes just after the package is uninstalled.

Should always exit with a status of 0, unless there is a serious error (and letting it proceed would be worse) ref and ref.

exit 0
# or
my last command || :

e.g.

%post
/sbin/chkconfig --add ypbind

%preun
if [ "$1" = 0 ] ; then
  /sbin/service ypbind stop > /dev/null 2>&1
  /sbin/chkconfig --del ypbind
fi
exit 0

%postun
if [ "$1" -ge 1 ]; then
  /sbin/service ypbind condrestart > /dev/null 2>&1
fi
exit 0

%verifyscript

%files

List the files that are part of the package (full paths, which will also be their destination when installed).

Files can have directives

%files
# Mark a file as docuemntation (placed in a package-specific directory
# in /usr/doc/<package-name-version>)
%doc README
/usr/local/bin/cdp
/usr/local/bin/cdplay
/usr/local/man/man1/cdp.1

# Set attributes (if not installed with those attributes):
# %attr (<mode>, <user>, <group) file
%attr(755, root, root) foo.bar
            
# Use - to avoid changing an attribute (because it was intalled with that attribute)
# e.g. don't set the file's user:
%attr(755, -, root) foo.bar

# Only include the directory and not its contents
%dir /usr/blather

# Also: %config, %docdir, %verify, %files -f <file>

%changelog (ref)

Appears at the end of a spec file, listing significant changes:

%changelog
* Fri Jun 21 2002 Bob Marley <marley@redhat.com>
- automated rebuild
* Tue May 08 2001 Peter Tosh <tosh@redhat.com> 1.3-1
- updated to 1.3

Macros

Services