A smattering of useful commands for dealing with package managers!

Frontends

Package manager front-ends are the programs used to use the package manager, for Debian these are apt, apt-get & dpkg; for CentOS these are yum, dnf & rpm.

List all packages

Dpkg shows a columnar table showing package state, version, uarch and description. The package list is sorted alphabetically.

RPM does not sort the output, and only shows package name, version and uarch, which are all included in the RPM package name.

> dpkg -l
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                          Version                                      Architecture Description
ii  accountsservice                               0.6.45-2                                     amd64        query and manipulate user account information
ii  accountwizard                                 4:18.08.3-1                                  amd64        wizard for KDE PIM applications account setup
ii  acl                                           2.2.53-4                                     amd64        access control list - utilities
ii  adduser                                       3.118                                        all          add and remove users and groups
> rpm -qa
> rpm -qa | head
dmz-icon-theme-cursors-11.3.0-1.22.noarch
libproxy1-0.4.15-4.3.1.aarch64
libIlmImf-2_2-23-2.2.1-3.21.1.aarch64
xcb-proto-devel-7.6_1.13-1.10.aarch64

List files provided by a package

)> dpkg -L openssh-server
/.
/etc
/etc/default
/etc/default/ssh
> rpm -ql openssh
/etc/pam.d/sshd
/etc/ssh
/etc/ssh/moduli

List packages that include a filename

> dpkg -S inotifywait
inotify-tools: /usr/share/man/man1/inotifywait.1.gz
inotify-tools: /usr/bin/inotifywait
...

List enabled repos

> dpkg ...
> yum repolist

Show scriptlets

Packages can run small shell scripts as part of their install and removal.

> rpm -qp --scripts package.rpm
postinstall scriptlet (using /bin/sh):
...
preuninstall scriptlet (using /bin/sh):
...
postuninstall scriptlet (using /bin/sh):
...

Update except for …

> apt-mark hold openssl
> apt dist-upgrade
> apt-mark unhold openssl

> yum update --exclude=openssl

Extract files

> dpkg -x package.deb .

> rpm2cpio package.rpm | cpio -idmv

Build process

RPM

RPMs are build using rpmbuild on a build directory which is defined by ~/.rpmmacros, some directives being:

  • $_topdir /home/joe/rpmbuild - Where rpmbuild will look for sources and produce RPMs.
  • %_tmppath $_topdir/temp - A location for temporary files, perhaps place it in /tmp/ to ensure it gets cleared.
  • %dist .heaton - This is inserted after the version number to denote the package variant.

The rpmbuild/ directory structure:

  • BUILD
    • Axiom
  • RPMS
    • Output completed RPM
  • SOURCES
    • Files to be packaged in RPM
  • SPECS
    • Configuration & scripting for the RPM build
  • SRPMS
    • Conveniently extract or reproduce an existing RPM from its Source RPM
%define _prefix /usr/local/bin/

Name:        nano
Version:     2.8.6
Release:     1%{?dist}
Summary:     a user-friendly editor, a Pico clone with enhancements

Group:       applications/editors
URL:         https://nano-editor.org/
License:     GPLv3+
Vendor:      GNU Project

Source0:     %{name}-%{version}.tar.xz

BuildRoot:   %{_tmppath}/%{name}-%{version}-buildroot
BuildArch:   x86_64
BuildRequires: autoconf, automake, gettext-devel, ncurses-devel, texinfo

%description
GNU nano is a small and friendly text editor.  It aims to emulate the
Pico text editor while also offering several enhancements.

%prep
%setup -q -n %{name}-%{version}

%build
tar -xf "%{SOURCE0}" --strip-components=1

%configure
make

%pre

%install
make install DESTDIR=$RPM_BUILD_ROOT

mkdir -p %{buildroot}/opt/ukmo/nano/%{version}
mkdir -p "%{buildroot}/opt/metoffice/modulefiles/nano-%{version}"
%{__install} -m 0644 -D "%{SOURCE1}" "%{buildroot}/opt/metoffice/modulefiles/nano/%{version}"

%clean
rm -rf "%{buildroot}"

%post

%files
${_prefix}/nano

%changelog
* Fri Jan 01 2016 Joe Heaton <[email protected]> - 1.2.3-0
- Initial Version