=====================
== avisiblenetwork ==
=====================
seeing the invisible

Software Packaging 101 with Deb Files

Use Case

Installing a package to use an application or updating with apt update && apt upgrade -y are common activities for all linux users, but this central activity is a nuanced process with great variability across distributions. As I prepare for the LFS203 exam, I wanted to look into what package management is and thought a good place to start is building a simple package and installing it locally. I followed the steps outlined by Debian (who defines the rules of creating deb files for installing packages on Debian-based distributions).

What am I trying to do?

When installing applications that other people have created, there should be a streamlined method of installing those applications on one’s system to make it easy to use. This is where a package becomes useful. It is a compilation of files that are “packaged” and distributed over networks, so you can use those applications on your system. The distribution’s maintainers will often look at the source code of an application, and modify the code and compile it in a way that fits into the distribution’s logic and your local system’s architecture, and distributes this version in their repositories. It is a great way to standardize application distribution.

Steps

https://wiki.debian.org/MakeAPrivatePackage

Source Code Compilation

I created a directory to store my source code.

mkdir -p my_package_dayoftheyear/usr/bin/

I wrote a short bash script to print the day of the year.

vim my_package_dayoftheyear/usr/bin/doty.sh

#!/bin/sh

echo "Day $(date +'%j') of $(date +'%Y')"

I gave permission to all users to execute the script.

chmod 755 my_package_dayoftheyear/usr/bin/doty.sh

I created a DEBIAN directory that stores metadata in the control file:

mkdir my_package_dayoftheyear/DEBIAN/control

Package: doty
Architecture: all
Version: 1.0.0
Section: misc
Maintainer: Andrew <andrew@avisiblenetwork.com>
Priority: optional
Standards-Version: 4.7.0
Description: Print Day of the year to standard output.

Build the package

Make sure you point to the directory that contains the DEBIAN directory to build the package: dpkg-deb --build my_package_dayoftheyear

andrewtest@lfs203-ubuntu:~$ dpkg-deb --build my_package_dayoftheyear/
dpkg-deb: building package 'doty' in 'my_package_dayoftheyear.deb'.

Get information of deb file:

andrewtest@lfs203-ubuntu:~$ dpkg --info my_package_dayoftheyear.deb
 new Debian package, version 2.0.
 size 626 bytes: control archive=253 bytes.
     208 bytes,     8 lines      control
 Package: doty
 Architecture: all
 Version: 1.0.0
 Section: misc
 Maintainer: Andrew <andrew@avisiblenetwork.com>
 Priority: optional
 Standards-Version: 4.7.0
 Description: Print Day of the year to standard output.

Install and Use the Command

Install the deb file locally:

andrewtest@lfs203-ubuntu:~$ sudo dpkg -i my_package_dayoftheyear.deb
[sudo] password for andrewtest:
Selecting previously unselected package doty.
(Reading database ... 73099 files and directories currently installed.)
Preparing to unpack my_package_dayoftheyear.deb ...
Unpacking doty (1.0.0) ...
Setting up doty (1.0.0) ...

Use the command locally now:

andrewtest@lfs203-ubuntu:~$ doty.sh
Day 160 of 2025.

Where is the command:

andrewtest@lfs203-ubuntu:~$ which doty.sh
/usr/bin/doty.sh

Remove package:

andrewtest@lfs203-ubuntu:~$ sudo dpkg --remove doty
(Reading database ... 73098 files and directories currently installed.)
Removing doty (1.0.0) ...

Using apt (the higher-level package manager vis-a-vis dpkg):

andrewtest@lfs203-ubuntu:~$ sudo apt install ./my_package_dayoftheyear.deb
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'doty' instead of './my_package_dayoftheyear.deb'
The following NEW packages will be installed:
  doty
0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded.
Need to get 0 B/626 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 /home/andrewtest/my_package_dayoftheyear.deb doty all 1.0.0 [626 B]
Selecting previously unselected package doty.
(Reading database ... 73099 files and directories currently installed.)
Preparing to unpack .../my_package_dayoftheyear.deb ...
Unpacking doty (1.0.0) ...
Setting up doty (1.0.0) ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
N: Download is performed unsandboxed as root as file '/home/andrewtest/my_package_dayoftheyear.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)

The download process of dpkg and apt are essentially the same.

What I Learned

I never looked beyond apt install [application] previously, so I took a peak into the layers of software delivery and the building block of a working Linux system. I have been wanting to dive into Gentoo Linux because I hear it is customizable. I understand that it is highly customizable because you decide from source code which features you want to enable/disable, and you compile the code to create the binary file to be used on your system. You are not using the distribution’s maintainer’s version and actually deciding compile-time options for yourself that is suitable for your system. You, in a sense, become the maintainer of your own system at the application level.

Takeaways

Creating packages can get complicated fast, so starting with a simple program with no dependencies may be the first step in understanding packages and software delivery.

What Next?

I will look into software dependencies and how package managers deal with dependencies.