Packaging Overview

GSoC Week 8–9 @ScoRe Lab

Dhruvi Doshi
SCoRe Lab
5 min readSep 3, 2022

--

What is package?

A package is simply an archive that combines all the libraries and binaries ,configuration and all the dependencies required to install the programs (i.e application, software or languages)

Why?

Histrionically in UNIX, every program had to write compiled linked and run. Then UNIX got the ability to use libraries (“shared objects”), ELF executables, etc. To solve the task of building more complicated software easily, make was developed. Make uses an makefile we had to create the makefile on our own so this was also a laborious task.

The main problems with make file’s are

  • The specified package is not present on the location.
  • Package is depend on another package.
  • If the downloaded package is not working properly.

The above problem can be solved by manually downloading the package. But there may be an version problem that downloaded package version is differant than we required or does not support.

This is called an “Dependency Hell” which is solved by package manager. How exactly the package manger works and solve all this problem, we discuss in following section.

Package Managers

  1. For a Debian based distribution system i.e. Linux mint , ubuntu , Debian ,pure OS etc. The base package manager is DPKG (Debian package). the frontend package that is generally used is APT its like cherry on the ice-cream top. There are some traditional frontend package managers that is also used with DPKG is APT-GET.
  2. For a RPM based distribution system like fedora, centos ,RHEL , we use Red-hat package managers (rpm) . The base package manager for a RPM based distribution system is RPM. The frontend package managers that is used more often with rpm is YUM ( YELLOW DOG Updater, Modified) .The more advanced version that we uses more often as a frontend package manger is DNF.

dpkg

dpkg is a tool to install, build, remove and manage Debian packages. The primary and more user-friendly front-end for dpkg is aptitude(1). dpkg itself is controlled entirely via command line parameters, which consist of exactly one action and zero or more options. The action-parameter tells dpkg what to do and options control the behavior of the action in some way.

dpkg suite

dpkg — Debian’s package maintenance system

This is the dpkg suite of programs that form the foundation of the Debian’s
package management system; on the lower layer there are ‘dpkg-deb’ and
‘dpkg-split’ programs handling the binary formats, and ‘dpkg-source’ program
handling the source formats; there is a collection of tools to handle building
source packages into binary packages; there is the medium-level and less
user-friendly command-line interface (CLI) in the form of the ‘dpkg’ command;
and then there is the terminal user interface (TUI) ‘dselect’ program (which
has gone out of preference in favor of the apt (CLI) and aptitude (TUI)
programs).

The dpkg suite also includes some other programs currently maintained
on external repositories, namely ‘dpkg-repack’, ‘dpkg-www’, ‘dupload’
and ‘debsig-verify’.

.deb

A deb file is an archive that contains data. Marked with the .deb extension, it is used to easily distribute and install programs for Linux Debian and derivatives. Deb files are handy when your app needs to take care of additional dependencies, integrate itself with the desktop, run pre and post install scripts and so on.

Internally, a deb package contains a collection of folders that mimics a typical Linux file system, such as /usr, /usr/bin, /opt and so on. A file put in one of those directories will be copied to the same location in the actual file system during installation. So, for example a binary file put into <.deb>/usr/local/bin/binaryfile will be installed to /usr/local/bin/binaryfile.

Source directory

package contains the following files in its debian/ directory:

  • changelog
  • compat
  • control
  • copyright
  • docs
  • node-libravatar.install
  • rules
  • source/format
  • watch

A very good reference apart from the official documentation is this:

https://feeding.cloud.geek.nz/posts/whats-in-a-debian-directory/

Binary directory

Create a temporary working directory to make your package in. On the outside instead, all deb package files follow a specific naming convention:

That is:

  • <name> – the name of your application;
  • <version> – the version number of your application;
  • <revision> – the version number of the current deb package;
  • <architecture> – the hardware architecture your program will be run on.

Put your program files where they should be installed to on the target system. For example, suppose you want your program to be installed to /usr/local/bin:

The -p flag to the mkdir command will create nested directories. Then copy the executable file in there:

The control file lives inside the DEBIAN directory. Mind the uppercase: a similar directory named debian (lowecase) is used to store source code for the so-called source packages. This tutorial is about binary packages, so we don't need it.

Let’s create the DEBIAN folder first:

And then create the empty control file:

Open the file previously created with your text editor of choice. The control file is just a list of data fields. For binary packages there is a minimum set of mandatory ones:

  • Package – the name of your program;
  • Version – the version of your program;
  • Architecture – the target architecture;
  • Maintainer – the name and the email address of the person in charge of the package maintenance;
  • Description – a brief description of the program.

For example:

The control file may contain additional useful fields such as the section it belongs to or the dependency list. The latter is extremely important in case your program relies on external libraries to work correctly. You can fill it manually if you wish, but there are helper tools to ease the burden. I will show you how in the next few paragraphs.

Building

This is the last step. Invoke dpkg-deb as following:

So in our example:

The --root-owner-group flag makes all deb package content owned by the root user, which is the standard way to go. Without such flag, all files and folders would be owned by your user, which might not exist in the system the deb package would be installed to.

The command above will generate a nice .deb file alongside the working directory or print an error if something is wrong or missing inside the package. If the operation is successful you have a deb package ready for distribution.

Installation

Final words

Now that we know packaging we will see different ways of packaging of python application in the next blog.

References

  1. https://medium.com/@knoldus/working-of-package-manager-in-linux-775ca131c388
  2. https://sauravstwt.medium.com/package-management-in-linux-7db916968247
  3. https://www.internalpointers.com/post/build-binary-deb-package-practical-guide
  4. https://feeding.cloud.geek.nz/posts/whats-in-a-debian-directory/
  5. https://www.senties-martinelli.com/articles/debian-packages
  6. https://github.com/FooBarWidget/debian-packaging-for-the-modern-developer

--

--