📜 ⬆️ ⬇️

deb-package on the knee

Task: create a package for Debian for pouring daemon / site to server.
I have never worked with deb-packages before - so the solution may not be optimal. But it works and is quite simple to use.

Training

First of all, for periodic dressings on the server, we will need versioning code. If svn is used, then most likely, you can use the revision number. Since I use git, I wrote a simple script for maintaining the project version: tag.sh
To increase the project version, call ./tag.sh build, ./tag minor or ./tag major. The script creates labels of the form v <MAJOR>. <MINOR>. <BUILD> (for example, v0.1.25)
To get the version, call git describe --match = v * HEAD and get the version as v0.2.1 (or v0.2.1-59-g919ab19 if after the tag there were commits).

There are many package creation manuals in the network that use dh_make or describe all possible options for creating a package from scratch. But we do not need the right package for the debian repository, but just the package of our project, which we install on the server.

Of all the package configuration files, only 2 seemed important:
control - package description
conffiles - description of the configuration files of the package (when installing a new version, apt will ask whether to replace the file or keep the old version).
')
control

The file format is quite simple:
Package: _
Version: - git describe
Architecture: - amd64 all -
Depends: -
Maintainer: _
Description:

For example:
Package: ggseductionserver
Version: v0.2.1-59-g919ab19
Architecture: amd64
Depends: libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.1.1), libboost-system1.38.0 (>=1.38.0),
libboost-thread1.38.0 (>=1.38.0), libboost-regex1.38.0 (>=1.38.0), libboost-serialization1.38.0 (>=1.38.0), libboost-program-options1.38.0 (>=1.38.0),
tokyotyrant, tokyocabinet, mysql-client (>=5.0), libssl0.9.8 (>=0.9.8), libreadline5 (>= 5.2), libmysql++3 (>= 3.0),
libpcre3 (>= 7.6), libpcrecpp0 (>= 7.6), libgd2-xpm (>= 2.0)
Maintainer: Alexander Fedora <alexander.fedora at gmail.com>
Description: glagol games server
<>This is server

Dependencies can be obtained using ldd and apt-file
$ ldd ./build/server | grep libboost_thread
/usr/lib/libboost_thread-mt.so.1.38.0
$ apt-file search /usr/lib/libboost_thread-mt.so.1.38.0
libboost-thread1.38.0: /usr/lib/libboost_thread-mt.so.1.38.0
libboost1.38-dbg: /usr/lib/debug/usr/lib/libboost_thread-mt.so.1.38.0

conffiles

This file contains a list of package configuration files. Example:
/etc/seduction/seductiond.conf
/etc/seduction/seductiond.log.properties


Build Package

I decided to use a simple shell script to create a package. Steps in order:
  1. Create a deb directory
  2. Create a deb / DEBIAN directory
  3. Get the current version of the project version = `git describe --match = v * HEAD`
  4. Write the package description to the deb / DEBIAN / control, and use $ version as the version.
  5. Write the list of configuration files to the file deb / DEBIAN / conffiles
  6. In the deb / directory, we write the proset files as if deb / is the root of the disk (for example, deb / usr / local / bin / exe_name, deb / etc / config_name, etc.)
  7. Create a package with the command dpkg -b deb / nameplate_ $ version'.deb '

After the package name, you must put an underscore (_) before the version.
An example of a working script can be found here (this is an example for a C ++ daemon, for a php site here )

Creating a repository on the server

Install the dpkg-dev package.
Create a directory / var / opt / repo /, and in it 2 subdirectories binary and source.
Fill the packages in binary and execute the command to create the archive directory:

dpkg-scanpackages -m binary /dev/null | gzip -9c > binary/Packages.gz

Write the shell script to automate the server update:

rsync -av -e ssh $HOME/projects/repo/*.deb server_name:/var/opt/repo/ || exit 1
ssh server_name 'cd /var/opt/repo; dpkg-scanpackages -m binary /dev/null | gzip -9c > binary/Packages.gz' || exit 1


Raising nginx to access the repository

Install nginx, add a new site:
$ cat /etc/nginx/sites-available/repo
server {
listen 9977;
server_name localhost;
access_log /var/log/nginx/repo.access.log;
location / {
autoindex on;
allow 127.0.0.1;
allow 192.168.0.2;
root /var/opt/repo;
}
}


Raise the site and make sure that it works.
$ ln -s /etc/nginx/sites-available/repo /etc/nginx/sites-enabled/repo
$ sudo /etc/init.d/nginx restart
$ wget 192.168.0.1:9977/binary/Packages.gz


Installing packages from the created repository

We add to /etc/apt/sources.list our site:
deb 192.168.0.1:9977/ binary/
And install the package:
$ sudo apt-get update
$ sudo apt-get install package_name


Conclusion

When installing the package, apt-get will shout that the package cannot be authenticated. In principle, you can add a digital signature to the package, but we already know that it is installed from our repository - so you can add the -y --force-yes keys and install the package automatically.

Ps. Do not kick much - this is my first post.

Source: https://habr.com/ru/post/72633/


All Articles