Package management
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:
- https://blog.heckel.xyz/2015/10/18/how-to-create-debian-package-and-debian-repository/
- https://www.linux.com/news/make-your-own-packages-debian-based-systems
- debian dpkg https://www.tecmint.com/dpkg-command-examples/
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:
- https://blog.packagecloud.io/eng/2015/10/13/inspect-extract-contents-rpm-packages/
- using rpm on Debian https://wiki.debian.org/RPM
- installing rpm on debian using alien https://wiki.debian.org/RPM
rpm2cpio package-name.rpm | cpio -idmv somedir
Using rpms https://linuxgazette.net/68/nazario.html
- yum cheatsheet media:yum-cheat.pdf https://access.redhat.com/sites/default/files/attachments/rh_yum_cheatsheet_1214_jcs_print-1.pdf
- redhat yum stuff https://www.digitalocean.com/community/tutorials/how-to-set-up-and-use-yum-repositories-on-a-centos-6-vps
- redhat https://www.tecmint.com/20-practical-examples-of-rpm-commands-in-linux/
- yum https://www.tecmint.com/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement/
# yum search package_name # yum search all package_name # yum whatprovides ?*/package_name?
- difference between yum and rpm https://unix.stackexchange.com/questions/157448/difference-between-yum-update-vs-yum-install
- rpm command examples https://www.tecmint.com/20-practical-examples-of-rpm-commands-in-linux/
- rpm inspecting scripts https://blog.packagecloud.io/eng/2015/10/13/inspect-extract-contents-rpm-packages/
rpm -q --scripts <packagename.rpm> rpm -qlp --scripts <packagename.rpm>
yum server
A yum server manages meta-data and serves up installation packages:
- https://www.howtoforge.com/creating_a_local_yum_repository_centos
- https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/sec-yum_repository
- https://www.tecmint.com/setup-local-http-yum-repository-on-centos-7/
- https://www.thegeekdiary.com/centos-rhel-how-to-create-and-host-yum-repository-over-httpd/
- from iso https://access.redhat.com/discussions/1598183
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
making packagesSince 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/
fpmNow 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
it is possible to generate packaging on various host operating systems.
Install fpm
sudo apt-get update sudo apt-get install ruby-dev build-essential sudo gem install fpm
sudo yum install ruby-devel gcc make rpm-build sudo gem install --no-ri --no-rdoc fpm
Install rpmbuild
sudo apt install rpm sudo apt install rpm-build via makeTo 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 formatsrpm
rpm -qlpv ./packagecloud-test-1.1-1.x86_64.rpm
rpm2cpio ./package.rpm | cpio -idmv appimagePortable application image references
categories |
