1. Debian
    13 Jan 2023
    1. Recently I wrote a little Ruby command line tool and I wanted to package it for easy installation (and removal) on Debian based systems. One of the challenges I encountered during the packaging process was that my command has a dependency on the gepub library, which at the time, did not have a deb package available, at least not in the official source. This meant that I also had to create a Debian package for the gepub library before I could proceed with the original packaging. This article will go through the steps I took to overcome this challenge and provide a guide for anyone looking to package Ruby gems as Debian packages.

    2. Configure the environment

      A lot of Debian packaging tools recognize input through specific environment variables. To let the templating engine for the package sources know how you are and tell the package builder not to sign the packages cryptographically (only in case you don’t indend to distribute them to a larger audience) you can set the environment like this:

      export DEBFULLNAME="Alexander E. Fischer"
      export DEBEMAIL=aef@example.net
      export DEBBUILDOPTS="-us -uc"

      Gather dependencies

      Because gepub depends on the Ruby gems nokogiri and rubyzip and we don’t want our Debian packages to depend on the Rubygems package system you will need to install the ruby-zip and ruby-nokogiri Debian packages through APT. You could use the following command:

      apt install ruby-zip ruby-nokogiri

      Preparing a source directory

      To start, you will need to use the gem2deb tool to create a package for the gepub library. Use the following command:

      gem2deb gepub --only-source-dir

      This will create a source directory for creating a gepub Debian package, but will not try to build it yet. Afterwards change into the package source directory.

      cd ruby-gepub-1.0.15

      Refining the package source

      Now you can edit the package metadata in the debian/ directory.

      Clean up the debian/changelog. First of all, if you build these packages for personal use, and not to upload them to the Debian project itself, you can remove references to issues on the Debian bugtracker. The urgency seems to relate to the order that packages are installed. If your library is like mine, a high level application component and this is not a security update release, it seems plausible to have a very low urgency.

      -ruby-gepub (1.0.15-1) UNRELEASED; urgency=medium
      +ruby-gepub (1.0.15-1) UNRELEASED; urgency=low
       
      -  * Initial release (Closes: #nnnn)
      +  * Initial release
       
        -- Alexander E. Fischer <aef@example.net>  Mon, 02 Jan 2023 12:58:37 +0100

      debian/control needs to be updated in several places. Again, as this is not uploaded to Debian, there is no need to differentiate between maintainer and uploader. I also had to tweek the naming of the Debian package for rubyzip because against the usual convention, the Debian package for it is not called ruby-rubyzip. They chose the name ruby-zip, probably for reasons of a less redundant name appealing more to the human perspective.

      Also, references to Debian trackers can be removed again. I had no intention of running tests when building the package, so I also removed references to this.

      Last but not least, it is a good idea to write a concise description for the package. And if the description of the source gem starts with an article, the Debian package linter complains. So in my case I rewrote it a bit.

      @@ -1,20 +1,16 @@
       Source: ruby-gepub
       Section: ruby
       Priority: optional
      -Maintainer: Debian Ruby Team <pkg-ruby-extras-maintainers@lists.alioth.debian.org>
      -Uploaders: Alexander E. Fischer <aef@example.net>
      +Maintainer: Alexander E. Fischer <aef@example.net>
       Build-Depends: debhelper-compat (= 13),
                      gem2deb (>= 1),
                      ruby,
                      ruby-nokogiri (<< 2.0),
                      ruby-nokogiri (>= 1.8.2),
      -               ruby-rubyzip (<< 2.4),
      -               ruby-rubyzip (>> 1.1.1)
      +               ruby-zip (<< 2.4),
      +               ruby-zip (>> 1.1.1)
       Standards-Version: 4.5.0
      -Vcs-Git: https://salsa.debian.org/ruby-team/ruby-gepub.git
      -Vcs-Browser: https://salsa.debian.org/ruby-team/ruby-gepub
       Homepage: http://github.com/skoji/gepub
      -Testsuite: autopkgtest-pkg-ruby
       XS-Ruby-Versions: all
       Rules-Requires-Root: no
      
      @@ -24,5 +20,5 @@
       XB-Ruby-Versions: ${ruby:Versions}
       Depends: ${misc:Depends},
                ${ruby:Depends},
                ${shlibs:Depends}
      -Description: a generic EPUB library for Ruby.
      +Description: gepub is a generic EPUB library for Ruby.
        gepub is a generic EPUB parser/generator. Generates and parse EPUB2 and EPUB3

      To allow Debian tooling to understand the copyright and license of the gepub library I adjusted debian/copyright. With it I wanted to point out, that the library itself is released under a 3 clause BSD license, while my packaging code is not licensed at all. The Debian standard for machine readable license documents doesn’t seem to have an option for no license, so I just made that “None” attribute up, because at the time, I did not want to spend any time thinking about licensing. If you intend to provide your package and its source to a wider audience, or do more fancy things to build the package, it would probably make it more useful for the consumers to issue a permissive license for use and modification here.

       Upstream-Name: gepub
       Source: http://github.com/skoji/gepub
      
       Files: *
      -Copyright: <years> <put author's name and email here>
      -           <years> <likewise for another author>
      -License: Expat (FIXME)
      +Copyright: 2010-2014 KOJIMA Satoshi
      +License: BSD-3-clause
      + Redistribution and use in source and binary forms, with or without
      + modification, are permitted provided that the following conditions are met:
      + .
      +     * Redistributions of source code must retain the above copyright
      +       notice, this list of conditions and the following disclaimer.
      +     * Redistributions in binary form must reproduce the above copyright
      +       notice, this list of conditions and the following disclaimer in the
      +       documentation and/or other materials provided with the distribution.
      +     * Neither the name of the <organization> nor the
      +       names of its contributors may be used to endorse or promote products
      +       derived from this software without specific prior written permission.
      + .
      + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
      + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
      + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      + DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
      + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
      + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
      + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
      + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
      + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      
       Files: debian/*
       Copyright: 2023 Alexander E. Fischer <aef@example.net>
      -License: Expat (FIXME)
      -Comment: The Debian packaging is licensed under the same terms as the source.
      -
      -License: Expat
      - Permission is hereby granted, free of charge, to any person obtaining a copy
      - of this software and associated documentation files (the "Software"), to deal
      - in the Software without restriction, including without limitation the rights
      - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      - copies of the Software, and to permit persons to whom the Software is
      - furnished to do so, subject to the following conditions:
      - .
      - The above copyright notice and this permission notice shall be included in
      - all copies or substantial portions of the Software.
      - .
      - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      - THE SOFTWARE.
      +License: None
      + All rights reserved

      Some of the package source files might be deleted if you again don’t aim to upload the package into the Debian project:

      rm debian/salsa-ci.yml
      rm debian/upstream/metadata
      rm debian/watch

      Building the package

      Now the ruby-gepub Debian package is ready to be built with the following command:

      debuild

      There might be benefits to consider using pbuilder instead of debuild, because that uses a more isolated and standardized building environment, so that the package sources are more likely to be buildable on systems other than your own. But I did not chose to investigate it this time.

    1. 0 Responses

      leave a comment
    2. Leave a comment: