Package management

From regional-training

Introduction

Package management and repositories make software distribution easier. However, different systems have different package formats, package managers and repositories. Debian uses .deb files that are managed by dpkg and apt with repositories served via ftp or http, and redhat has .rpm files managed by rpm, and yum with their repository server being files typically served via a web-server, or local file system.

Packages may make executable code or source easily distributable, particularly as dependencies are usually listed, and pre and post installation scripts can be included.

debian

A deb file is a standard Unix archive that contains two bzipped or gzipped archives, one for the installer control information and another for the actuall installable data. Debian also provides micro debian packages .udeb which only contain essential functional files.

You may read about debian packaging with the following links:

aptitude update && aptitude search package_name

You can listinstalled packages via

sudo apt list --installed
sudo dpkg-query -l

sudo dpkg-query -l

redhat/CentOS

The rpm format is similar to cpio archives with header and meta-data information. You may read about redhat packaging referring to these links:

rpm2cpio package-name.rpm | cpio -idmv somedir

Using rpms https://linuxgazette.net/68/nazario.html

# yum search package_name
# yum search all package_name
# yum whatprovides ?*/package_name?
 rpm -q --scripts <packagename.rpm>
 rpm -qlp --scripts <packagename.rpm>

yum server

A yum server manages meta-data and serves up installation packages:

A yum repo may be updated via rsync

rsync -rz --progress rsync://mirror.csclub.uwaterloo.ca/centos/os/x86_64/ /repos/CentOS/6/5/

Popular repos

Opening and Converting

The yum cheatsheet is available media:yum-cheat.pdf

I installed a yum repository on my host OS

http://localhost:82/repo/

Accessible from the guests OS on:

http://192.168.122.1:82/repo



working with yum repositories

To work with yum repositories it is a good idea to install yum-utils

  • to obtain the yum-config-manager
yum install yum-utils

You place repository config files within /etc/yum.repos.d e.g.

  • dst.repo
  • redhat.repo

These repository configurations need to be enabled via e.g.

yum-config-manager --enable redhat.repo

NOTE: There is a repos executing on the host listening on 192.168.122.1:82.

Note the port needs to be included in all the corresponding urls in /etc/repos.d/dst.repo file. e.g.

baseurl = http://192.168.122.1:82/repo.rhel-7-server-rt-rpms

List repositories via

yum repolist

Then you may search through the repositories for rpms:

See also yum server.

Yum repositories may be copied with reposync: reposync --gpgcheck -l --repoid=rhel-proxy:rhel-server-rhscl-7-rpms --download_path=/var/local

Package management cheat sheet

TODO update to include all popular distro packagemanagers from https://distrowatch.com/dwres.php?resource=package-management

Task apt (deb)
Debian, Ubuntu
zypp (rpm)
openSUSE
yum/dnf (rpm)
Fedora, CentOS
urpmi (rpm)
Mandriva, Mageia
Managing software        
Install new software from package repository apt-get install pkg zypper install pkg dnf install pkg urpmi pkg
Install new software from package file dpkg -i pkg zypper install pkg dnf localinstall pkg urpmi pkg
Update existing software apt-get install pkg zypper update -t package pkg dnf update pkg urpmi pkg
Remove unwanted software apt-get remove pkg zypper remove pkg dnf erase pkg urpme pkg
Updating the system        
Update package list apt-get update
aptitude update
zypper refresh dnf check-update urpmi.update -a
Update system apt-get upgrade
aptitude safe-upgrade
zypper update dnf update urpmi --auto-select
Searching for packages        
Search by package name apt-cache search pkg zypper search pkg dnf list pkg urpmq pkg
Search by pattern apt-cache search pattern zypper search -t pattern pattern dnf search pattern urpmq --fuzzy pkg
Search by file name apt-file search path zypper wp file dnf provides file urpmf file
List installed packages dpkg -l zypper search -is rpm -qa rpm -qa
Configuring access to software repositories        
List repositories cat /etc/apt/sources.list zypper repos dnf repolist urpmq --list-media
Add repository (edit /etc/apt/sources.list) zypper addrepo path name (add repo to /etc/yum.repos.d/) urpmi.addmedia name path
Remove repository (edit /etc/apt/sources.list) zypper removerepo name (remove repo from /etc/yum.repos.d/) urpmi.removemedia media

making packages

Since there are several package formats, and several managers depending on various operating systems and libraries, it is problematic to make and package code for each target system in one lot of scripts. For more details on various packages see the management https://www.tecmint.com/linux-package-management/

fpm

Now here I introduce fpm', a promising tool, because it can make packages for various host operating systems.

fpm can also convert and generate between various package formats, depending on some constraints, for example it is not possible to generate a .rpm package on debian unless rpmbuild is compiled and installed on Debian. (rpmbuild is a redhat specific package generator). It is however possible to convert from dir format to .deb or .rpm on the various target systems.

With fpm using -s dir and -t xxx, where xxxx is one of

  • rpm // for redhat or CentOS
  • deb // Debian or Ubuntu
  • tar // a tarball
  • zip // a zip file
  • sh // self-extracting sh file
  • osxpkg // for OS X
  • solaris // for Solaris
  • puppet // for puppet
  • pkgin // for BSD systems

it is possible to generate packaging on various host operating systems.

Install fpm

  • on Debian
sudo apt-get update
sudo apt-get install ruby-dev build-essential
sudo gem install fpm
  • on redhat
sudo yum install ruby-devel gcc make rpm-build
sudo gem install --no-ri --no-rdoc fpm

Install rpmbuild

  • on Debian
sudo apt install rpm
sudo apt install rpm-build

via make

To illustrate a case in point, this is how I setup the makefile for chrole and chdsg to generate packaging on the development (Debian) and host systems (Redhat):

#######################################################################################################################################
#
# This is the production makefile - please note that there is no optimisation, and that we have included the debug symbols and
# its OK to release like that. We don't need any optimisation, or consequential code change, because this is security software
# and we want it to work as intended and we need to be able to analyse a core dump should it crash.
#
# History:
# 20190222 Ralph Holland        include deb and rpm targets for generating packaging on debian and redhat systems
# 20190217 Ralph Holland        included std=c++11 in CPPFLAGS and fixed error in call to variadic function SysLogger.log
# 20190213 Ralph Holland        separated the chds and chrole into ./main and have separate CC rules for them
#                                                       included remaining source and includes in ./src
#                                                       incorporate the objects int ./obj
#                                                       incorportate the bin into ./bin
#                                                       will be putting tests into ./test
#
#######################################################################################################################################
CC                      =g++ -Wall -g3 
CPPFLAGS        := -std=c++11
SRCDIR      := src
INCDIR      := src
BUILDDIR    := obj
TARGETDIR   := bin
RESDIR      := res
SRCEXT      := cpp
DEPEXT      := d
OBJEXT      := o
INC         := -I$(INCDIR) -I/usr/local/include
EUID            := $(shell id -u -r)
SOURCES         := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS         := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT)))
FPM_VERSION     := $(shell fpm --version)
DATE            := $(shell date -u +%Y%m%dT%H%M)
INSTALLDIR      = /usr/local/bin
ACCESS_VERSION          = 1.0
ACCESS_RELEASE          = $(DATE)
ACCESS_NAME                     = access
ARCH                            = x86_64
DESC                            = chrole and chds commands for HPC Data Set group access
.PHONY: setup all install clean
# default rule
all: setup build
deb:    deb-bin deb-src
deb-bin:        all packman setuid
        fpm -s dir -t deb -n $(ACCESS_NAME) -v $(ACCESS_VERSION) --iteration $(DATE) -a $(ARCH) --description '$(DESC)' bin/chrole=/usr/bin/chrole bin/chds=/usr/bin/chds
deb-src:        packman clean
        fpm -s dir -t deb -n $(ACCESS_NAME) -v $(ACCESS_VERSION) --iteration $(DATE) -a src -x bin -x .git -x obj -C ../access
        
rpm:    rpm-bin rpm-src
rpm-bin:        all packman setuid
        fpm -s dir -t rpm --debug -n $(ACCESS_NAME) -v $(ACCESS_VERSION) --iteration $(DATE) -a $(ARCH) --description '$(DESC)' bin/chrole=/usr/bin/chrole bin/chds=/usr/bin/chds
rpm-src:        packman clean
        fpm -s dir -t rpm -n $(ACCESS_NAME) -v $(ACCESS_VERSION) --iteration $(DATE) -a src -x bin -x .git -x obj -C ../access
packman:
        @echo "fpm version [$(FPM_VERSION)]"
ifeq ($(FPM_VERSION),)
        @echo "*** please install ruby fpm ***"
        @exit 1
endif
build: setup bin/chrole bin/chds
        echo "Objects $(OBJECTS) FPM_VERSION=$(FPM_VERSION)"
        
setup:  
        @mkdir -p bin
        @mkdir -p obj
        
setuid: all
ifneq ($(EUID),0)
        @echo "*** Please run make install as root user ***"
        @exit 1
endif
        chown root.root bin/chds bin/chrole
        chmod u+s bin/chds bin/chrole   
install: all setuid
        cp bin/chrole $(INSTALLDIR)  --preserve=mode,ownership,timestamps
        cp bin/chds $(INSTALLDIR)  --preserve=mode,ownership,timestamps
        
clean:
        rm -fr bin $(BUILDDIR)
        rm -fr *.rpm *.deb
        echo Clean done
        
$(BUILDDIR)/%.o: $(SRCDIR)/%.cpp
        @mkdir -p $(dir $@)
        $(CC) -c -o $@ $^ $(CFLAGS) $(INC)  $(CPPFLAGS)
        
$(BUILDDIR)/chrole.o:   main/chrole.cpp $(OBJECT)
        $(CC) -c -o $@ $< $(CFLAGS) $(INC) $(CPPFLAGS)
        
$(BUILDDIR)/chds.o:     main/chds.cpp   $(OBJECT)
        $(CC) -c -o $@ $< $(CFLAGS) $(INC) $(CPPFLAGS)
        
bin/chrole: $(BUILDDIR)/chrole.o $(OBJECTS)
        @mkdir -p $(dir $@)
        $(CC) -o $@ $^ $(CFLAGS) $(INC)
        
bin/chds: $(BUILDDIR)/chds.o $(OBJECTS)
        @mkdir -p $(dir $@)
        $(CC) -o $@ $^ $(CFLAGS) $(INC) 
        

package formats

rpm

rpm -qlpv ./packagecloud-test-1.1-1.x86_64.rpm
  • extracting files
rpm2cpio ./package.rpm | cpio -idmv

appimage

Portable application image

references

50px-Tux.jpg

categories