How to merge multiple deb packages into one deb package


Preface

The developer mode is not enabled by default in the UOS system. If you need to install multiple deb packages, you can only manually click on the deb packages one by one and enter the password to install them. If there are many dependent packages, this method is very troublesome; We need to provide a way to merge multiple debs into one deb package for users to use.

The following will explain step by step how to extract and repackage deb through the dpkg-deb management tool.


A deb basic knowledge

".deb" is the file extension of the Debian software package format. The deb package is a standard archive of Unixar. The package file information and package content are packaged through gzip and tar. A deb package usually consists of two parts, the control script and Program data :
Insert image description here

1.1 Directory structure

The following takes the directory structure of the tigervnc-viewer program as an example, as shown in the figure below:

Insert image description here
tigervnc-viewer is the root directory of the current project and is regarded as the root directory of the Linux system. During deb installation, required programs, libraries and various script files will be installed into the actual Linux system according to the current directory structure; DEBIAN is the control script Directory, the usr directory is the program data directory.

1.2 Package structure description

The DEBIAN directory mainly stores control scripts. There are at least control files in this directory, and there may also be postinst (postinstallation), postrm (postremove), preinst (preinstallation), prerm (preremove), copyright (copyright), changelog (revision record) and confiles etc.

The five most commonly used script files:
• control, used to record software identification, version number, platform, dependency information and other data;
• preinst, a script run before installing the data package and requires execution permission
• postinst, used to install the data package Scripts that are run later require execution permissions;
• prerm, scripts that are run before files are deleted during uninstallation, require execution permissions;
• postrm, scripts that are run after files are deleted, require execution permissions.

control file: describes the name (Package), version (Version), description (Description), etc. of the software package. It is a descriptive file that the deb package must have to facilitate the installation, management and indexing of the software .

In order to fully manage the software package, it may also have the following fields:
  Section: Declares the category of the software, common ones include utils, net, mail, text, x11, etc.;
  Priority: Declares the importance of the software to the system, such as required, standard, optional, extraetc.;
  Essential: Declares whether it is the most basic software package of the system (the options are yes/no). If so, this indicates that the software is a software package that maintains the stability and normal operation of the system and does not allow any form of uninstallation (unless Perform mandatory uninstallation)
  Architecture: software package structure, such as i386amd64 ,m68k , sparc , alpha , powerpc', etc.;
  Source: the source code name of the software package;
  Depends: other software packages and library files that the software depends on. If you depend on multiple software packages and library files, separate them with commas;
  Pre-Depends: Dependent software packages and library files must be installed and configured before software installation. It is often used for necessary pre-run script requirements;
  Recommends: This field indicates other software packages and library files recommended for installation;
  Suggests: Other software packages and library files recommended for installation.

2. Merge multiple deb packages into one deb package

The following uses tigervnc-viewer as an example to illustrate how to merge multiple deb packages into one deb package, system UOS 1050 Education Edition.

2.1 Download offline deb package

First clear the deb package in the /var/cache/apt/archives directory and then install tigervnc-viewer.

sudo apt-get clean                   #清空/var/cache/apt/archives目录下deb包
sudo apt-get install tigervnc-viewer #安装tigervnc-viewer安装包和依赖包

If tigervnc-viewer and missing related dependency packages have not been installed in the current system, /var/cache/apt/archivesmultiple deb packages will be downloaded in the directory, as shown below:

Insert image description here
From the above information, we can know that under the current system, the tigervnc-viewer program still lacks two dependent libraries, libfltk1.3 and libfltk-images1.3.

2.2 Unzip the installation package

cp these three installation packages to other directories, and decompress and repackage the installation packages. The directory here is the jx directory.
The decompression command is as follows:

dpkg-deb -R tigervnc-viewer_1.9.0.1-1+dde_amd64.deb  tigervnc
dpkg-deb -R libfltk-images1.3_1.3.4-9_amd64.deb  tk-images
dpkg-deb -R libfltk1.3_1.3.4-9_amd64.deb  tk

After executing the command, three new directories will be generated, namely tigervnc, tk-images, and tk, as shown in the figure below:
Insert image description here
dpkg-deb can extract the control script and program data from the deb package so that it can be used to merge the deb package in the next step. For related content, please refer to this article. Instructions for using common parameters of Linux dpkg and dpkg-deb

2.3 deb package merge

From step 2.1, we know that the current tigervnc-viewer program still lacks two dependent library files, libfltk1.3 and libfltk-images1.3. This time, these two dependent library files need to be merged into tigervnc-viewer; in order to ensure that the merged The installation package can correctly identify the dependencies. We need to modify the Depends field in the control file of tigervnc;

The overall merger and packaging process is as follows:

1. 提取libfltk库文件中的control文件中的Depends字段
2. 提取libfltk-images1.3库文件中的control文件信息中的Depends段
3. 移除tigervnc-viewer control文件中关于libfltk和libfltk-images1.3 Depends信息。
4. 合并这三个目录下的control 文件中的Depends信息,有重复的需要删掉
5. 合并libfltk、libfltk-images1.3、tigervnc-viewer程序数据到vncviewer目录下
6. 执行打包命令dpkg-deb -b vncviewer vncviewer.deb 

The Depends field in the libfltk library file. The
Insert image description here
Depends field in the libfltk-images1.3 library file. The Depends field
Insert image description here
in the tigervnc-viewer program.
Insert image description here
The merged Depends information is as follows:

libc6 (>= 2.15), libfontconfig1 (>= 2.12.6), libgcc1 (>= 1:3.0), libgnutls30 (>= 3.6.6), 
libjpeg62-turbo (>= 1.3.1), libpam0g (>= 0.99.7.1), libstdc++6 (>= 5), libx11-6, libxcursor1 (>> 1.1.2),libxext6, 
libxfixes3, libxft2 (>> 2.1.1), libxinerama1, libxrender1, zlib1g (>= 1:1.1.4),  libpng16-16 (>= 1.6.2-1), 

It has been verified that vncviewer.deb can be executed normally on a pure UOS system, as shown in the figure below:
Insert image description here
When we verify the installation package on the kylin system, the system can correctly give the alarm information as follows:
Insert image description here

3. Possible problems when using merged deb packages

If the vncviewer.deb installation package has been installed on our UOS system, when installing libfltk-images1.3 and libfltk libraries separately,

sudo apt-get install libfltk1.3

The installation package manager will give an error message, indicating that the file already exists.
Insert image description here
To solve this problem, you can only use the force installation command:

dpkg -i  --force-overwrite xx.deb

4. Summary

The above is how to use the dpkg-deb command to merge multiple deb packages into one deb package. You can use it according to your own needs. The overall process is relatively simple. Pay more attention to the accuracy of the Depends field in the control file.

Reference articles:
https://www.cnblogs.com/Genesis-007/p/5219960.html
https://blog.csdn.net/GW569453350game/article/details/49301427

Guess you like

Origin blog.csdn.net/xiao3404/article/details/131880902