Table of Content

This is a four-parts article. There are few sections here.

Part One
  • Preface: Test Bed, Must Read
  • Getting Started With Docker
  • Package Management: DPKG Frontend, APT Frontend, Get Help, The new APT, APT Shell
  • Updating System: OS Release, Refresh Update, List Upgradable, Upgrade
  • Package IRSIF: Install, Download, Removal, Unused Dependency, Query Search, Show Info, List Files, Extract
  • What's Next
Part Two
  • Group: Task
  • Package More: Change Log, Policy, aptitude, dselect, configure, Search Files, dlocate, Unused Dependency
  • System Wide: Statistics, List Packages, Config, Verify
  • History: The Log File
  • Clean Up: Clean, Unused Dependency, Orphan
  • What's Next
Part Three
  • Dependency: Dependency, Reverse Dependency, Test
  • Hold Package: Building Example, Mark Hold, Pinning
  • Repository: Configuration, Policy, Add Repository, Mirror
  • Distribution Upgrade
  • Repository Pinning: nmap Case, New Docker for Stretch, Stable nmap, Pinning Unstable, Unstable nmap
  • What's Next
Part Four
  • Build from Source: The Toolchain, Source Repository, User Privilege, Build Directory, Example, Download Source, Build Source, Examine Directory, Install Result
  • Developer Script: debcheckout, Build Dependency, Build Package, Lintian, Source Compile, debi, Deb Checksums, Show Source
  • Conclusion

Build from Source

APT has the capability to build the source code, not just download the package.

I actually have cover this last year. I just need to recompile the material, to fit this package management (in docker) series articles.

Reading

The Toolchain

Preparing the toolchain is as simply as install apt-src. What you need to know is, this toolchain is a lot of packages in number as this message said “_ 10 upgraded, 80 newly installed_ “, “ Need to get 145 MB of archives “.

$ apt install apt-src
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  ...
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  ...
Suggested packages:
  ...
The following NEW packages will be installed:
  apt-src binutils binutils-common binutils-x86-64-linux-gnu
  ...
The following packages will be upgraded:
  ...
10 upgraded, 80 newly installed, 0 to remove and 63 not upgraded.
Need to get 145 MB of archives.
After this operation, 635 MB of additional disk space will be used.
Do you want to continue? [Y/n]        

Docker APT-SRC: Prepare Toolchain

Source Repository

Make sure that source repository is enabled in your /etc/apt/sources.list. Add the deb-src and apt-src update.

Now sources.list seems like an appropriate name.

$ nano /etc/apt/sources.list
deb http://deb.debian.org/debian testing main
deb-src http://deb.debian.org/debian testing main

Docker APT-SRC: Prepare Repository

User Privilege

Build require regular user, non root one. Consider make one first.

$ useradd -m -g users -G sudo -s /bin/bash epsi

$ groups epsi
epsi : users sudo

$ passwd epsi
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

$ su epsi

$ whoami
epsi

If you wish you can also setup sudoers.

$ nano /etc/sudoers
epsi    ALL=(ALL:ALL) ALL

Docker APT-SRC: adduser Epsi

Build Directory

Make any directory as a working directory for your compilation process

$ mkdir ~/build
$ cd ~/build

Docker APT-SRC: Prepare Directory

Example

Again, consider apt package as our guinea pig example. Simply issue one of this command below to check package version.

$ dpkg --list apt 

$ apt show apt

$ apt search '^apt$'
apt search '^apt$'
Sorting... Done
Full Text Search... Done
apt/testing,now 1.5~rc1 amd64 [installed,automatic]
  commandline package manager

It is going to be a good idea to upgrade system to latest version to avoid missing libraries. Since we are going to modify system package, this is a must do part. Or you may end up with something similar as message below

$ apt
apt: relocation error: /lib/x86_64-linux-gnu/libapt-private.so.0.0: 
symbol _ZTI17pkgAcquireStatus2, version APTPKG_5.0 not defined in 
file libapt-pkg.so.5.0 with link time reference

Download Source

Building a package could be as simple as this.

$ sudo apt-src --build install apt

This above is the most important part of the process. You can also unbundling this process into two steps.

$ apt-src install apt
$ apt-src build apt

The first one, will also install the needed package, such as code and al its dependencies.

$ apt-src install apt
Reading package lists... Done
NOTICE: 'apt' packaging is maintained in the 'Git' version control system at:
https://anonscm.debian.org/git/apt/apt.git
Please use:
git clone https://anonscm.debian.org/git/apt/apt.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 2098 kB of source archives.
Get:1 http://deb.debian.org/debian testing/main apt 1.5~rc1 (dsc) [2590 B]
Get:2 http://deb.debian.org/debian testing/main apt 1.5~rc1 (tar) [2095 kB]
Fetched 2098 kB in 1s (1865 kB/s)
dpkg-source: info: extracting apt in apt-1.5~rc1
dpkg-source: info: unpacking apt_1.5~rc1.tar.xz

Docker APT-SRC: install apt

Now we have this files our working directory.

$ ls
apt-1.5~rc1  apt_1.5~rc1.dsc  apt_1.5~rc1.tar.xz

Build Source

Consider Build the package. Let’s do it. This is the most interesting part. This is going to takes time.

$ apt-src build apt
I: Building in ./apt-1.5~rc1 ..
dpkg-buildpackage: info: source package apt
dpkg-buildpackage: info: source version 1.5~rc1
dpkg-buildpackage: info: source distribution unstable
dpkg-buildpackage: info: source changed by Julian Andres Klode <jak@debian.org>
dpkg-buildpackage: info: host architecture amd64
 dpkg-source --before-build apt-1.5~rc1
dpkg-source: info: using options from apt-1.5~rc1/debian/source/options: --compression=xz
 fakeroot debian/rules clean
dh clean
   dh_auto_clean
   dh_autoreconf_clean
   debian/rules override_dh_clean
make[1]: Entering directory '/home/epsi/build/apt-1.5~rc1'
cp COPYING debian/copyright

Docker APT-SRC: build apt

Docker APT-SRC: build apt

Docker APT-SRC: build apt

Examine Directory

Check your directoy, your apt_1.5~rc1_amd64.deb package should already be there.

$ ls 
...
apt_1.5~rc1.dsc
apt_1.5~rc1.tar.xz
apt_1.5~rc1_amd64.buildinfo
apt_1.5~rc1_amd64.changes
apt_1.5~rc1_amd64.deb
...

Docker APT-SRC: Directory Result

Install Result

Install package using dpkg command

$ sudo dpkg --install apt_1.5~rc1_amd64.deb
(Reading database ... 29517 files and directories currently installed.)
Preparing to unpack apt_1.5~rc1_amd64.deb ...
Unpacking apt (1.5~rc1) over (1.5~rc1) ...
Setting up apt (1.5~rc1) ...
Processing triggers for libc-bin (2.24-17) ...
Processing triggers for man-db (2.7.6.1-2) ...

Docker APT-SRC: DPKG Install

Does it work? You can check your apt version now

$ apt --version
apt 1.5~rc1 (amd64)

Docker APT-SRC: Does it works?

After a few days, you will feels like compiling is not difficult.


Developer Script

There are other way though, more elegant to build package from source. If you are a developer there are few goodies you can have from devscripts.

$ apt install build-essential debhelper devscripts
...
Need to get 65.0 MB of archives.
After this operation, 176 MB of additional disk space will be used.
Do you want to continue? [Y/n]
...

Note that as usual, consider be as user and enable source repository.

  • debi

  • debcheckout

debcheckout

$ apt-get source herbstluftwm

Or

$ apt source herbstluftwm

Or

$ debcheckout herbstluftwm
debcheckout herbstluftwm
declared git repository at git://git.debian.org/collab-maint/herbstluftwm.git
git clone git://git.debian.org/collab-maint/herbstluftwm.git herbstluftwm ...
Cloning into 'herbstluftwm'...
remote: Counting objects: 7334, done.
remote: Compressing objects: 100% (2114/2114), done.
remote: Total 7334 (delta 5474), reused 6985 (delta 5193)
Receiving objects: 100% (7334/7334), 1.27 MiB | 222.00 KiB/s, done.
Resolving deltas: 100% (5474/5474), done.

Docker Debian: debcheckout

Build Dependency

$ sudo apt-get build-dep herbstluftwm

Or:

$ sudo apt build-dep herbstluftwm
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  asciidoc asciidoc-base asciidoc-common libglib2.0-bin libglib2.0-data
  libglib2.0-dev libglib2.0-dev-bin libpcre16-3 libpcre3-dev libpcre32-3
  libpcrecpp0v5 libpthread-stubs0-dev libx11-dev libxau-dev libxcb1-dev
  libxdmcp-dev libxext-dev libxinerama-dev libxinerama1 libxml2-utils
  x11proto-core-dev x11proto-input-dev x11proto-kb-dev x11proto-xext-dev
  x11proto-xinerama-dev xorg-sgml-doctools xtrans-dev
The following packages will be upgraded:
  libglib2.0-0
1 upgraded, 27 newly installed, 0 to remove and 20 not upgraded.
Need to get 16.0 MB of archives.
After this operation, 38.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

Docker Debian: build-dep

Build Package

Go to build tree directory first.

$ cd ~/build/herbstluftwm
$ dpkg-buildpackage -rfakeroot -uc -b
dpkg-buildpackage: info: source package herbstluftwm
dpkg-buildpackage: info: source version 0.7.0-1
dpkg-buildpackage: info: source distribution unstable
dpkg-buildpackage: info: source changed by Christoph Egger <christoph@debian.org>
dpkg-buildpackage: info: host architecture amd64
 dpkg-source --before-build herbstluftwm
 fakeroot debian/rules clean
dh clean --parallel
   debian/rules override_dh_auto_clean
make[1]: Entering directory '/home/epsi/build/herbstluftwm'
dh_auto_clean -- VERBOSE= COLOR=0
	make -j2 clean VERBOSE= COLOR=0
make[2]: Entering directory '/home/epsi/build/herbstluftwm'
rm -f doc/herbstclient.1
...

Docker Debian: buildpackage

And you will have the result similar as below:

$ ls .. | grep herbstluftwm
herbstluftwm
herbstluftwm-dbgsym_0.7.0-1_amd64.deb
herbstluftwm_0.7.0-1_amd64.buildinfo
herbstluftwm_0.7.0-1_amd64.changes
herbstluftwm_0.7.0-1_amd64.deb

Lintian

Check for possible issue.

$ lintian
W: herbstluftwm: binary-without-manpage usr/bin/dmenu_run_hlwm

Docker Debian: lintian

Source Compile

This is even shorter.

$ apt source --compile herbstluftwm
Reading package lists... Done
NOTICE: 'herbstluftwm' packaging is maintained in the 'Git' version control system at:
git://git.debian.org/collab-maint/herbstluftwm.git
Please use:
git clone git://git.debian.org/collab-maint/herbstluftwm.git
to retrieve the latest (possibly unreleased) updates to the package.
Need to get 261 kB of source archives.
Get:1 http://deb.debian.org/debian testing/main herbstluftwm 0.7.0-1 (dsc) [1969 B]
Get:2 http://deb.debian.org/debian testing/main herbstluftwm 0.7.0-1 (tar) [247 kB]
Get:3 http://deb.debian.org/debian testing/main herbstluftwm 0.7.0-1 (diff) [11.1 kB]
Fetched 261 kB in 1s (152 kB/s)      
dpkg-source: info: extracting herbstluftwm in herbstluftwm-0.7.0
dpkg-source: info: unpacking herbstluftwm_0.7.0.orig.tar.gz
dpkg-source: info: unpacking herbstluftwm_0.7.0-1.debian.tar.xz
dpkg-buildpackage: info: source package herbstluftwm
dpkg-buildpackage: info: source version 0.7.0-1
dpkg-buildpackage: info: source distribution unstable

Docker Debian: source compile

Debi

$ sudo debi
[sudo] password for epsi: 
Selecting previously unselected package herbstluftwm-dbgsym.
(Reading database ... 36536 files and directories currently installed.)
Preparing to unpack herbstluftwm-dbgsym_0.7.0-1_amd64.deb ...
Unpacking herbstluftwm-dbgsym (0.7.0-1) ...
Selecting previously unselected package herbstluftwm.
Preparing to unpack herbstluftwm_0.7.0-1_amd64.deb ...
Unpacking herbstluftwm (0.7.0-1) ...
Setting up herbstluftwm (0.7.0-1) ...
update-alternatives: using /usr/bin/herbstluftwm to provide /usr/bin/x-window-manager (x-window-manager) in auto mode
Setting up herbstluftwm-dbgsym (0.7.0-1) ...
Processing triggers for man-db (2.7.6.1-2) ...

Docker Debian: debi

Debuild

debuild is a convenient way, if you want to build your own package.

Since we do not have our very own source, consider use the newly downloaded herbstluftwm. Go to build directory first.

$ cd ~/build/herbstluftwm-0.7.0
$ debuild
 dpkg-buildpackage -rfakeroot -us -uc
dpkg-buildpackage: info: source package herbstluftwm
dpkg-buildpackage: info: source version 0.7.0-1
dpkg-buildpackage: info: source distribution unstable
dpkg-buildpackage: info: source changed by Christoph Egger <christoph@debian.org>
 dpkg-source --before-build herbstluftwm-0.7.0
...
Finished running lintian.
Now signing changes and any dsc files...
 signfile dsc herbstluftwm_0.7.0-1.dsc Christoph Egger <christoph@debian.org>
gpg: skipped "Christoph Egger <christoph@debian.org>": No secret key
gpg: /tmp/debsign.q2AXXKv1/herbstluftwm_0.7.0-1.dsc: clear-sign failed: No secret key
debsign: gpg error occurred!  Aborting....
debuild: fatal error at line 1053:
running debsign failed
epsi@ea09d9991c35:~/build/herbstluftwm

Docker Debian: debuild

Of course we do not have secret key for herbstuftwm. This is a part of Debian security model.

Deb Checksums

$ debsums ./herbstluftwm_0.7.0-1_amd64.deb 
/usr/bin/dmenu_run_hlwm                                                       OK
/usr/bin/herbstclient                                                         OK
/usr/bin/herbstluftwm                                                         OK
/usr/share/bash-completion/completions/herbstclient-completion                OK
/usr/share/doc/herbstluftwm/BUGS.gz                                           OK
/usr/share/doc/herbstluftwm/NEWS.gz                                           OK
/usr/share/doc/herbstluftwm/changelog.Debian.gz                               OK
...

Docker Debian: debsums

Show Source

Now we can see the source info in cache.

$ apt-cache showsrc herbstluftwm

Or

$ apt showsrc herbstluftwm
...
Vcs-Browser: http://git.debian.org/?p=collab-maint/herbstluftwm.git;a=summary
Vcs-Git: git://git.debian.org/collab-maint/herbstluftwm.git
...

Docker Debian: showsrc


Conclusion

These are just preliminary knowledge about APT.

Thank you for reading