deb package detailed explanation

1. Detailed explanation of deb package

1. File structure of deb package

The structure inside the deb software package: It has DEBIAN and the specific installation directory of the software (such as etc, usr, opt, tmp, etc.).

composition detailed
data pack Contains the actual installed program data, the file name is "data.tar.XXX"
Installation information and control package Contains deb installation instructions, logos, scripts, etc., the file name is "control.tar.gz"
binary data Contains file header and other information, which requires special software to view
|----DEBIAN
       |-------control
       |-------postinst(postinstallation)
       |-------postrm(postremove)
       |-------preinst(preinstallation)
       |-------prerm(preremove)
       |-------copyright(版权)
       |-------changlog(修订记录)
       |-------conffiles
|----etc
|----usr
|----opt
|----tmp
|----boot
       |-----initrd-vstools.img
2. control file

control: This file mainly describes the name of the software package (Package), version (Version), Installed-Size (size), Maintainer (packager and contact information) and description (Description), etc. It is a descriptive file that the deb package must have. , to facilitate software installation management and indexing.

control file

Field Purpose Example/Other

Package program name cannot have spaces in the middle

Version software version  

Description Program Description  

Section software category utils, net, mail, text, x11

Priority The importance of the software to the system required, standard, optional, extra, etc.;

Essential Whether it is the most basic software package of the system yes/no, if yes, uninstallation is not allowed (unless forced uninstallation)

Architecture platform architecture supported by the software i386, amd64, m68k, sparc, alpha, powerpc, etc.

Source The source code name of the software package  

Depends If other software packages and library files that the software depends on depend on multiple software packages and library files, use commas to separate them.

Pre-Depends Software packages and library files that must be installed and configured before software installation are often used for necessary pre-run script requirements

Recommends Other software packages and libraries recommended for installation  

Suggests Additional packages and libraries recommended for installation  

Remark:

  • inst is the abbreviation of install
  • pre is the prefix before XX
  • post is the prefix after XX
  • rm is the abbreviation of remove
3. preinst file

This script will be run before the Deb package file is unpacked (that is, before the software is installed). You can stop the service acting on the software package to be upgraded until the installation or upgrade of the software package is completed .

4. postinst file

Responsible for completing the configuration work when installing the package. Such as newly installed or upgraded software restarting the service. After the software is installed, execute this Shell script, which is generally used to configure the software execution environment. It must start with "#!/bin/sh".

#!/bin/sh
echo "my deb" > /root/mydeb.log
#!/bin/sh
if [ "$1" = "configure" ]; then
/Applications/MobileLog.app/MobileLog -install
/bin/launchctl load -wF /System/Library/LaunchDaemons/com.iXtension.MobileLogDaemon.plist 
fi
5. prerm file

This script is responsible for stopping the daemon service associated with the software package. It is executed before the package associated files are deleted.

#!/bin/sh
if [[ $1 == remove ]]; then
/Applications/MobileLog.app/MobileLog -uninstall
/bin/launchctl unload -wF /System/Library/LaunchDaemons/com.iXtension.MobileLogDaemon.plist 
fi
6. postrm file

Responsible for modifying package links or file associations, or deleting files created by it. After the software is uninstalled, execute this Shell script, which is generally used as a cleanup and finishing work. It must start with "#!/bin/sh".

#!/bin/sh
rm -rf /root/mydeb.log

2. Detailed explanation of dpkg

1. Package dpkg -b

dpkg -b . mydeb-1.deb

The first parameter is the name of the directory to be packaged (. represents the current directory), and the second parameter is the name of the generated package <.deb file name>

2. Install (unpack and configure) dpkg -i|–install <.deb file name>

dpkg -i mydeb-1.deb

//Force installation

dpkg --force-depends -i mydeb-1.deb

Unpack:

dpkg --unpack mydeb-1.deb

This command only unpacks "mydeb-1.deb" and does not perform package configuration.

3. Uninstall dpkg -r|–remove, delete the package but keep the configuration file

dpkg -r my-deb

dpkg -P|–purge my-deb

This command deletes the package and deletes the configuration file.

4. Check whether the deb package is installed/deb package information dpkg -s|–status 

dpkg -s my-deb

5. View the contents of the deb package file

dpkg -c mydeb-1.deb

6. View the information of a deb package in the current directory

dpkg --info mydeb-1.deb

7. Unzip the files to be installed in the deb

dpkg -x  mydeb-1.deb mydeb-1

The first parameter is the deb package to be decompressed, and the second parameter is to decompress the deb package to the specified directory.

8. Unzip the files in the DEBIAN directory in the deb package (including at least the control file)

dpkg -e mydeb-1.deb mydeb-1/DEBIAN

9. List the files associated with the package dpkg -L|–listfiles

dpkg -L my-deb

10. Configure the software package dpkg --configure

dpkg --configure my-deb

3. Making deb process

Prepare an executable binary file. This binary file must be executable. Compatibility must be considered in advance. If the program has a directory, it must be a complete program directory.

1. Create a new software folder 

Our test name is MyDeb-deb

Create a new folder named DEBIAN 

This folder stores control information

Create a new text document in DEBIAN named control, encoded as utf-8, and the content is as follows:

Package: MyDeb
Version: 1.1.0
Architecture: amd64
Section: utils
Priority: optional
Maintainer: MC
Homepage: http://montecarlo.org.cn
Description: Gale debug

Then we create the corresponding binary package and place the path information in the directory of the same level as DEBIAN after the installation is completed, that is, the current directory is regarded as the root ("/") directory. After the installation is completed, the current directory except the DEBIAN directory Other directories will be installed to the system's "/" directory by default.

Below is an example of a program directory.

|——MyDeb-deb
     |————usr
           |————bin
                 |——可执行文件(安装后,就在你的/usr/bin生成相应的可执行文件)
           |————share
                |————icons 
 
                    |——deb.png(图标文件生成到/usr/share/icons/)
                |————applications                           
                    |——deb.desktop(桌面文件生成到/usr/share/applications/)
     |————DEBIAN(大写、用来制作打包文件)
            |————control(描述deb包的信息必须的文件)

Complete experimental example directory structure:

JFeng-deb
├── DEBIAN
│  └── control
├── opt
│  └── JFeng
│      ├── heart
│      └── heart.desktop
└── usr
    ├── bin
    │  └── heart -> /home/ubuntu/桌面/MyDeb-deb/opt/MyDeb/heart
    └── share
        ├── applications
        │  └── heart.desktop
        └── icons
            └── heart_98.png

8 directories, 6 files

3. Packing

sudo dpkg -b JFeng-deb/ JFeng-linux-amd64.deb

Reprinted from: Detailed explanation of deb package_Coding<_>'s blog-CSDN blog

Guess you like

Origin blog.csdn.net/fuhanghang/article/details/133376938
Recommended