% on the following slides, include icon in the left sidebar
\def\lximg{/usr/share/lx/icons/fueller.png}

\input{configpres}

\section{Debian}
\title{Building Debian Packages}
\maketitle

% stop displaying 'fueller.png' on the following slides
\def\lximg{none}

\subsection{Basics}
\begin{frame}
\frametitle{Debian Packages}
\begin{itemize}
\item Binary packages
\item Source packages
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{Binary packages}
\begin{alertblock}{What is a binary package?}
A binary package contains executables, configuration files, documentation and
copyright information.
\end{alertblock}
\end{frame}

\begin{frame}
\frametitle{Package types}
\begin{itemize}
\item single binary
\item multiple binary
\item library
\item kernel module
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{Source packages}
\begin{alertblock}{What is a source package?}
A source package contains the unmodified source code of a package and usually a file
which describes the debian specific changes.
\end{alertblock}
\end{frame}

\begin{frame}[fragile]
\frametitle{Binary packages}
\small
\begin{verbatim}
$ ar tv barcode_0.98+debian-8_amd64.deb
rw-r--r-- 0/0      4 Sep 11 15:40 2009 debian-binary
rw-r--r-- 0/0    889 Sep 11 15:40 2009 control.tar.gz
rw-r--r-- 0/0  79118 Sep 11 15:40 2009 data.tar.gz
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Binary packages}
\begin{verbatim}
debian-binary
\end{verbatim}
Contains the version of the Debian file format.
\end{frame}

\begin{frame}[fragile]
\frametitle{Binary packages}
\begin{verbatim}
data.tar.gz
\end{verbatim}
Contains the files to be installed.
\end{frame}

\begin{frame}[fragile]
\frametitle{Binary packages}
\begin{verbatim}
control.tar.gz
\end{verbatim}
Contains the ''administrative'' files, like ''control'', ''md5sums'', ...
\end{frame}

\begin{frame}[fragile]
\frametitle{Source packages}
\begin{verbatim}
$ apt-get source barcode
[...]
$ ls -1
total 376
barcode-0.98+debian
barcode_0.98+debian-8.diff.gz
barcode_0.98+debian-8.dsc
barcode_0.98+debian.orig.tar.gz
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Source packages}
\begin{verbatim}
barcode_0.98+debian.orig.tar.gz
\end{verbatim}
Contains the original unmodified source code.
\end{frame}

\begin{frame}[fragile]
\frametitle{Source packages}
\begin{verbatim}
barcode_0.98+debian-8.diff.gz
\end{verbatim}
Contains the debian specific changes. If there's no difference to the upstream
package, only the .tar.gz file will be provided.
\end{frame}

\begin{frame}[fragile]
\frametitle{Source packages}
\begin{verbatim}
barcode_0.98+debian-8.dsc
\end{verbatim}
Contains meta-information about the source package.
\end{frame}

\begin{frame}[fragile]
\frametitle{Source packages: The debian/ directory}
\begin{verbatim}
$ ls -1 barcode-0.98+debian/debian/
[...]
changelog
control
copyright
rules
[...]
\end{verbatim}
\end{frame}

\begin{frame}
\frametitle{debian/control}
Contains a couple of fields describing the package:
\begin{itemize}
\item Architecture
\item Dependencies
\item Maintainer
\item Description
\item Section
\item ...
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{debian/rules}
This is a Makefile containing some rules on how to handle the source files.
Mandatory targets are:
\begin{itemize}
\item clean
\item build
\item binary
\item binary-arch
\item binary-indep
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{debian/changelog}
Information about:
\begin{itemize}
\item version number
\item revisions
\item bugfixes
\end{itemize}
\end{frame}

\begin{frame}
\frametitle{debian/copyright}
Copyright information:
\begin{itemize}
\item author(s)
\item upstream author(s)
\item licensing information
\end{itemize}
\end{frame}

\subsection{Creating Debian Packages}
\begin{frame}[fragile]
\frametitle{Documentation}
\begin{verbatim}
$ apt-get install debian-policy
$ ls /usr/share/doc/debian-policy/
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Building binary packages}
\begin{enumerate}
\item Download / Create the source code
\item Prepare a skeleton using dh\_make
\item Customize the files in debian/
\item Build the package using dpkg-buildpackage
\item Optional: Debug using lintian or linda
\end{enumerate}
\end{frame}

\begin{frame}[fragile]
\frametitle{Setting up the environment}
\begin{lstlisting}
export DEBEMAIL=musermann@mustermail.org
export DEBFULLNAME="Max Mustermann"
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{Preparing / Building}
Exercise:
\begin{enumerate}
\item Create a directory hello-1.2.3
\item Change to the directory and create hello.c and a corresponding Makefile (which should also provide a clean target)
\item Then do:
\end{enumerate}
\begin{lstlisting}
# tar your sources
tar zvf hello-1.2.3.tar.gz hello-1.2.3
# 
$ cd hello-1.2.3
$ dh_make -f ../hello-1.2.3.tar.gz
\end{lstlisting}
\end{frame}

\begin{frame}[fragile]
\frametitle{dh\_make}
\tiny
\begin{verbatim}
Type of package: single binary, multiple binary, library, kernel module or
cdbs?
 [s/m/l/k/b] s

Maintainer name : Max Mustermann
Email-Address   : musermann@mustermail.org 
Date            : Fri, 25 Feb 2011 10:53:00 +0000
Package Name    : hello
Version         : 1.2.3
License         : blank
Using dpatch    : no
Type of Package : Single
Hit <enter> to confirm: 
Done. Please edit the files in the debian/ subdirectory now. You should also
check that the hello Makefiles install into $DESTDIR and not in / .
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Adjust the files}
\tiny
\begin{verbatim}
# debian/control
Source: hello
Section: unknown
Priority: extra
Maintainer: Max Mustermann <musermann@mustermail.org>
Build-Depends: debhelper (>= 7)
Standards-Version: 3.7.3
Homepage: <insert the upstream URL, if relevant>

Package: hello
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: <insert up to 60 chars description>
 <insert long description, indented with spaces>

\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Modify debian/rules}
If your Makefile doesn't provide an install target, modify the following line:\\
Replace
\begin{verbatim}
install:
  [...]

  $(MAKE) DESTDIR=$(CURDIR)/debian/hello install
\end{verbatim}
by
\begin{verbatim}
install:
  [...]

  install -D -m 755 hello \
       $(CURDIR)/debian/hello/bin/hello
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Building the package}
Now you can build the package with:
\begin{verbatim}
dpkg-buildpackage
\end{verbatim}
Afterwards you should see a file named hello\_1.2.3-1\_i386.deb in ../
\small
\begin{verbatim}
$ dpkg -I ../hello_1.2.3-1_i386.deb
new debian package, version 2.0.
 size 3028 bytes: control archive= 536 bytes.
     330 bytes,    11 lines      control              
     246 bytes,     4 lines      md5sums              
 Package: hello
 Version: 1.2.3-1
 Architecture: i386
 Maintainer: Max Mustermann <musermann@mustermail.org>
[...]
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Packages based on binary data}
\begin{verbatim}
mkdir debian
mkdir debian/bin
mkdir debian/DEBIAN
cp hello debian/bin
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Packages based on binary data}
vim debian/DEBIAN/control
\small
\begin{verbatim}
Package: hellobin
Version: 0815
Section: misc
Priority: optional
Architecture: all
Depends: libc6 (>= 2.6)
Maintainer: Max Mustermann
Description: 42
 The hitchhikers guide might give you some more
 information about the number 42 ;)
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{Packages based on binary data}
\begin{verbatim}
$ dpkg-deb --build debian hellobin.deb
$ dpkg -I hellobin.deb
 new debian package, version 2.0.
 size 3304 bytes: control archive= 317 bytes.
     234 bytes,    10 lines      control              
 Package: hellobin
...
\end{verbatim}
\end{frame}

\subsection{debconf}
\begin{frame}[fragile]
\frametitle{debconf: The template file}
vim debian/hello.templates
\begin{verbatim}
Template: hello/some_question
Type: boolean
Description: Just say yes or no ;-)
 Just a simple debconf example.
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{debconf: The config file}
vim debian/hello.config
\begin{verbatim}
. /usr/share/debconf/confmodule

db_input critical hello/some_question
db_go
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{debconf: The config file}
vim debian/rules
\begin{verbatim}
...
dh_installdebconf
...
\end{verbatim}
\end{frame}

\begin{frame}[fragile]
\frametitle{debconf: The config file}
vim debian/hello.postinst
\begin{verbatim}
#!/bin/sh -e

. /usr/share/debconf/confmodule

db_get hello/some_question
echo user answered "$RET"
\end{verbatim}
\end{frame}

\subsection{sources}
\begin{frame}
\begin{thebibliography}{1}
\bibitem{debm} http://www.debian.org/doc/maint-guide/
\bibitem{tldp} http://tldp.org/HOWTO/Debian-Binary-Package-Building-HOWTO/x60.html
\bibitem{abut} Grundlagen des Debian Paketverwaltungssystems - Fatih Abut (Hochschule Bonn-Rhein-Sieg)
\end{thebibliography} 

\end{frame}
\input{tailpres}
