Creating Debian Package


Packages to be installed

sbuild – sbuild is a convenience wrapper script of schroot to build binary packages easily under specified chroot. sbuild is used on the official build network to build binary and source packages for all supported architectures.

build-essential – The build-essentials packages are meta-packages that are necessary for compiling software. They include the GNU debugger, g++/GNU compiler collection, and some more tools and libraries that are required to compile a program.

devscripts – The devscripts package provides a collection of texts that can be used by Debian developers and others who wish to create Debian packages.

debhelper – Debhelper is used to help you build a Debian package.

Note : while installing the above packages the server does not respond with the header some time. For some systems it might require retrying a few times.

The aim of the packaging process is to allow the automation of configuring, installing, upgrading, and removing computer programs for Debian in a consistent manner.

The easiest package source code consists of three files:

  1. The renamed upstream tarball, as per the naming convention

  2. Debian directory, which contains changes made to the upstream source, as well as all the files needed to create a binary package.

  3. Description file (with .dsc extension), containing metadata for the two files above.

Note : The below instructions are sequenced for an example like Sample Project Linux where the build is ready and needs to be converted to a debian package to be used. But the format can be changed as per the requirements.

Step 1: Create Build

For Sample Project : > gradle build

use command in root Project Directory with one update in current build script where final Build file is named in testpackage-3.2.4.tar.gz naming convention

<packagename>-<version>.tar.gz

Step 2: Rename tarball with proper naming convention & Move it to source directory

The tarball should be followed with suffix <.orig.tar.gz>

For our example the bolow command and name would be used

> mv testpackage-3.2.4.tar.gz testpackage_3.2.4.orig.tar.gz

> cp testpackage_3.2.4.orig.tar.gz /usr/share/java/

Note : Source directory could be anything based on preference. Source package name should be lowercase, and may contain letters, digits, and dashes..

Step 3: Unpack tarball in source directory

> tar xf testpackage_3.2.4.orig.tar.gz

For our example the new directory name is testpackage-3.2.4

Step 4: Create debian/ directory inside source code directory

> cd testpackage-3.2.4

> mkdir debian

All below files in Step 4 will be places in debian/ subdirectory

  • debian/changelog
  • debian/compat
  • debian/copyright
  • debian/rules
  • debian/source/format
  • debian/control
  • debian/install
  • debian/conffiles
  • debian/postinst
  • debian/preinst
  • debian/postrm
  • debian/postrm

debian/changelog – This is a required file, with a special format. This format is used by dpkg and other applications to determine your version number, update, distribution, and urgency of your package.

For Sample Project : Below command can be used

> dch –create -v 3.2.4-1 –package testpackage

Above command creates a test package. While Publishing it will show an error message. After the above command is called an update option will be called, UNRELEASED should be replaced with a valid Ubuntu version. Eg xenial, bionic.

14.04 LTSTrusty Tahr
16.04 LTSXenial Xerus
18.04 LTSBionic Beaver
20.04 LTSFocal Fossa
22.04 LTSJammy Jellyfish

Different packages can be created for Different Ubuntu versions.

#Note : Package name (testpackage) MUST match the source package name. 3.2.4-1 version. Section 3.2.4 is the upstream version . Part -1 is the Debian version: the first version of the Debian package for the upcoming version 1.0. If the Debian package has a bug, and it is fixed, but the upcoming version remains the same, then the next version of the package will be called 3.2.4-2. Then 3.2.4-3, and so on.

debian/compat – The compat file defines the debhelper compatibility level.

For Sample Project : Below command can be used

> echo “10” > debian/compat

debian/copyright – This file is often required to contain a verbatim copy of the package’s copyright information.

debian/rules – It is an executable script used for building Debian packages. The debian/rules script re-targets the upstream build system to install files in the destination directory) and creates the archive file of the generated files as the deb file.

Below is sample script for rules

#!/usr/bin/make -f

%:

dh $@

debian/source/format – it contains the version number for the format of the source package.

For Sample Project : Below command can be used

> echo “3.0 (quilt)” > debian/source/format

debian/control – The control file contains the most important (and version-independent) information about the source package and the binary packages it creates.

For Sample Project : Below data can be replaced

Source: testpackage

Maintainer: Name <maintainer_email@gmail.com>

Section: misc

Priority: optional

Standards-Version: 3.9.2

Package: testpackage

Architecture: all

Depends: ${shlibs:Depends}, ${misc:Depends}, openjdk-8-jre | openjdk-7-jre | openjdk-6-jre | oracle-java8-installer | oracle-java7-installer | oracle-java6-installer | jarwrapper

Description: UEM_AGENT testpackage-3.2.4, manage Linux System.

#Note : Here package dependency is set to different versions of JAVA. whichever mentioned JAVA version can be used.

debian/install – specify which files need to be installed where.

The Structure of debian/install file is :

<Input File> <Output File Directory>

We can use Filter Files also. For Sample Project : Below example can be used

install.sh usr/share/java/<project-directory>/

app/project* usr/share/java/<project-directory>/

#Note : Below files are all executable scripts which Debian automatically runs before or after package installation or Removal.

debian/conffiles – This file tells dpkg that you don’t want to replace these files on every install/upgrade. So if you would like a file to persist between upgrades you should add its name to this file.

For Sample Project

$ echo “” > debian/conffiles

debian/postinst – This script typically completes any required configuration of the installed package once the package has been unpacked from its Debian archive (“.deb”) file.

Operations that can be performed

  • Starting new services
  • Initializing environment files
  • Initializing environment variables
  • Clear Unwanted Files after Installation
  • And Other Post Installation Operations

debian/preinst – This script executes before the package is unpacked from its Debian archive (“.deb”) file.

Operations that can be performed

  • Stopping previous services 
  • Deleting some old directories
  • Downloading other resources required
  • Creating new services
  • Managing other Old Build clean resources operations like creating Old Build Backups.

debian/postrm – This script typically modifies links or other files associated with the package, and/or removes files created by the package after the package is removed.

Operations that can be performed

  • Removing all Unwanted resources after Removal of package
  • Restart all system services
  • Manage logs of removed package
  • Reverting any system change done by package
  • Creating Backup of leftover files

debian/prerm – This script typically stops any daemons associated with a package. Done before deleting package related files.

Operations that can be performed

  • Stopping services
  • Removing Link Files(unregistered all commands)
  • Creating Backup of resources before removal

#Note : In Linux Package a Link file can be added to link a main script file to a command naming similar to package in above 

Create a link file in /usr/bin/testpackage and link it to any script in System.

Step 5 : Build the package

> debuild -us -uc

Package File created : testpackage_3.2.4-1_all.deb

Other files created : 

testpackage_3.2.4-1_amd64.build

testpackage_3.2.4-1_amd64.buildinfo

testpackage_3.2.4-1_amd64.changes

testpackage_3.2.4-1.debian.tar.xz

testpackage_3.2.4-1.dsc

Step 6 : Install the package Locally

> dpkg -i testpackage_3.2.4-1_all.deb

Step 7 : Command called to run main script

> testpackage

Step 8 : Removing Installed Package after testing

> dpkg –purge testpackage

Leave A Comment

Your email address will not be published. Required fields are marked *