Debian Packaging Tutorial
Total Page:16
File Type:pdf, Size:1020Kb
Debian Packaging Tutorial Lucas Nussbaum [email protected] version 0.27 – 2021-01-08 Debian Packaging Tutorial 1 / 89 About this tutorial I Goal: tell you what you really need to know about Debian packaging I Modify existing packages I Create your own packages I Interact with the Debian community I Become a Debian power-user I Covers the most important points, but is not complete I You will need to read more documentation I Most of the content also applies to Debian derivative distributions I That includes Ubuntu Debian Packaging Tutorial 2 / 89 Outline 1 Introduction 2 Creating source packages 3 Building and testing packages 4 Practical session 1: modifying the grep package 5 Advanced packaging topics 6 Maintaining packages in Debian 7 Conclusions 8 Additional practical sessions 9 Answers to practical sessions Debian Packaging Tutorial 3 / 89 Outline 1 Introduction 2 Creating source packages 3 Building and testing packages 4 Practical session 1: modifying the grep package 5 Advanced packaging topics 6 Maintaining packages in Debian 7 Conclusions 8 Additional practical sessions 9 Answers to practical sessions Debian Packaging Tutorial 4 / 89 Debian I GNU/Linux distribution I 1st major distro developed “openly in the spirit of GNU” I Non-commercial, built collaboratively by over 1,000 volunteers I 3 main features: I Quality – culture of technical excellence We release when it’s ready I Freedom – devs and users bound by the Social Contract Promoting the culture of Free Software since 1993 I Independence – no (single) company babysitting Debian And open decision-making process (do-ocracy + democracy) I Amateur in the best sense: done for the love of it Debian Packaging Tutorial 5 / 89 Debian packages I .deb files (binary packages) I A very powerful and convenient way to distribute software to users I One of the two most common package formats (with RPM) I Universal: I 30,000 binary packages in Debian ! most of the available free software is packaged in Debian! I For 12 ports (architectures), including 2 non-Linux (Hurd; KFreeBSD) I Also used by 120 Debian derivative distributions Debian Packaging Tutorial 6 / 89 The Deb package format I .deb file: an ar archive $ ar tv wget_1.12-2.1_i386.deb rw-r--r-- 0/0 4 Sep 5 15:43 2010 debian-binary rw-r--r-- 0/0 2403 Sep 5 15:43 2010 control.tar.gz rw-r--r-- 0/0 751613 Sep 5 15:43 2010 data.tar.gz I debian-binary: version of the deb file format, "2.0\n" I control.tar.gz: metadata about the package control, md5sums, (pre|post)(rm|inst), triggers, shlibs,... I data.tar.gz: data files of the package I You could create your .deb files manually http://tldp.org/HOWTO/html_single/Debian-Binary-Package-Building-HOWTO/ I But most people don’t do it that way This tutorial: create Debian packages, the Debian way Debian Packaging Tutorial 7 / 89 Tools you will need I A Debian (or Ubuntu) system (with root access) I Some packages: I build-essential: has dependencies on the packages that will be assumed to be available on the developer’s machine (no need to specify them in the Build-Depends: control field of your package) I includes a dependency on dpkg-dev, which contains basic Debian-specific tools to create packages I devscripts: contains many useful scripts for Debian maintainers Many other tools will also be mentioned later, such as debhelper, cdbs, quilt, pbuilder, sbuild, lintian, svn-buildpackage, git-buildpackage,... Install them when you need them. Debian Packaging Tutorial 8 / 89 General packaging workflow Debian mirror Web upstream source apt-get source dget dh_make source package where most of the manual work is done debuild (build and test with lintian) or dpkg-buildpackage one or several binary packages .deb upload (dput) install (debi) Debian Packaging Tutorial 9 / 89 Example: rebuilding dash 1 Install packages needed to build dash, and devscripts sudo apt-get build-dep dash (requires deb-src lines in /etc/apt/sources.list) sudo apt-get install --no-install-recommends devscripts fakeroot 2 Create a working directory, and get in it: mkdir /tmp/debian-tutorial ; cd /tmp/debian-tutorial 3 Grab the dash source package apt-get source dash (This needs you to have deb-src lines in your /etc/apt/sources.list) 4 Build the package cd dash-* debuild -us -uc (-us -uc disables signing the package with GPG) 5 Check that it worked I There are some new .deb files in the parent directory 6 Look at the debian/ directory I That’s where the packaging work is done Debian Packaging Tutorial 10 / 89 Outline 1 Introduction 2 Creating source packages 3 Building and testing packages 4 Practical session 1: modifying the grep package 5 Advanced packaging topics 6 Maintaining packages in Debian 7 Conclusions 8 Additional practical sessions 9 Answers to practical sessions Debian Packaging Tutorial 11 / 89 Source package I One source package can generate several binary packages e.g. the libtar source generates the libtar0 and libtar-dev binary packages I Two kinds of packages: (if unsure, use non-native) I Native packages: normally for Debian specific software (dpkg, apt) I Non-native packages: software developed outside Debian I Main file: .dsc (meta-data) I Other files depending on the version of the source format I 1.0 or 3.0 (native): package_version.tar.gz I 1.0 (non-native): I pkg_ver.orig.tar.gz: upstream source I pkg_debver.diff.gz: patch to add Debian-specific changes I 3.0 (quilt): I pkg_ver.orig.tar.gz: upstream source I pkg_debver.debian.tar.gz: tarball with the Debian changes (See dpkg-source(1) for exact details) Debian Packaging Tutorial 12 / 89 Source package example (wget_1.12-2.1.dsc) Format: 3.0 (quilt) Source: wget Binary: wget Architecture: any Version: 1.12-2.1 Maintainer: Noel Kothe <[email protected]> Homepage: http://www.gnu.org/software/wget/ Standards-Version: 3.8.4 Build-Depends: debhelper (>> 5.0.0), gettext, texinfo, libssl-dev (>= 0.9.8), dpatch, info2man Checksums-Sha1: 50d4ed2441e67[..]1ee0e94248 2464747 wget_1.12.orig.tar.gz d4c1c8bbe431d[..]dd7cef3611 48308 wget_1.12-2.1.debian.tar.gz Checksums-Sha256: 7578ed0974e12[..]dcba65b572 2464747 wget_1.12.orig.tar.gz 1e9b0c4c00eae[..]89c402ad78 48308 wget_1.12-2.1.debian.tar.gz Files : 141461b9c04e4[..]9d1f2abf83 2464747 wget_1.12.orig.tar.gz e93123c934e3c[..]2f380278c2 48308 wget_1.12-2.1.debian.tar.gz Debian Packaging Tutorial 13 / 89 Retrieving an existing source package I From the Debian archive: I apt-get source package I apt-get source package=version I apt-get source package/release (You need deb-src lines in sources.list) I From the Internet: I dget url-to.dsc I dget http://snapshot.debian.org/archive/debian-archive/ 20090802T004153Z/debian/dists/bo/main/source/web/ wget_1.4.4-6.dsc (snapshot.d.o provides all packages from Debian since 2005) I From the (declared) version control system: I debcheckout package I Once downloaded, extract with dpkg-source -x file.dsc Debian Packaging Tutorial 14 / 89 Creating a basic source package I Download the upstream source (upstream source = the one from the software’s original developers) I Rename to <source_package>_<upstream_version>.orig.tar.gz (example: simgrid_3.6.orig.tar.gz) I Untar it I Rename the directory to <source_package>-<upstream_version> (example: simgrid-3.6) I cd <source_package>-<upstream_version> && dh_make (from the dh-make package) I There are some alternatives to dh_make for specific sets of packages: dh-make-perl, dh-make-php,... I debian/ directory created, with a lot of files in it Debian Packaging Tutorial 15 / 89 Files in debian/ All the packaging work should be made by modifying files in debian/ I Main files: I control – meta-data about the package (dependencies, etc.) I rules – specifies how to build the package I copyright – copyright information for the package I changelog – history of the Debian package I Other files: I compat I watch I dh_install* targets *.dirs, *.docs, *.manpages, . I maintainer scripts *.postinst, *.prerm, . I source/format I patches/ – if you need to modify the upstream sources I Several files use a format based on RFC 822 (mail headers) Debian Packaging Tutorial 16 / 89 debian/changelog I Lists the Debian packaging changes I Gives the current version of the package 1.2.1.1-5 Upstream Debian version revision I Edited manually or with dch I Create a changelog entry for a new release: dch -i I Special format to automatically close Debian or Ubuntu bugs Debian: Closes: #595268; Ubuntu: LP: #616929 I Installed as /usr/share/doc/package /changelog.Debian.gz mpich2 (1.2.1.1-5) unstable; urgency=low * Use /usr/bin/python instead of /usr/bin/python2.5. Allow to drop dependency on python2.5. Closes: #595268 * Make /usr/bin/mpdroot setuid. This is the default after the installation of mpich2 from source, too. LP: #616929 + Add corresponding lintian override. -- Lucas Nussbaum <[email protected]> Wed, 15 Sep 2010 18:13:44 +0200 Debian Packaging Tutorial 17 / 89 debian/control I Package metadata I For the source package itself I For each binary package built from this source I Package name, section, priority, maintainer, uploaders, build-dependencies, dependencies, description, homepage, . I Documentation: Debian Policy chapter 5 https://www.debian.org/doc/debian-policy/ch-controlfields Source: wget Section: web Priority: important Maintainer: Noel Kothe <[email protected]> Build-Depends: debhelper (>> 5.0.0), gettext, texinfo, libssl-dev (>= 0.9.8), dpatch, info2man Standards-Version: 3.8.4 Homepage: http://www.gnu.org/software/wget/ Package: wget Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: retrieves files from the web