Windows.  Viruses.  Notebooks.  Internet.  office.  Utilities.  Drivers

deb file is an archive in the format ar, containing setup files programs, information about the program, as well as scripts (command files) that are executed before and after installation and removal of the program (the presence of scripts is optional - they may not be included in the package).

The format of the deb file is described in the man pages (man pages) deb(5) - this help is displayed if you type the command man deb in the terminal. There are also many pages on the Internet containing this information - just type deb(5) into the search bar to find them. This manual is not included here because the official Debian Developers Manual, the Package Format Reference (which, at the time of this writing, is located at http://www.debian.org/doc/manuals/debian-faq/ch- pkg_basics.en.html) it is written that the format of packages can change, and therefore it is recommended to use the dpkg-deb utility to work with them. You can get help with the dpkg-deb utility by typing man dpkg-deb in a terminal.

The work of the GUI-deb program is precisely to create a directory containing the necessary data, and run the dpkg-deb program, specifying this directory and other necessary parameters.

The correct directory needed for dpkg-deb to create an installation package must first of all contain a "DEBIAN" subdirectory. This directory should contain all data that is not copied to the system, but used directly by programs for working with packages - information about the package, scripts executed before and after installation, etc. Any files contained in the DEBIAN directory will not end up on the file system of the computer on which the package is installed when the package is installed.

Outside the "DEBIAN" directory are those files that will be copied to the file system of the computer on which the package will be installed. The files must be located in the directories in which they will be placed when installing the package. That is, inside the directory created for dpkg-deb, a copy of the parts of the file system we need should be created - as if this directory were its root ("/"). That is, for example, if the name of the directory on the basis of which the package will be created is "~/TMP_DEBS/MyProgram", and it is necessary that when installing in file system the file "MyProgram.png" was written to the "/usr/share/pixmaps" directory - you need to create the "usr" directory in the "~/TMP_DEBS/MyProgram" directory, in it - the "share" directory, inside "share" - the "pixmaps" directory ", and already in the "pixmaps" directory place the file "MyProgram.png". As a result, the full path to the file will be "~/TMP_DEBS/MyProgram/usr/share/pixmaps/MyProgram.png". When creating a package, a part of the "~/TMP_DEBS/MyProgram" directory will be truncated, and during installation, the "MyProgram.png" file will just get to the desired address "/usr/share/pixmaps". Thus, the necessary directories must be created for each file.

After creating the directory, all that remains is to run dpkg-deb, passing the necessary parameters. The most important dpkg-deb options for building packages are described in the section "Command line options for the dpkg-deb utility" . If there are no errors in the control file, the installation package will be created.

I described building the program from source, as well as creating a simple deb package. This time I want to dwell on their creation in more detail. This guide does not claim to be a guide for developers or maintainers, so at the end I will provide links to detailed guides from developers Debian.

There are quite a few ways to create a deb package. I won't describe the large build systems that are used on build servers here, because most people don't need to. I will describe two of the most simple ways creating your package. First of all, we need to install some tools for work:

sudo apt-get install build-essential git automake devscripts make libtool fakeroot automake autotools-dev

Next, you need to create a digital key. This step is optional, but if you plan to redistribute your packages, it would be extremely wise to sign them with your key. This will allow the user who downloaded your package to verify that it was you who created it. To create a key, you can use graphic utilities ( sea ​​horse, kgpg) or in the terminal:

DEBEMAIL="your E-Mail that you specified when creating the key"
DEBFULLNAME="Your name (or alias)"
export DEBEMAIL DEBFULLNAME

This will automatically add your digital signature when signing packages. Next, we need an archive with source code. I will conduct a simple example, because, depending on the complexity of the program, additional configuration is required (creation of post-installation scripts, assembly rules, etc.). Suppose we have an archive with the source code of the program "myprogramm" - myprogramm_1.0.tar.gz. Unpack it to your home directory (or any where you prefer). Please note: the directory after unpacking must have the name myprogramm-1.0. Name followed by a dash - version number. Now open a terminal and run:

cd ~/myprogramm-1.0
dh_make --createorig

We moved into the source directory and created an archive with it and a basic debianization. After the second command, a message will be displayed where you need to select the package type: s (single, single), m (multiple, several packages), l (library, library), k (kernel module, kernel module). In our case, this is s. Now we need to set things up a bit. Go to /myprogramm-1.0/debian directory and open the file control in any text editor. This is the main file for building the package. It contains all the basic information. It looks something like this:

Source: myprogram
Section: admin
Priority: optional
Maintainer: Aleksey Samoilov
Build-Depends: debhelper (>= 5)
Standards-Version: 3.9.6
Homepage: http://www.example.com

Package: myprogram
Architecture: all
Depends: $(shlib:Depends), $(misc:Depends)
Section: admin
Priority: optional
Description: My new program
My programm is a simple example to build your own deb-package

Let's go in order. The first section contains the name of the source package. Next, the software section (in this case admin). Then the priority (optional), the name of the maintainer and his E-Mail (i.e. yours), build dependencies (packages needed for building), version of the standard (on this moment 3.9.7), followed by the name of the package after the build, the architecture for which it is built (all means all supported architectures), software section, priority, short description And Full description. Since our example is simple, this is enough to get started. You can also open the file copyright and enter your name and e-mail there. In file changelog contains a list of changes for each version of this software. Since this is the first build, you need to indicate that this is First Release, and also close a certain bug (lack of this package in the repository). The bug number can be written from the bulldozer. If you are rebuilding a package, first change its version with the command dch-i Files in the debian directory with extensions .ex are examples. When building more complex packages, you will need these additional files. These are, for example, post-installation scripts ( postinst), a file that checks for new version tarball with source code ( watch) and so on. File rules is a makefile, the rules for assembling the package. For simple programs you can not change it, in other cases - you need to edit it, to specify the assembly parameters, or install icons. Many things.

Now that you have filled in the control file, you can start building. To do this, while in the directory with the source code, run the command debuild. The system will configure, compile the program, pack it into a package, check for common errors during debianization and ask you to enter the password for your key twice (if you did not create it, then nothing will happen). Now in the directory one level higher (in our case, in the home directory), you will see several files, among which the deb package you are looking for. Now it can be installed with the command sudo dpkg -i myprogramm-1.0-1.deb or in the Gdebi graphical manager.

This is how you can assemble a simple package. But what if you don't want to litter the system with a bunch of build dependencies? Moreover, when building some packages, some modified files may be used. For example, newer versions of libraries, if you updated the system from backports, or various changes in configs. On similar cases you can use virtual machine, container, or use a special tool called pbulder. pbuilder is a tool for creating a clean environment that contains only what is needed for the build. The system does not get clogged. junk files, and the assembly of the program takes place in the laboratory. Install:

sudo apt install pbuilder

I will give an example of my config, with which you can build packages not only for different Debian releases, but also for Ubuntu.

sudo nano /etc/pbuilderrc

Paste the following content:

STABLE_CODENAME="stable"
OLDSTABLE_CODENAME="oldstable"
DEBIAN_SUITES=($UNSTABLE_CODENAME, $TESTING_CODENAME, $STABLE_CODENAME $STABLE_BACKPORTS_SUITE $OLDSTABLE_CODENAME
"sid" "stretch" "jessie" "wheezy")
UBUNTU_SUITES=("precise" "trusty" "xenial")
UBUNTU_MIRROR="mirror.yandex.ru"
DEBIAN_MIRROR="mirror.yandex.ru"
: $(DIST:="$(lsb_release --short --codename)")
: $(ARCH:="$(dpkg --print-architecture)")

NAME="$DIST"
if [ -n "$(ARCH)" ]; then
NAME="$NAME-$ARCH"
# the next line is needed in order to build for different architectures
DEBOOTSTRAPOPTS=("--arch" "$ARCH" "$(DEBOOTSTRAPOPTS[@])")
fi

BASETGZ="/home/sunderland93/pbuilder/$NAME-base.tgz"
DISTRIBUTION="$DIST"
BUILDRESULT="/home/sunderland93/pbuilder/$DIST/result/"
APTCACHE="/home/sunderland93/pbuilder/$NAME/aptcache/"
BUILDPLACE="/home/sunderland93/pbuilder/build/"
if $(echo $(DEBIAN_SUITES[@]) | grep -q $DIST); then
MIRRORSITE="http://$DEBIAN_MIRROR/debian/"
COMPONENTS="main contrib non-free"
elif $(echo $(UBUNTU_SUITES[@]) | grep -q $DIST); then
MIRRORSITE="http://$UBUNTU_MIRROR/ubuntu/"
COMPONENTS="main restricted universe multiverse"
else
echo "Unknown distribution: @DIST"
exit 1
fi

export DPKG_GENSYMBOLS_CHECK_LEVEL=4
USE_PDEBUILD_INTERNAL=yes

Replace sunderland93 ​​with your system name. Thus, we will be able to build packages for Debian 7, 8, testing and unstable, as well as for Ubuntu 12.04, 14.04 and 16.04. Dependencies downloaded for assembly will be in pbuilder/distribution name/aptcache. By the way, this is very useful - we will have a base archive that will not be clogged with left-handed dependencies and weigh several gigabytes. And the environment will be prepared individually for each program. It is possible to sew these dependencies into the base archive, but I do not recommend doing this. Now let's create a base archive containing a clean build environment. Let's take Debian 8 64-bit as an example:

sudo DIST=jessie ARCH=amd64 pbuilder --create

The archive creation process will begin. After it is ready, you can start building the program. To do this, open a terminal, go to the directory with the source code, and execute:

sudo DIST=jessieARCH=amd64 pdebuild

And we are waiting. The downloaded packages will be cached, and next time I will not download. After building, the finished deb package will appear in the directory pbuilder/jessie/result. That's all.

Today I will tell on an abstract example how Right create *.deb package for Ubuntu/Debian. We will make the package binary. Packages that compile binaries from sources are not considered here: having mastered the knowledge presented below, in the future, using ready-made examples, you can understand the essence and act by analogy :)

There will be no unnecessary fuss “manually” in the article: the package format has evolved into a fairly simple, and most importantly, logical structure, and everything is done literally on the knee, using a couple of specialized utilities.

As a bonus, at the end of the article there will be an example of quickly creating your own local repository: installing packages from the repository allows you to automatically track dependencies, and of course! - install all one console command on multiple machines :)

For those who do not want to go into the powerful software installation system in Linux, I recommend visiting the CheckInstall program site: it automatically creates a deb package from the “make install” command;) And we, along with the curious -

Sources

Information gleaned from many places, but here are the two main ones:
  • Debian.org: Debian Policy Manual - official
  • Ubuntu Wiki: Packaging Guide/Basic
This article details the basics of packaging enough to get some pretty powerful application installation control. More advanced features are omitted, but direct links to documentation are provided for those interested.
The article is not a copy or translation of any documentation: it is a collection of knowledge that was lying around in the form of notes, and is now formatted as an article. For clarity, there are examples everywhere, clarifications on the fingers, convenient features I found and some typical mistakes that can be made out of ignorance.

Preparation

Why is this all?
Yes, CheckInstall can create a working package, but it does not support all the goodies that deb packages are capable of :) Namely:
  • Scripts that run before, after and instead of installing a package :)
  • Automatic management of configuration files: the package will not allow you to overwrite old configs with new ones without asking
  • Working with templates: the ability to ask the user questions during installation (!!!)
  • Modifying other package files
What will be required
Of course, tar, gz, ar archivers are enough to create a full-fledged package, but you can eliminate unnecessary fuss and use tools created to make life easier :)
We put:
$ sudo apt-get install dpkg debconf debhelper lintian
What do we do
For example, a certain script /usr/bin/super.sh will be considered. It doesn't matter what's inside, the main thing is how it will appear in the right place :)
Folder preparation
In the home directory (or wherever convenient) create a folder that will contain all the files of the future package: mkdir ~/supersh . Hereafter, we will call it package root.
In the root of the package, create a folder "DEBIAN" ( capital letters, it is important!). This folder contains package generation control information, and is not copied to disk when the package is installed.
Also, the root folder of the package contains the future "root of the disk": when installing the package, all files (except the "debian" folder) are unpacked to the root /. so our script should be on this path, relative to the root of the package: "usr/bin/super.sh"
White on black:
mkdir -p ~/supersh/DEBIAN # control directory
mkdir -p ~/supersh/usr/bin # script path
cp super.sh ~/supersh/usr/bin/ # copy our script to the right place
As a result, we have:
supersh/DEBIAN/
supersh/usr/
supersh/usr/bin/
supersh/usr/bin/super.sh

Create package: DEBIAN/*

As I said, the DEBIAN folder contains the files used during the installation. Here I will describe (with examples) each file.
To create a full-fledged package, the “control” control file is enough, all the rest are used either to attach text information (changelog, license), or to manage advanced application installation options.
From the files described below in the DEBIAN / * folder, select the necessary ones and fill them in according to the instructions :)
In our example, only required DEBIAN/control.
DEBIAN/control: Basic information
control - the central package file that describes all the main properties. The file is a text file consisting of "Attribute: value" pairs. You can use comments: character "#" at the beginning of the line (feature was added in version dpkg >= 1.10.11, don't rely on comments :).
The table lists all the fields defined for the control file. Required fields highlighted bold: without them, the package will not be considered correct.
Attribute Description Examples
- basic -
package: Package name: - only Latin, numbers, and hyphens. Name used during installation: apt-get install Package: supersh
version: The version of the package (and the program inside). Used to determine whether to update.
The format adopted is:<версия_программы>-<версия_пакета> .
I recommend Always indicate the version of the package: when changing the structure of the package, the number increases by one.
Valid characters are quite free: you can use the date and letters. See examples today in your repository :)
Version: 1.0-1
Version: 2009.12.12-1
Provides The application name (possibly virtual) that is registered with the system as a result of installing this package.
Rarely used: mostly if you need to change the package name, or if more than one package offers the same functionality. For example, the Apache and nginx packages provide the httpd daemon capability: Provides: httpd
You must have encountered an error when trying to install: "is a virtual package". This is what it is :)
Provides: supersh
maintainer The name and email of the package maintainer: the person who "debianized" the application.
The format is arbitrary, but the name is accepted
Maintainer: o_O Tync
architecture The processor architecture for which the package is intended.
Valid values: i386, amd64, all, source
all is used for scripts: they are portable, right? :)
source is used for compiled source packages
Architecture: all
Section Specifies the task for which the application is typically used (application group).
Possible values: admin, base, comm, contrib, devel, doc, editors, electronics, embedded, games, gnome, graphics, hamradio, interpreters, kde, libs, libdevel, mail, math, misc, net, news, non-free , oldlibs, otherosfs, perl, python, science, shells, sound, tex, text, utils, web, x11
Section: misc
Description Description of the package.
The description consists of two parts: a short description (70 characters) on the same line, and a long description on subsequent lines, starting with a space.
In the extended description, all newlines are ignored. \n is inserted using a single dot.
Description: short.
␣Long
␣goes here.
␣.
␣New line.
- connections and dependencies -
Depends A comma-separated list of packages that are required to install this package.
After the package name, you can specify a version limit in parentheses using the operators:<<, =, >>, <=, >=. If the operator is not specified, >= is used.
Depends: dpkg, libz (>= 1.2.3), jpeg (= 6b), png (< 2.0)
Pre-Depends List of packages that are required during the installation of this package.
These dependencies may be required for package installation scripts: for example, the flash-installer package requires wget
You can use version restrictions (see Depends).
Pre-Depends: wget (>= 1.0)
Conflicts List of packages that cannot be installed at the same time as this.
The installation will fail if at least one of the listed packages is already installed.
conflicts: crapscript
Replaces List of packages whose files are modified by this package.
Required if you create a "patch package" that changes something: otherwise, when replacing the files of someone else's package, an installation error will occur. For example, I have such a package that patches UT2004 and removes the sound of a homing rocket launcher :)
Replaces: ut2004
Recommendations List of packages recommended for installation
These packages are optional, but are usually used in conjunction with the current
Recommended: superplatform
Suggestions List of packages offered for installation.
These packages are optional, but the program works even better with them :) In theory, the package manager should offer to install them.
Suggests: supersh-modules
Build-Depends (Only for Architecture: source)
List of packages required to compile sources.
Same as Depends, but logically separated.
Build-Depends: cmake
- extra -
Installed-Size Size of package files in kilobytes.
Just a number rounded to the nearest integer. Used by the package manager to determine the total disk space required.
Installed-Size: 3
priority Packet priority: how important it is in the system
Possible values: extra, optional, standard, important, required (such packages are not removed at all!).
Priority: optional
Essential If you set this attribute to "yes", the package cannot be removed. Essential: yes
origin String: where the programs in the package come from. Usually the URL of the author's site, mail or name is used. Origin: brain
X source Full link to *.tar.gz source archive X-Source: ...*.tgz

Yes, these are the solid features of the control file :)
And in our example, it looks like this:
Package: supersh
Version: 1.0-1
Section: misc
Architecture: all
Depends: bash, sed (>= 3.02-8)
Maintainer: o_O Tync
Description: Super Shell Script
␣A super example script.
␣.
␣It does nothing:)
DEBIAN/copyright:/license
License text. The file is not required, but it's better to underline your authorship;)
DEBIAN/changelog: changelog
Changelog in a special format: used by dpkg to get the version number, revision, distribution, and importance of a package. It's better to look in ;) and I'll just give an example:
supersh (1.0-1) stable; urgent=medium

O_O Tync Sun, 13 Dec 2009 00:11:46 +0300

DEBIAN/conffiles: list of configuration files
Packages usually contain blank configuration files, such as those placed in /etc. Obviously, if the config in the package is updated, the user will lose their edited config. This problem is easily solved by using folders like "config.d", the contents of which are included in the main config, replacing the repeated options.
The file "DEBIAN/conffiles" solves the problem in a different way: it contains a list of configuration files (one per line). If in current version package one of these files is updated, then the user receives a warning about the conflict of config versions, and can choose to delete, replace, or merge.
Every Linuxoid who delved into the configs probably faced this situation :) And the legs grow from here.
Each line must contain the full absolute path to each config. For example:
/etc/supersh/init.conf
/etc/supersh/actions.conf
DEBIAN/dirs: list of folders to create
"A list of absolute paths to folders that are required by the program, but for some reason are not created." - says the official documentation. In practice, all folders that are used by the program in one way or another are listed here: where the binaries are located, and which are used by the program.
One per line. For example:
/var/log/supersh
/var/lib/supersh
Useful for creating multiple empty folders.
DEBIAN/menu: creating menu items
A tricky file for creating menu items. It never worked for me :) One gets the feeling that its contents are used either in unusual window managers, or in some console menu ... or it was used earlier and was forgotten :)
Example:
?package(supersh):needs="text" section="Applications/Programming" title="Super Shell Script" command="/usr/bin/super.sh" !}
TODO: find out why you need to. This is written in man5 menufile , to be honest, I didn’t delve into it :)
UPD: Correct way to add a menu item
The /DEBIAN/menu file creates no one knows what and no one knows where: the graphical menu elements are not created anyway. So let's do it right :)
In /usr/share/applications we see a bunch of *.desktop files: these are the menu items. They represent text files with a syntax similar to an ini file. Open, learn, do the same and put the resulting *.desktop file in usr/share/applications/ . The icon for it should be in usr/share/pixmaps .
After that, you need to add the execution of the update-menus menu update command to the postinst script:
if [ "$1" = "configure" ] && [ -x "`which update-menus 2>/dev/null`" ] ; then
update-menus
fi

Working with package installation scripts will be discussed later.
Thanks Condorious for the tip :)

DEBIAN/md5sums: file checksums
Used to check the integrity of a package. Important file.
Filled like this (cwd=package root):
$ md5deep -r usr > DEBIAN/md5sums
DEBIAN/watch: monitoring the site where the program was downloaded from
The function is useful if you maintain more than a few dozen packages, and it is difficult to keep track of all the updates.
The file contains instructions for the uscan and uupdate programs. Using this feature, you can keep track of the site where the sources of the package were obtained from, and ensure the quality control of the distribution as a whole.
Example:
# Site Directory Pattern Version Script
ftp.obsession.se /gentoo gentoo-(.*)\.tar\.gz debian uupdate
DEBIAN/(preinst|postinst|prerm|postrm): installation scripts
In total, you can create up to four scripts in one package:

Please note that the errors that occur in these scripts not logged at all: nothing more interesting than the return code of the script is stored anywhere, and logging must be done manually! Users of one of my packages were failing to install on Linux Mint, and it was not even possible to ask them for an error log (which is not there) to debug the reason :)
I recommend using the following blank at the beginning of each script: it will save all errors that occur to the syslog.
#!/bin/bash
set -e # fail on any error
set -u # treat unset variables as errors

# ======[ Trap Errors ]======#
set -E # let shell functions inherit ERR trap

# Trap non-normal exit signals:
# 1/HUP, 2/INT, 3/QUIT, 15/TERM, ERR
trap err_handler 1 2 3 15 ERR
function err_handler(
local exit_status=$(1:-$?)
logger -s -p "syslog.err" -t "ootync.deb" "supersh.deb script "$0" error code $exit_status (line $BASH_LINENO: "$BASH_COMMAND")"
exit $exit_status
}

Your setup script code...

WARNING: the disc has not yet been widely tested, check again! I came across the impossibility of debugging quite recently :)

DEBIAN/templates: dialog templates
As already mentioned, in the DEBIAN / config script, you can ask the user questions: enter a string, select one of the options, tick, ... This is done by the bash "library" of the debhelper functions of the debconf package, which can also do a lot of useful things. I don't see them here :)
The DEBIAN/templates file contains the data used in the output dialog boxes(GUI or ncurses). The file contains blocks separated by empty string. Each block defines the resources used in one particular dialog box.
The header for all types of dialogs is standard:
Template: supersh/template-name
Type: string
Default: Default-value
Description: Dialog title
␣Dialog-text

Template - unique (within the same package) template identifier. If a script needs to call a specific dialog, this name is used.
Type - template type. The following types are defined: string, password, boolean, select, multiselect, text, note, error.
Default-value - the default value: the user can simply agree with it.
Description - as in the control file, it consists of two fields: a short description, and long text. The first is the title of the "window", the second is a more detailed description of what is required from the user. It is recommended not to use words like “enter”, but immediately the essence: “Script greeting”, “Mount point”, ...

Type Template description
string Text string prompt
password Password prompt.
There is no Default value for this template type for obvious reasons :)
boolean Checkmark :) Has the string value "true" or "false"
select Possibility to choose one of several options.

Choices: yes, no, maybe
multiselect Ability to select multiple options with checkboxes.
Options are offered in an additional template attribute:
Choices: sex, drugs, rock-n-roll
text Displays text: some not very important information
note Displays text: important information
error Displays text on the screen: very important information, critical.

The text, note, error templates also do not have a Default value, since they only display information :)
Let's play with the following pattern:
Template: supersh/greeting
Type: string
Description: Welcome message
␣The message you wish the script to welcome you with.
Default: Greetings, my master!
Basics of using debconf and debhelper
These are just working sketches. In the original, you can read about templates and working with them here: man 7 debconf-devel :)
To use templates in your DEBIAN/config configuration script, you must first include the debhelper functions:
. /usr/share/debconf/confmodule . Also, this file must be included in the postinst script: otherwise the DEBIAN/config script will not be executed at all!
These functions are available in the debconf package, don't forget to include it as a dependency!
Primitive usage example. DEBIAN/config FILE
#!/bin/bash -e

# Connecting debconf commands

Case "$1" in
configure|reconfigure)
# Request


# Handling the response

greeting="$RET"
echo "$greeting" > /etc/supersh/greeting.txt
;;
*)
echo "config called with unknown argument \`$1"" >&2
exit 1
;;
esac
# Request
db_input medium "supersh/greeting" || true # initialization
db_go || true # display the request on the screen

# Handling the response
db_get "supersh/greeting" # Get value into $RET variable
greeting="$RET"
echo "$greeting" > /etc/supersh/greeting.txt

Here already lies an unpleasant ambush: note that the priority of the medium dialog is passed to the db_input function. For debconf, you can set a minimum priority: dialogs with a priority below which are not displayed, but the default value (Default of the template) is taken! To prevent this EXACTLY from happening, we use the critical priority :) In addition, when installing from the GUI, the threshold for displaying questions is higher, and many of them are not displayed at all.
Possible priorities are: low - default is always used, medium - default is usually quite appropriate, high - default is undesirable, critical - user attention is vital.
|| true is used to prevent the script from dying because of the "-e" option passed to bash.
In this script, it is also recommended to use that pig to catch errors, otherwise the redistributable package may have problems when debugging :)
All the subtleties of using debconf (functions, methods, options, error codes) are described in a rather verbose mana: man debconf-devel .

One last thing: when a package is removed with the purge command, debconf must also purge the package information from its database. For example, it saves the user's choice on db_input queries.
To clean up this data, you need to add the following to the postinst script:
if [ "$1" == "purge" ] && [ -e /usr/share/debconf/confmodule ] ; then
. /usr/share/debconf/confmodule
db_purge
fi

We collect the package! :)

Hooray! All the necessary files have been created, they are in the right folders. Now it's time to pack :)
The first thing to do is to recursively set all files in the package root to user and group root:root (or others if needed). This is because the package files are packaged into a tar.gz archive that preserves both the file permissions and the owner. Therefore, you need to do:
$ sudo chown -R root:root .
However, this is not required. There is an excellent fakeroot command that, when creating an archive, will replace the owner of the file with root.
In our example, the script must have the executable bit.
Then we go back to the folder so that the root folder of the package can be seen, and the package is created with a light kick itself:
$ fakeroot dpkg-deb --build supersh
The created package needs to be renamed to match the *. deb packages: <имя пакета>_<версия>_<архитектура>.deb
$ mv supersh.deb supersh_1.0-1_all.deb
Everything, the package is ready!
Automatic package check
There is a lintian utility that allows you to check the package and identify typical errors in its structure. It is done like this:
$ lintian supersh_1.0-1_all.deb
Package installation
$ sudo dpkg -i supersh_1.0-1_all.deb

Create your own package repository

Now we have our own package. When there are several of them, and even more so with dependencies, it will turn out to be much more convenient to quickly raise your own local micro-repository, and include it in the list of package manager sources :) Here I will describe a quick HowTo "how to create your own repository". The idea will be easy to develop by reading the relevant documentation :)
Let's install the helper first:
$ sudo apt-get install reprepro
Description of the future repository
Repository center - its description. The main thing in it is the list of repository components. We will create the "soft" and "games" components.
Select a folder for the future repository. All actions are performed from its root.
Create a conf/distributions file with the following content:
Description: my local repository
Origin: Ubuntu
Suite: testing
AlsoAcceptFor: unstable experimental
Codename: karmic
Version: 5.0
Architectures: i386 amd64 source
Components: soft games
UDebComponents: soft games

In our business of creating a simple repository, all fields do not play a fundamental role, and are used only to visually determine “what is what” :)

Creating a repository
Repository described! Now let's generate a blank based on the description. The commands are executed in the root of the repository:
$ reprepro export
$reprepro createsymlinks
And add the ready repository to /etc/apt/sources.list:
deb file:///path/to/repo/ karmic soft games
This repository can also be shared using a web server.
Managing packages in a repository
We put *.deb files to be added to the root of the repository, and add them to the soft component of the karmic distribution:
reprepro -C soft includedeb karmic *.deb
now the packages are available from the package manager :)
Removing packages:
reprepro -C soft remove karmic supersh

Finish

The article discusses materials on creating deb packages. The emphasis is on moments for which there is not enough visual description in the network. I hope that my attempt to state simply and clearly did not fail :)
Homework :)) - quite well documented things that are easy to find in man "ahs and articles:
  • Creation of source packages that compile sources: on the example of Zabbix, habrauser mahoro spoke about this perfectly in his article
  • Debconf, debhelper in config scripts: read debconf-devel and debhelper mana. They also allow you to create a package skeleton with the dh_make command.
  • Advanced ways to create documentation in packages: DEBIAN/docs, DEBIAN/manpage.* files
  • Creating init scripts
  • cron job management
  • Signing a repository with a gpg key

I will try to explain the process of creating deb packages as clearly as possible using ruby-zookeper as an example. I warn you right away that the ruby ​​gems packaging method I described is wrong, it's better to use gem2deb for this, but since build ruby-zookeper from source using gem2deb latest version I did not succeed, then here is the easiest assembly method.

If you will be building ruby ​​packages via gem2deb as recommended, it's better to add the line

Export DH_RUBY_IGNORE_TESTS=all/export DH_RUBY_IGNORE_TESTS=all

in debian/rules.

Because Since we will be building ruby ​​code, we will need ruby ​​and a set of tools for building deb packages.

sudo apt-get install ruby ​​dpkg-dev

If you have an old version of ruby, then it does not have a gem command, you will also have to install the rubygems package or update ruby.

Now let's install the gem fpm, which will collect the deb package for us.

sudo gem install fpm fpm -s gem -t deb zookeeper

In the current directory, we have the rubygem-zookeeper_1.4.11_amd64.deb package, it would seem that the matter is already in the bag, but because we need a source package so that we can build a deb from it, for example in OBS, then we will continue.

Create a build directory

cp rubygem-zookeeper_1.4.11_amd64.deb ~/ cd mkdir -p ruby-zookeeper/fakeroot cd ruby-zookeeper/fakeroot

Let's extract the contents of the newly built package into it.

dpkg-deb -R ~/rubygem-zookeeper_1.4.11_amd64.deb ruby-zookeeper_1.4.11-1

Now we will create the files needed to build the package. They must be in the debian directory. We can copy some of the files from the unpacked package.

mkdir debian cp rubygem-zookeeper_1.4.11-1/DEBIAN/control debian/control

Let's edit it to the next state. Don't forget to change Maintainer

Source: ruby-zookeeper Maintainer: Section: ruby ​​Build-Depends: debhelper (>= 7.0.50~) Priority: extra Homepage: https://github.com/slyphon/zookeeper Package: ruby-zookeeper Architecture: amd64 Depends: $(shlibs:Depends), $ (misc:Depends), ruby ​​Description: A low-level multi-Ruby wrapper around the ZooKeeper API bindings. For a friendlier interface, see http://github.com/slyphon/zk. Currently supported: MRI: (1.8.7, 1.9.2, 1.9.3), JRuby: ~> 1.6.7, Rubinius: 2.0.testing, REE 1.8.7. . This library uses version 3.4.5 of zookeeper bindings.

We still need debian/rules. Let's create it. override_dh_shlibdeps is needed in order not to check the linking of zookeeper libraries, because she doesn't get through.

#!/usr/bin/make -f # -*- makefile -*- %: dh $@ override_dh_shlibdeps: true

Tabs in debian/rules are required, you cannot replace them with spaces. Let's make it executable.

Chmod +x debian/rules

Usr/* var/*

Now let's create debian/changelog and write there:

Ruby-zookeeper (1.4.11-1) UNRELEASED; urgent=medium * Initial release -- root Wed, 25 Nov 2015 20:01:55 +0300

We also need debian/compat

Echo 7 > debian/compat

Let's copy the files that will be installed to a local directory and delete the folder with the unpacked package, we won't need it anymore.

Mv ruby-zookeeper_1.4.11-1/(usr,var) . rm -r ruby-zookeeper_1.4.11-1

Let's build a new package, as well as a source package.

dpkg-buildpackage -rfakeroot -uc -F

In the directory above, we will have all the necessary files.

Ll .. total 5528 drwxr-xr-x 3 root root 4096 Dec 20 13:32 ./ drwx------ 12 root root 4096 Dec 20 13:31 ../ drwxr-xr-x 5 root root 4096 Dec 20 13:28 fakeroot/ -rw-r--r-- 1 root root 1261 Dec 20 13:32 ruby-zookeeper_1.4.11-1_amd64.changes -rw-r--r-- 1 root root 2375044 Dec 20 13: 32 ruby-zookeeper_1.4.11-1_amd64.deb -rw-r--r-- 1 root root 565 Dec 20 13:32 ruby-zookeeper_1.4.11-1.dsc -rw-r--r-- 1 root root 3263381 Dec 20 13:32 ruby-zookeeper_1.4.11-1.tar.gz

You can check the contents of the resulting deb package

Create a list of packages:

$ dpkg-scanpackages . /dev/null | gzip -9c > ./Packages.gz
Maybe we will get a message like:

dpkg-scanpackages: warning: Packages in archive but missing from override file: dpkg-scanpackages: warning: fossil linux-headers-3.8.0-avl9-pae linux-image-3.8.0-avl9-pae pdfsam sublimetext virtualbox-4.2 xserver -xorg-input-wacom zotero dpkg-scanpackages: info: Wrote 8 entries to output Packages file.
We now have 8 packages in our repository. Ok, let's add our repository to the file:

line like:

Deb file:///home/username/zips/virensdebianrepository ./
Now you need to update the list of packages so that they become available for installation:

Everything, now you can install, for example, freshly assembled text editor Sublime Text 2 (great instructions there) as always: Now, in order to install SublimeText, just do:
# apt-get install sublimetext

Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: sublimetext 0 upgraded, 1 newly installed, 0 to remove and 245 not upgraded. Need to get 0 B/11.4 MB of archives. After this operation, 17.4 MB of additional disk space will be used. WARNING: The following packages cannot be authenticated! sublimetext Install these packages without verification ? Y Selecting previously deselected package sublimetext. (Reading database ... 247813 files and directories currently installed.) Unpacking sublimetext (from ..././sublimetext_2.0.2_i386.deb) ... Setting up sublimetext (2.0.2) ... Everything, the package will be unpacked and installed, but the fact that it is from the local repository can be seen here: (from ..././sublimetext_2.0.2_i386.deb)

Conclusion

The recipes described in this post are quick dishes, not foie gras with truffles. For large repositories or complex packages, you will still have to familiarize yourself with the documentation and manuals. You can also use the program, which can not only create repositories, but also burn them to CD / DVD discs.

Special thanks to Com. brainstream, which pointed out a bug in a post with rendering of the PRE environment. This happens when you trust Haskell crafts like pandoc :-)

Yes, if you have something to add - write in the comments, but keep in mind that the post is in haste, without the need to re-read the Debian Packaging Guidelines tomes and other quantum physics.

Anonymous comments...

There is an error in your text:
"Now, in order to install Skype, just do:

# apt-get install sublimetext"

Anonymous comments...

You can unpack packages using dpkg-deb:
$ dpkg-deb -x what.deb where/

Anonymous comments...

I have always used dpkg -e and dpkg -x to fully extract a package and quickly fix files or dependencies in control files. I also used checkinstall instead of make install to create a package when compiling something. I think these utilities are worth mentioning.

virens comments...

Building packages from source in Debian is evil! I now recall my experience:

1. The deb-package must contain a maintainer and other nonsense, without which (surprise-surprise!) the package will not be built.

2. Have you assembled, installed and think that's it? No luck, good aptitude can blow a package to hell when installing something else. You know that feeling: how? Where? What? I already installed this package! Well, this is his aptitude - all of himself is Orthodox, which means that he is patriarchal and does not allow freethinking.

3. Therefore, a maneuver is urgently needed: aptitude hold package. "What, is it holding up well? And now be kind - unstick it!" (c) Because from now on aptitude will complain that it can't resolve dependencies without tearing down your package.

4. At this point, my nerves gave out... And I discovered Gentoo, and my hair became soft and silky again!

virens comments...

@iv_vl comments...
And I discovered Gentoo, and my hair...
Brazen PR Genta?! IN my blogger??? There is no way! ;-)

1. The deb package must have a maintainer and other nonsense
Standard policy - you need to know who to punch in the face for a broken package :-) And then, it’s different better than that the bedlam that is going on in RPM fedoras and zyuzes.

2. Have you assembled, installed and think that's it? No luck, good aptitude can blow a package to hell when installing something else.
Only if you put a package old version- for example, I have a hold on IceWM, which I installed from Lenny (the idiot maintainer stuffed ice with a broken tray into Squeeze). Aptitude will warn you before such maneuvers, if anything.

3. Therefore, a maneuver is urgently needed: aptitude hold package.... aptitude will swear that it is not able to resolve dependencies
This is a lie and a provocation: unless you put hold on something like gcc or glibc, it will normally resolve dependencies. Unlike RPMs, who like to give up immediately in the style of "Well, I couldn't, I couldn't" :-)

There can be problems with debugging, that's a fact, but it's better than frying bacon and eggs on the CPU while waiting for fresh KDE gentoy to finish...

4. On this, my nerves passed ...
Somehow you quickly blew up. By the way, what about dependencies in Gent? How do you live there with swearing at every sneeze?
I am ... not trolling for the sake of .... people are interested.

iv_vl

If you notice an error, select a piece of text and press Ctrl + Enter
SHARE: