packaging – Mouflons and Penguins https://www.theo-andreou.org Just another boring linux blog Sun, 29 Sep 2019 12:28:47 +0000 en-US hourly 1 https://wordpress.org/?v=5.4.2 Creating a new Debian package using pbuilder: gnujump https://www.theo-andreou.org/?p=1145 https://www.theo-andreou.org/?p=1145#comments Tue, 23 Jun 2015 08:41:15 +0000 http://www.theo-andreou.org/?p=1145 Yet another practical packaging session, this ine on how to build a Debian package from scratch. This one too is based on the packaging tutorial and practical sessions of Lucas Nussbaum.

We are going to download the source code of gnujump from upstream, and use the pbuilder tool to package it. The advantages of pbuider is that it creates a minimal chroot jail that helps you track any dependencies you might forgot to specify in debian/control. Also it gives you the opportunity to build Debian packages on Ubuntu and vice-versa. You can also build packages for releases other than your own.

Prerequisites

  • A recent Debian or Ubuntu system.

Preparation of the pbuilder jail

Install pbuilder and relevant packages:

$ sudo apt-get -y install pbuilder debootstrap devscripts packaging-dev debian-keyring ubuntu-archive-keyring

NOTE: use ubuntu-keyring instead of ubuntu-archive-keyring if your build station is Ubuntu

Prepare the target environment. For example for Ubuntu trusty use can use this setup:

$ sudo pbuilder create --debootstrapopts --variant=buildd --mirror http://cy.archive.ubuntu.com/ubuntu --distribution trusty --architecture amd64 --components main --debbuildopts -mJohn Doe <john.doe@example.net>

Prepare the new package

  1. Download the source:
    $ wget https://ftp.gnu.org/gnu/gnujump/gnujump-1.0.8.tar.gz
    
  2. Extract the archive and change into the source tree:
    $ tar xvzf gnujump-1.0.8.tar.gz
    $ cd gnujump-1.0.8/
    

Prepare for debian packaging

  1. We are going to use the dh_make utility to prepare the debian directory and all the necessary files:
    $ DEBFULLNAME="John Doe" DEBEMAIL="john.doe@example.net" dh_make -s -y --createorig
    

    Check if all necessary files are there:

    $ find debian/
    debian/
    debian/compat
     debian/manpage.1.ex
    debian/preinst.ex
    debian/rules
    debian/gnujump.default.ex
    debian/README.Debian
    debian/copyright
    debian/gnujump.cron.d.ex
    debian/gnujump.doc-base.EX
    debian/changelog
    debian/README.source
    debian/control
    debian/menu.ex
    debian/manpage.sgml.ex
    debian/docs
    debian/init.d.ex
    debian/source
    debian/source/format
    debian/watch.ex
    debian/postrm.ex
    debian/prerm.ex
    debian/manpage.xml.ex
    debian/postinst.ex
    

    Now Check the contents of the debian/changelog, debian/rules and debian/control files.

  2. We will need to make some changes in the debian/control file:

    Source: gnujump
    Section: games
    Priority: optional
    Maintainer: John Doe <john .doe@example.net>
    Build-Depends: debhelper (>= 9), autotools-dev, libsdl1.2-dev, libsdl-image1.2-dev, libsdl-mixer1.2-dev
    Standards-Version: 3.9.5
    Homepage: http://gnujump.es.gnu.org
    ...
    

    The libsdl1.2-dev, libsdl-image1.2-dev and libsdl-mixer1.2-dev have been discovered by repeatedly compiling and failing until you get it right. The you can use the apt-cache search and apt-file search commands to discover the packages corresponding to the missing dependencies.

  3. Edit the debian/rules file to look like this:

    DH_VERBOSE = 1
    
    DPKG_EXPORT_BUILDFLAGS = 1
    include /usr/share/dpkg/default.mk
    
    export DEB_BUILD_MAINT_OPTIONS = hardening=+all
    
    export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
    export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
    
    %:
            dh $@  --with autotools-dev
    
    CFLAGS += -lm
    

  4. Edit the debian/changelog, with dch -e, to look like this:
    gnujump (1.0.8-1) unstable; urgency=low
    
      * Initial release
    
     -- John Doe</john><john .doe@example.net>  Mon, 22 Jun 2015 17:41:22 +0300
    

Build the package

Run this command from the source tree:

$ pdebuild

Give your password when asked. pdebuild will download and install all dependencies in the pbuilder jail and then build the package. Changes will be lost from the jail, the next time you use it but if all goes well, you should see these files under /var/cache/pbuilder/result:

$ ls -la /var/cache/pbuilder/result/
total 5776
drwxr-xr-x 2 root      root         4096 Ιούν 22 17:52 .
drwxr-xr-x 9 root      root         4096 Ιούν 22 11:26 ..
-rw-r--r-- 1 john john    1449 Ιούν 22 17:52 gnujump_1.0.8-1_amd64.changes
-rw-r--r-- 1 john john 1560574 Ιούν 22 17:52 <strong>gnujump_1.0.8-1_amd64.deb</strong>
-rw-rw-r-- 1 john john    9228 Ιούν 22 17:52 gnujump_1.0.8-1.debian.tar.xz
-rw-rw-r-- 1 john john     885 Ιούν 22 17:52 gnujump_1.0.8-1.dsc
-rw-rw-r-- 1 john john 2508641 Ιούλ 24  2012 gnujump_1.0.8.orig.tar.gz
-rw-rw-r-- 1 john john 1814056 Ιούν 22 17:41 gnujump_1.0.8.orig.tar.xz

Checking the result

  1. View the information related to the package file:
    $ dpkg -I /var/cache/pbuilder/result/gnujump_1.0.8-1_amd64.deb
    new debian package, version 2.0.
    size 1560574 bytes: control archive=5550 bytes.
        419 bytes,    11 lines      control              
      18390 bytes,   233 lines      md5sums              
    Package: gnujump
    Version: 1.0.8-1
    Architecture: amd64
    Maintainer: John Doe </john><john .doe@example.net>
    Installed-Size: 2355
    Depends: libc6 (>= 2.14), libgl1-mesa-glx | libgl1, libsdl-image1.2 (>= 1.2.10), libsdl-mixer1.2, libsdl1.2debian (>= 1.2.11)
    Section: games
    Priority: optional
    Homepage: http://gnujump.es.gnu.org
    Description: <insert up to 60 chars description>
     </insert><insert long description, indented with spaces>
    

As you can see our work is not finished. We need to add a description in debian/control and rebuild it.

  1. Check the contents of the package file:
    $ dpkg -I /var/cache/pbuilder/result/gnujump_1.0.8-1_amd64.deb
    

Install the package

Now we can install the package:

$ sudo dpkg -i /var/cache/pbuilder/result/gnujump_1.0.8-1_amd64.deb

Now run the gnujump software and check if it works.

This is not the whole story of course. You have to check the package against Lintian to see if it complies with the Debian Policy. And if it’s not compliant, you may need to use Quilt to patch it. You will need to fill debian/watch so you can track updates on the upstream with uscan. The work of a Debian packager never ends.

References

  • https://wiki.ubuntu.com/PbuilderHowto
  • https://www.debian.org/doc/manuals/packaging-tutorial/packaging-tutorial.en.pdf</insert></john>
]]>
https://www.theo-andreou.org/?feed=rss2&p=1145 1
Modifying an existing Debian package: grep https://www.theo-andreou.org/?p=1112 https://www.theo-andreou.org/?p=1112#comments Sat, 20 Jun 2015 08:34:42 +0000 http://www.theo-andreou.org/?p=1112 This guide is a practical session on how to modify an existing debian package, when the version is not included in the current release. It is based on the excellent packaging tutorial and practical sessions of Lucas Nussbaum.

We are going to download a source deb package, build it without modifications, modify it, patch it, rebuild it and in the end, install it in our system.

Prerequisites

  • A recent Debian or Ubuntu system.

Installation of development packages

$ sudo apt-get -y install build-essential debhelper devscripts packaging-dev debian-keyring

Get the source from the debian repos

$ dget http://cdn.debian.net/debian/pool/main/g/grep/grep_2.21-1.dsc

After that you should see these files under the current directory:

$ ls
grep_2.21-1.debian.tar.bz2  grep_2.21-1.dsc  grep_2.21.orig.tar.xz
  • grep_2.21-1.dsc: Package’s debian source control file.
  • grep_2.21.orig.tar.xz: Original source.
  • grep_2.21-1.debian.tar.bz2: Debian files and patches.

Unpack the source

The dpkg-source file will unpack the original and debian tarballs and apply the debian patches, if available.

$ dpkg-source -x grep_2.21-1.dsc

Download build dependencies

$ sudo apt-get -y build-dep grep

Build the unmodified package

Change into the source tree and run debuild. We are using the -us and -uc flags to suppress warnings about signing.

$ cd grep-2.21/
$ debuild -us -uc

It doesn’t take long before this package is build. In the parent directory you will find three more files:

  • grep_2.21-1_amd64.deb: the newly created deb package file.
  • grep_2.21-1_amd64.build: the build log. You can use this to check for errors or warnings.
  • grep_2.21-1_amd64.changes: Debian applied changes.

Modify the package

I suggest you do not touch the source, unless you fancy spending your day debugging. We will simply make some modifications on the debian/changelog and debian/rules files.

  1. Add the --with-gnu-ld flag in the DEB_CONFIGURE_EXTRA_FLAGS line of the debian/rules file.

    The --with-gnu-ld is a trivial change and shouldn’t break anything during build. Find this line:

    DEB_CONFIGURE_EXTRA_FLAGS += --without-included-regex
    

    And change it to this:

    DEB_CONFIGURE_EXTRA_FLAGS += --without-included-regex --with-gnu-ld
    
  2. Update the changelog file.

    We are going to use the dch utility which is simply a wrapper around your default editor, with changelog syntax checking. Run the following command in the source tree:

    $ DEBFULLNAME="John Doe" DEBEMAIL="john.doe@example.net" dch -i
    

    Make the following changes (in bold) the debian/changelog file:

    grep (2.21-1ubuntu1) experimental; urgency=low
    
     * Support for GNU ld linker.
    
    -- John Doe <john .doe@example.net>  Fri, 19 Jun 2015 13:01:37 +0300
    

    Note how the name and email of the patcher have been automatically inserted in the changelog entry. That’s because we defined the DEBFULLNAME and DEBEMAIL variables in the shell that runs dch.

Rebuild the modified package

$ debuild -us -uc

You will see the following error:

dpkg-source: error: aborting due to unexpected upstream changes, see /tmp/grep_2.21-1ubuntu1.diff.eYCcPk
dpkg-source: info: you can integrate the local changes with dpkg-source --commit
dpkg-buildpackage: error: dpkg-source -b grep-2.21 gave error exit status 2
debuild: fatal error at line 1376:

The above error happens because the --with-gnu-ld flag makes changes to the upstream source and this is against the Debian policy.

Apply patches for Policy compliance

$ cp /tmp/grep_2.21-1ubuntu1.diff.eYCcPk debian/patches/90-enable-gnu-ld.patch
$ echo 90-enable-gnu-ld.patch >> debian/patches/series

It is considered a good practice to edit the patch, add a description and a short summary and fill the headers related to the [Patch Tagging Guidelines](http://dep.debian.net/deps/dep3/ "Patch Tagging Guidelines").

This method is only a workaround. The correct way to deal with patches is [Quilt](https://pkg-perl.alioth.debian.org/howto/quilt.html "Quilt Howto").

Final rebuild of the modified package

$ debuild -us -uc

You will see five additional files in the parent directory:

  • grep_2.21-1ubuntu1_amd64.deb: the new deb package file.
  • grep_2.21-1ubuntu1.debian.tar.bz2: the new debian directory tarball.
  • grep_2.21-1ubuntu1.dsc: the new debian source control file.
  • grep_2.21-1ubuntu1_amd64.build: the build log.
  • grep_2.21-1ubuntu1_amd64.changes: the changes file.

Checking the differences between original and new

The following commands will find the differences in the debian source control and changes files:

$ diff ../*.changes
$ diff ../*dsc

Install the new package

$ sudo debi

Check if grep is the correct version:

$ grep --version
grep (GNU grep) <strong>2.21</strong>
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

All done. If you have reached so far congratulations! You have successfully rebuilt a Debian package.

References:

  • http://www.lucas-nussbaum.net/
  • https://www.debian.org/doc/manuals/packaging-tutorial/packaging-tutorial.en.pdf
  • http://dep.debian.net/deps/dep3/</john>
]]>
https://www.theo-andreou.org/?feed=rss2&p=1112 1