Summary of the method for creating a deb package using the dpkg command

Source: Internet
Author: User

Summary of the method for creating a deb package using the dpkg command

How to make the Deb package and the corresponding software warehouse is actually very simple. We recommend that you use dpkg to create, edit, and create a deb package.

First, understand the file structure of the Deb package:

Structure in the Deb software package: It has Debian and specific software installation directories (such as etc, USR, opt, TMP, etc ). The Debian directory contains at least control files, followed by postinst (postinstallation), postrm (postremove), preinst (preinstallation), prerm (preremove), and copyright (copyright), changlog (Revision record) and conffiles.

Control: This file mainly describes the package name, version, description, and so on. It is a descriptive file required for the Deb package, facilitate Software Installation Management and indexing. To fully manage the software package, you may also have the following fields:

Section: this field declares the Software category. Common types include 'utils', 'net', 'mail', 'text', and 'x11;

Priority: this field declares the importance of the software to the system, such as 'requestred', 'standard', 'optional', and 'extra;

Essential: this field declares whether it is the most basic software package of the system (option: yes/no). If yes, it indicates that the software is a software package that maintains system stability and normal operation, dismounting in any form is not allowed (unless it is mandatory)

Architecture: declare the structure of the software package, for example, based on 'i386', 'amd64', 'm68k', 'shanghai', 'alpha', and 'powerpc;

Source: the source code name of the software package;

Depends: other software packages and library files that the software depends on. If multiple software packages and library files are dependent on each other, 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 required pre-run script requirements;

Recommends: this field indicates the recommended installation of other software packages and library files;

Suggests: other software packages and library files recommended for installation.


For control, here is a complete example:

Package: bioinfoserv-ARB
Version: 2007_14_08
Section: bioinfoserv
Priority: Optional
Depends: bioinfoserv-base-directories (> = 1.0-1), xviewg (> = 3.2p1.4), xfig (> =), libstdc ++ 2.10-glibc2.2
Suggests: fig2ps
Architecture: i386
Installed-size: 26104
Maintainer: Mingwei Liu <>
Provides: bioinfoserv-ARB
Description: The ARB software is a graphically oriented package comprising various tools for sequence database handling and data analysis.
If you want to print your graphs you probably need to install the suggested fig2ps package. preinst: this file is the work to be done before the software is installed, and the execution will follow the script in it;
The postinst file contains the configuration that the software needs to perform after copying normal directory files to the system.
Prerm: script to be executed before the software is detached
Postrm: the script to be executed after the software is uninstalled. Now let's take a look at how to revise an existing Deb package software.

========================================================== ======================================
Debian creates a deb package (with the root permission.
# Create a software folder to be packaged, as shown in figure
Mkdir cydia
CD cydia

# Create a folder Based on the installation path of the program and add the corresponding program to the folder. For example
Mkdir applications
Mkdir var/mobile/Documents (this directory is required for the game class and may be required for others)
Mkdir *** (to be added according to program requirements)

# Create a Debian folder
Mkdir Debian

# Create a control file under the Debian directory and add relevant content.
Touch Debian/control (you can also use VI Debian/control to edit and save it)
# Edit Control
VI Debian/Control

# Related content (Note that there must be a blank line at the end ):
Package: Soft (program name)
Version: 1.0.1 (Version)
Section: utils (program type)
Architecture: iPhone OS-arm (Program format)
Installed-size: 512 (size)
Maintainer: Your <your_email@gmail.com> (package and contact info)
Description: soft package (program description)
(A blank line is required to end)
Note: This file can also be edited on the computer (you can use the upload editor to complete the file and then go to the. txt file) and uploaded to the package directory.

# You can also set script files in Debian as needed
Preinst
The script will be run before the Deb package file unpacks. Many "preinst" scripts stop the services acting on the software package to be upgraded until the software package is installed or upgraded.

Postinst
The main task of this script is to complete the configuration of the installation package. Many postinst scripts are responsible for executing commands to restart services for newly installed or upgraded software.

Prerm
This script stops the daemon service associated with the software package. It is executed before the associated file of the software package is deleted.

Postrm
This script modifies the software package links or file associations, or deletes the files created by it.

# Postinst example:
#! /Bin/sh
If ["$1" = "Configure"]; then
/Applications/cancelog. APP/cancelog-install
/Bin/launchctl load-WF/system/library/launchdaemons/COM. ixtension. cancelogdaemon. plist
Fi

# Prerm example:
#! /Bin/sh
If [[$1 = remove]; then
/Applications/cancelog. APP/cancelog-uninstall
/Bin/launchctl unload-WF/system/library/launchdaemons/COM. ixtension. cancelogdaemon. plist
Fi

# If the Debian directory contains execution files such as postinst and prerm
Chmod-r 755 Debian

# Exit the package software folder and generate Deb
Dpkg-Deb -- Build cydia
========================================================== ==================================
Sometimes the following error is reported when installing your own Deb package:
Selecting previusly deselected package initrd-Deb.
(Reading database... 71153 files and directories currently installed .)
Unpacking initrd-DEB (from initrd-vstools_1.0_amd64.deb )...
Dpkg: Error Processing initrd-vstools_1.0_amd64.deb (-- install ):
Trying to overwrite '/boot/initrd-vstools.img', which is also in package initrd-deb-2
Dpkg-DEB: subprocess paste killed by signal (broken pipe)
Errors were encountered while processing:
Initrd-vstools_1.0_amd64.deb
The main meaning is that there is already a deb that has installed the same file, so by default, the installation is quit, as long as the original installation file is uninstalled, you can install it again.

The following is the practice:

All directories and files:

Mydeb

| ---- Debian

| ------- Control
| ------- Postinst

| ------- Postrm

| ---- Boot

| ----- Initrd-vstools.img

Create directories and files as shown above in any directory
# Mkdir-P/root/mydeb # store the files and directories that generate the Deb package in this directory
# Mkdir-P/root/mydeb/Debian # The directory name must be capitalized.
# Mkdir-P/root/mydeb/boot # Install the file in the/boot directory
# Touch/root/mydeb/Debian/control # This file must be available
# Touch/root/mydeb/Debian/postinst # Run the shell script after the software is installed.
# Touch/root/mydeb/Debian/postrm # Run the shell script after the software is uninstalled.
# Touch/root/mydeb/boot/initrd-vstools.img # the so-called "software" program, here is just an empty file

Control File Content:
Package: My-DEB (software name, no space in the middle)
Version: 1 (Software Version)
Section: utils (software type)
Priority: Optional (importance of software to the System)
Architecture: amd64 (Platform Architecture Supported by the software)
Maintainer: xxxxxx <> (package and contact information)
Description: My first Deb (description of the software)

Postinst file content (after the software is installed, execute the shell script, which is generally used to configure the software execution environment, which must start with "#! /Bin/sh "is the first line, and then the script is given the executable permission: chmod + x postinst ):
#! /Bin/sh
Echo "My Deb">/root/mydeb. Log

Postrm file content (after the software is uninstalled, execute the shell script. Generally, it is used as the final cleaning. It must start with "#! /Bin/sh "is the first line, and then the script is given executable permissions: chmod + x postrm ):
#! /Bin/sh
Rm-RF/root/mydeb. Log

Package the mydeb directory:
# Dpkg-B mydeb mydeb-1.deb # The first parameter is the name of the directory to be packaged,
# The second parameter is the name of the generated package.

Install the Deb package:
# Dpkg-I mydeb-1.deb # Run postinst,
# The postinst script generates a mydeb. log file containing the "My Deb" character in the/root directory.

Uninstall the Deb package:
# Dpkg-r my-Deb # The package name to be detached here is my-Deb defined in the package field of the control file.
# After removing the initrd-vstools.img under the/boot directory, execute posrm,
# The postrm script deletes the mydeb. log file under the/root directory.

Check whether the Deb package is installed:
# Dpkg-s my-Deb # The package name to be detached here is my-Deb defined in the package field of the control file.

View the Deb package file content:
# Dpkg-C mydeb-1.deb

View the information of a deb package in the current directory:
# Dpkg -- info mydeb-1.deb

Decompress the files to be installed in the Deb package
# Dpkg-x mydeb-1.deb mydeb-1 # The first parameter is the Deb package to be decompressed, here is the mydeb-1.deb
# The second parameter is to extract the Deb package to the specified directory, which is the mydeb-1

Decompress the files in the Debian directory of the Deb package (including at least the control file)
# Dpkg-e mydeb-1.deb mydeb-1/Debian # The first parameter is the Deb package to be decompressed,
# Mydeb-1.deb here
# The second parameter is to decompress the Deb package to the specified directory,
# Here is the mydeb-1/Debian

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.