Debian | Ubuntu | OpenSource | WSO2 | Installers

The Easiest Way to Build Debian Installer for Your Application

Build your debian installer by a single command.

Kosala Sananthana
The Startup

--

The Debian Project is an association of individuals who have made common cause to create a free operating system. This operating system that we have created is called Debian.

If we need to install a program or an application on Debian system we can use a Debian Installer as known as Debian Package. Whether there are many methods are available, using a Debian package is the easiest way for that. 😇

🤔 What is a “Debian Package”?

A Debian package is a collection of files that allow for applications or libraries to be distributed via the Debian package management system. The aim of packaging is to allow the automation of installing, upgrading, configuring, and removing computer programs for Debian in a consistent manner. ( Source: Debian Wiki)

A Debian package consists of one source package component and one or more binary package components. Debian Policy requires that these package files are built with a particular structure and format but there are many methods of arriving at these files.

Source packages not only contain the upstream source distribution and options for the Debian package build system but also lists of run-time dependencies and conflicting packages, a machine-readable description of copyright and license information, initial configurations, etc.

🔧 dpkg-deb

While the goal of packaging is to produce application distribution’s files, however, it will do the initial configuration process also. The binary packages (.deb) will be built for you by tools such as dpkg-deb. dpkg-deb packs, unpacks and provides information about Debian archives. This tool is already available in Debian system.

To build a debian package you can simply use the following command.

dpkg-deb --build binary-directory [archive|directory]

This will create a debian package from the filesystem tree stored in binary-directory. binary-directory must have a DEBIAN sub-directory, which contains the control information files such as the control file itself. This directory will not appear in the binary package’s filesystem archive, but instead the files in it will be put in the binary package’s control information area. It will check the file for syntax errors and other problems, and display the name of the binary package being built. dpkg-deb will also check the permissions of the maintainer scripts and other files found in the DEBIAN control information directory.

If no package is specified then dpkg-deb will write the package into the file binary-directory.deb.If the archive to be created already exists it will be overwritten. If the second argument is a directory then dpkg-deb will write to the file directory/package_version_arch.deb.

As described above the DEBIAN sub-directory should be in the package directory when you build the debian package and DEBIAN sub-directory may contain following files.

  1. control file
  2. maintainer scripts

The usage and the configurations of control file will be discussed in the next section and you can get a basic idea of maintainer scripts and their usage from Introduction to Debian Maintainer Script Flow Charts article. If have not read that please read it before start the next section. It will cover all the debian package processes and configurations.

In this article, I am hoping to build a debian installer for WSO2 API Manager using my automated build script as an example. WSO2 API Manager addresses full API lifecycle management, monetization, and policy enforcement. It allows extensibility and customization and ensures freedom from lock-in and it has been named as a Leader in The Forrester Wave™: API Management Solutions, Q4 2018 Report.

📦 Let’s Build our Debian Installer

First, you need to clone debian installer builder repository to your debian machine and then add needed configurations to it (will describe in the the following section). After that, you only need to run the command to build your application’s installer. Let’s start our journey.

1. Clone debian-installer-builder repository to your local machine. You can clone the repository by the following command. Let’s define the repository’s home as <REPO_HOME>.

git clone https://github.com/KosalaHerath/debian-installer-builder.git

2. Copy your application’s distribution files (which you need to be copied after the installation) to application directory which located at:

<REPO_HOME>/debian-x64/application

As an example, I downloaded WSO2 API binary distribution and unzipped. Then copied all the files to ‘application’ directory.

WSO2 API Manager’s distribution copied to the application directory

3. Modify the following files with your application’s information. You can find these resource files in the following location.

<REPO_HOME>/debian-x64/resources/DEBIAN

contol :

This file contains various values which dpkg, dselect, apt-get, apt-cache, aptitude, and other package management tools will use to manage the package.

control file that contains the package details

You can change the details about the debian package by modifying the above given parameters as necessary. If you want to add more parameters or change the file you can refer this debian document for control file’s parameters.

In this example, I have parameterized the product name and version. However you can change the details as you wish in this file. These details will show in the installation page of the application.

maintainer scripts :

These files are executable scripts which are automatically run before or after a package is installed or removed. The maintainer scripts flow charts explain this automatic running flow. These maintainer scripts flow charts are the blueprint of debian package process flow. If you need to build your own debian package for your Linux application or product, you should know have a better understanding on these flow charts. You can get basic idea about all these scripts and flow charts from my previous article Introduction to Debian Maintainer Script Flow Charts.

You can modify these script to do you install, update and uninstall processes with automatic flow. In the example repository, I already added some scripts with functions that support install, update and uninstall processes. You can change them according to your application.

4. Change the copyright file according to your product.

You need to change the copyright file which is located at

<REPO_HOME>/debian-x64/resources/copyright

For more details about the copyright file and parameters you can refer debian document about the copyright file. In the example file I have added copyrights which needed for WSO2 API Manager.

5. Run the following command to build your debian installer.

bash <REPO_HOME>/debian-x64/build-debian-x64.sh [APPLICATION_NAME] [APPLICATION_VERSION]

Note: You should provide an application name and application version. In addition, application version should be [0–9].[0–9].[0–9] pattern. ( Example: 2.6.0 )

This will start the installer generating process and after completing the building process of the installer the debian package (wso2am-debian-x64–2.6.0.deb) will be saved to following location.

<REPO_HOME>/debian-x64/target/wso2am-debian-x64-2.6.0

Bravo!! 💪That’s it. Now you can start the installation process by double clicking the .deb file.

⚙ Installation Process

📦 Installation via UI

Installation process steps are given below:

Installation page of the package (Details we added on control file are shown here)

Then click on the install button on the screen and this will start the installation process.

Installing the debian package on the system

After the installation you can remove the package by clicking remove button if you needed.

After successful installation

📦 Installation via Terminal

Go to the location where debian package has generated and run the following command to start the installation.

$ sudo dkpg -i <REPO_HOME>/debian-x64/target/<DEBIAN_PACK_NAME>
Installation of the debian package using terminal

If you want to purge the installed package from the system, you can run the following command on the terminal.

$ sudo apt purge <APPLICATION_NAME>
Purging process using terminal command

So, You can use this automated debian installer builder to easily generate installers for your any application that can be run on debian systems. Please suggest any modifications that will improve the debian installer builder to here.

Cheers!! 🍺🍺

More details on debian packages and package management :

--

--

Kosala Sananthana
The Startup

PhD Student @ AχL — Monash University | Former Senior Software Engineer @ WSO2 Inc. | Writer @ The Startup/Better Programming/Towards Data Science