So, now we have had a look at building metapackages, let's have som fun with "real" packages. This will be a short tutorial on packaging Debian packages. I should point out that I'm using a Kali based build system, so some things might be different if you're building on something else.

 For this tutorial, we're going to build a package with a man page, so we can install it on a lot of machines, without to much work.

The first thing we need to do, is make a directory, named like the package we're creating. Mine is called blackdragon-docs-logitacker-1.0.

#make package dir

mkdir blackdragon-docs-logitacker-1.0

#Jump into package dir

cd blackdragon-docs-logitacker-1.0

The next thing we need to do is make a couple of skeleton files we need for later. We use the dh_make command for that, like so

nx@xeon:~/dev/blackdragon-docs-logitacker-1.0$ dh_make --native

Type of package: (single, indep, library, python)
[s/i/l/p]?

select "i"

Maintainer Name     : nx
Email-Address       : This email address is being protected from spambots. You need JavaScript enabled to view it.
Date                : Mon, 08 Mar 2021 13:03:30 +0100
Package Name        : blackdragon-docs-logitacker
Version             : 1.0
License             : gpl3
Package Type        : indep
Are the details correct? [Y/n/q]

Type "y"

Currently there is not top level Makefile. This may require additional tuning
Done. Please edit the files in the debian/ subdirectory now.

Now we have a directory called debian, let's see what's in that, and go through it, and talk about it.

nx@xeon:~/dev/blackdragon-docs-logitacker-1.0/debian$ ls

blackdragon-docs-logitacker.cron.d.ex    changelog  manpage.1.ex     postinst.ex  prerm.ex       README.source    source
blackdragon-docs-logitacker.doc-base.EX  control    manpage.sgml.ex  postrm.ex    README         rules
blackdragon-docs-logitacker-docs.docs    copyright  manpage.xml.ex   preinst.ex   README.Debian  salsa-ci.yml.ex

There,s a lot of files in here, but we'll only need a couple of them, and they are changelog, control, copyright, rules, and the readme files. All the files ending in ex, should be deleted, since they are example files we don't need.

# delete example files

rm *.ex
rm *.EX
rm *.docs

# Check what we have

ls

changelog  control  copyright  README  README.Debian  README.source  rules  source

source is a directory, and can be deleted, but I keep it around, it doesn't matter. But, we need to make a directory to store our man page in, so step back, so you're in the base package directory.

cd ..

/dev/blackdragon-docs-logitacker-1.0$ ls
debian

Here, I make a directory called data, and in there I place my files, so I know where they are. We need it later, when we're going to write the install file.

#Make directory

mkdir data

In the data directory, I place my man page file. Here it's called logitacker.7.gz, So, we place it on the host system in /usr/share/man/man7/, remember this path for later

 Next, we start of by editing the control under the debian directory. file. This is the file that controls the build, so open it in your editor, and let's go.

# Control file, before editing

nx@xeon:~/dev/blackdragon-docs-logitacker-1.0/debian$ cat control
Source: blackdragon-docs-logitacker
Section: unknown
Priority: optional
Maintainer: nx <This email address is being protected from spambots. You need JavaScript enabled to view it.>
Build-Depends: debhelper-compat (= 13)
Standards-Version: 4.5.1
Homepage: <insert the upstream URL, if relevant>
#Vcs-Browser: https://salsa.debian.org/debian/blackdragon-docs-logitacker
#Vcs-Git: https://salsa.debian.org/debian/blackdragon-docs-logitacker.git
Rules-Requires-Root: no

Package: blackdragon-docs-logitacker
Architecture: all
Depends: ${misc:Depends}
Description: <insert up to 60 chars description>
 <insert long description, indented with spaces>

# Control file, after editing

nx@xeon:~/dev/blackdragon-docs-logitacker-1.0/debian$ cat control
Source: blackdragon-docs-logitacker
Section: misc
Priority: optional
Maintainer: nx <This email address is being protected from spambots. You need JavaScript enabled to view it.>
Build-Depends: debhelper-compat (= 13)
Standards-Version: 4.5.1
Homepage: https://www.blackdragon.se
Rules-Requires-Root: no

Package: blackdragon-docs-logitacker
Architecture: all
Depends: ${misc:Depends}
Description: Blackdragon Logitacker man page
 This package provides the man page for the Logitacker Project.

Remember that Description lines start with a space, and empty lines with a space and a .

When you're done, save the file, and let's move on to the changelog file. Let's have a look at it.

cat changelog

blackdragon-docs-logitacker (1.0) unstable; urgency=medium

  * Initial Release.

 -- nx <This email address is being protected from spambots. You need JavaScript enabled to view it.>  Mon, 08 Mar 2021 13:03:30 +0100

We could change something here, and add notes about the changes we made. I leave it be, since this is the first release, so nothing has changed really.

Next, we could change the copyright file, I leave it be for now, since this is just an internal package.

So, now we need to write an install file, that takes care of installing our man page onto the host. First we make the file

touch install

Open it in your text editor, and let's define some rules for our content. Remember our data is in the data directory, and we want it in /usr/share/man/man7/. We need one line in the install file, and it's this one.

data/* /usr/share/man/man7/

That's it. jump one directory back, so you're in the base directory, named after your package. The one where you got two folders, debian and data, and call the build with

# Build command

dpkg-buildpackage -us -uc

# Output from the build command, yours will be different :)

dpkg-buildpackage: info: source package blackdragon-docs-logitacker
dpkg-buildpackage: info: source version 1.0
dpkg-buildpackage: info: source distribution unstable
dpkg-buildpackage: info: source changed by nx <This email address is being protected from spambots. You need JavaScript enabled to view it.>
dpkg-buildpackage: info: host architecture amd64
 dpkg-source --before-build .
 debian/rules clean                                                                                                                     
dh clean                                                                                                                                
   dh_clean
 dpkg-source -b .
dpkg-source: info: using source format '3.0 (native)'                                                                                   
dpkg-source: info: building blackdragon-docs-logitacker in blackdragon-docs-logitacker_1.0.tar.xz
dpkg-source: info: building blackdragon-docs-logitacker in blackdragon-docs-logitacker_1.0.dsc
 debian/rules binary
dh binary                                                                                                                               
   dh_update_autotools_config
   dh_autoreconf
   create-stamp debian/debhelper-build-stamp
   dh_prep
   dh_install
   dh_installdocs
   dh_installchangelogs
   dh_installman
   dh_perl
   dh_link
   dh_strip_nondeterminism
   dh_compress
   dh_fixperms
   dh_missing
   dh_installdeb
   dh_gencontrol
   dh_md5sums
   dh_builddeb
dpkg-deb: building package 'blackdragon-docs-logitacker' in '../blackdragon-docs-logitacker_1.0_all.deb'.
 dpkg-genbuildinfo
 dpkg-genchanges  >../blackdragon-docs-logitacker_1.0_amd64.changes                                                                     
dpkg-genchanges: info: including full source code in upload                                                                             
 dpkg-source --after-build .
dpkg-buildpackage: info: full upload; Debian-native package (full source is included)  

# Check if the packages are there

cd ..

ls

ls

blackdragon-docs-logitacker_1.0_all.deb

# Output changed a bit, there will be more types, but the one we want is package.deb            

So, now there's one thing left, and that is to test if we can install it, and remove it. We can do that with dpkg -i

root@xeon:/home/nx/dev# dpkg -i blackdragon-docs-logitacker_1.0_all.deb

Vælger tidligere fravalgt pakke blackdragon-docs-logitacker.
(Læser database ... 706053 filer og kataloger installeret i øjeblikket.)
Gør klar til at udpakke blackdragon-docs-logitacker_1.0_all.deb ...
Udpakker blackdragon-docs-logitacker (1.0) ...
Sætter blackdragon-docs-logitacker (1.0) op ...
Behandler udløsere for man-db (2.9.4-2) ...

# Check if we got a man page

apropos logitacker
logitacker (7)       - (ukendt emne)

And we did, so out package is working. Let's see if we can remove it

dpkg --purge blackdragon-docs-logitacker

(Læser database ... 706058 filer og kataloger installeret i øjeblikket.)
Afinstallerer blackdragon-docs-logitacker (1.0) ...
Behandler udløsere for man-db (2.9.4-2) ...

root@xeon:/home/nx/dev# man logitacker
Ingen manualindgang for logitacker

And yes, it did uninstall cleanly, so our package works

If you made it to the end, pat yourself on the back, well done :) Now, you know how to package for Kali, and Debian. The same method should apply to all Debian based distro's without to much changing, so try it out :)

You have no rights to post comments