Sometimes fun problems come up: we need to install a certain program, but the version we need isn't available (for example, PHP 5.3), and we can't (don't want to, aren't allowed to) add extra (unstable, unreliable) repositories to our system, or we simply couldn't find one. But we do have the sources from the official site. It would seem simple enough: just grab them and build from source. But we're lazy people and we understand that we'll need to build from source again next time, or we'll need to do the same thing on several other machines. Why bother?
So we take a different route - we build the package itself for ourselves. The whole process is described in the official guide, but in this article we'll look at a simpler version of it.
Preparing the system.
To compile the program and build the package we'll need some developer tools:
# aptitude install binutils cpp cpio dpkg-dev file gcc libc6-dev make patch perl5-5.005 dh-make debhelper devscripts fakeroot lintian debian-policy developers-reference
(you can find out more about each package in the official guide)
For convenience let's create a separate folder, for example packages, and then place the source tree of the package we're going to build into it.
So we end up with ~/pkg/pkg-1.1
The directory with the sources must be named like this: <packetName>-<version>.
Let's prepare the package for building
cd ~/pkg/
tar -c packet-3.2|gzip -9 >pkg-1.1.tar.gz
cd pkg-1.1/
dh_make -e your@email.com -f ../pkg-1.1.tar.gz
Or for an archive:
mv ~/Downloads/pkg-1.1.tar.gz ~/pkg/
cd ~/pkg/
tar xvzf pkg-1.1.tar.gz
cd pkg-1.1
dh_make -e your@email.com -f ../pkg-1.1.tar.gz
While it runs, dh_make will ask about a couple of things we won't dwell on - it's all clear enough if you're comfortable with English.
An archive pkg.tar.gz and an additional directory ~/pkg/pkg-1.1/debian with the necessary files will be created.
$ ls
changelog
compat
control
copyright
cron.d.ex
dirs
docs
emacsen-install.ex
emacsen-remove.ex
emacsen-startup.ex
init.d.ex
init.d.lsb.ex
manpage.1.ex
manpage.sgml.ex
manpage.xml.ex
menu.ex
postinst.ex
postrm.ex
preinst.ex
prerm.ex
README.Debian
rules
packet-default.ex
packet.doc-base.EX
watch.ex
dh_make did a good job creating the files, though we don't need all of them.
The control file
Source: Package name
Section: contrib/net - section
Priority: optional
Maintainer: Andry Bel <name@mail.domain>
Build-Depends: debhelper (>= 7) build dependencies for the package
Standards-Version: 3.7.3 - Debian Policy version - I won't go into detail here
Homepage: http://your.domain.name/name/of/project - url from which the package can be downloaded
Package: Package name
Architecture: any - the architecture it's built for (i386, ppc, sparc, etc.)
Depends: ${shlibs:Depends}, ${misc:Depends} - which packages it depends on
Description: apache log analyzer
Apache log files analyzer, generates single-file-report in html format
Description - a short description of the package. The next line should contain the full description. Note, the first character must be a space.
The changelog file:
packet (3.2-1) unstable; urgency=low
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP>
-- Your Name <your@mail.name> Wed, 03 Sep 2008 11:02:51 +0400
Seems clear enough.
The copyright file - no questions there, an example:
This package was debianized by Andry Bel <zaezzz@how-it.ru> on
Wed, 03 Sep 2008 11:02:51 +0400.
It was downloaded from http://yourdomain.name/project/name
Upstream Author(s):
Andry Bel <zaezzz@how-it.ru>
Copyright: Copyright (C) 2011 Andry Bel License: GPL The Debian packaging is (C) 2011, Andry Bel <zaezzz@how-it.ru> and is licensed under the GPL, see `/usr/share/common-licenses/GPL'. # Please also look if there are files or directories which have a # different copyright/license attached and list them here.
Indentation is mandatory here.
The dirs file - names of directories that must exist for installation. The leading slash is omitted.
usr/bin
usr/sbin
Not all files will be useful to us; you can delete them after first reading the comments in the files themselves.
rm docs init.d.ex init.d.lsb.ex cron.d.ex manpage.* menu.ex README.Debian watch.ex packet-default.ex packet.doc-base.EX
We leave the files emacsen-install.ex, emacsen-remove.ex, emacsen-startup.ex unchanged.
The files postinst.ex, postrm.ex, preinst.ex, prerm.ex are scripts that run before/after installation/removal. They contain exhaustive comments and an empty skeleton.
The main file, rules.
Changed:
#$(MAKE) DESTDIR=$(CURDIR)/debian/pkg install
install -m 0755 pkg $(dstdir)/usr/bin
If you don't change it, our package will be installed into the root, which is obviously unacceptable
Everything is ready.
Let's build it:
cd ~/pkg/pkg-1.1/
dpkg-buildpackage -rfakeroot
Done. The installation file pkg-1.1.deb has appeared in the ~/pkg/ directory.
Let's look at it to make sure everything went correctly:
dpkg-deb -I ../packet_3.2-1_i386.deb
dpkg --contents ../packet_3.2-1_i386.deb
Looks like everything is fine. Let's install it.
sudo dpkg -i ../packet_3.2-1_i386.deb
Comments