1. 程式人生 > >製作deb安裝包(Debian Binary Package)全過程

製作deb安裝包(Debian Binary Package)全過程

1.Getting Started

From the Debian Reference 2.2.2 2002-11-30: "The internals of this Debian binary package format are described in the deb(5) manual page. Because this internal format is subject to change (between major releases of Debian), always use dpkg-deb(8) for manipulating .deb files."

From the dpkg-deb man page: "dpkg-deb packs, unpacks and provides information about Debian archives. .deb files can also be manipulated with ar

 and tar alone if necessary. Use dpkg to install and remove packages from your system."

You might find lots of example .deb files in directory '/var/cache/apt/archives/'. With 'dpkg-deb -I somepackage.deb' you might get a general overview of what this package offers in particular. 'dpkg-deb -c somepackage.deb

' lists all files which will be installed.

List content of the .deb file with 'ar tv somepackage.deb'. Use the 'x' option to extract the files.

2.Package Structure

Let's examine one example package a little bit closer. E.g. file 'parted_1.4.24-4_i386.deb' contains these three files:

$ ar tv parted_1.4.24-4_i386.deb
rw-r--r-- 0/0      4 Mar 28 13:46 2002 debian-binary
rw-r--r-- 0/0   1386 Mar 28 13:46 2002 control.tar.gz
rw-r--r-- 0/0  39772 Mar 28 13:46 2002 data.tar.gz

Now we can start to extract all files including the content of the tar files.

2.1. debian-binary

The content of this file is "2.0\n". This states the version of the deb file format. For 2.0 all other lines get ignored.

2.2. data.tar.gz

The 'data.tar.gz' file contains all the files that will be installed with their destination paths:

drwxr-xr-x root/root         0 2002-03-28 13:44:57 ./
drwxr-xr-x root/root         0 2002-03-28 13:44:49 ./sbin/
-rwxr-xr-x root/root     31656 2002-03-28 13:44:49 ./sbin/parted
drwxr-xr-x root/root         0 2002-03-28 13:44:38 ./usr/
drwxr-xr-x root/root         0 2002-03-28 13:44:41 ./usr/share/
drwxr-xr-x root/root         0 2002-03-28 13:44:38 ./usr/share/man/
drwxr-xr-x root/root         0 2002-03-28 13:44:52 ./usr/share/man/man8/
-rw-r--r-- root/root      1608 2002-03-28 13:44:37 ./usr/share/man/man8/parted.8.gz
drwxr-xr-x root/root         0 2002-03-28 13:44:41 ./usr/share/doc/
drwxr-xr-x root/root         0 2002-03-28 13:44:52 ./usr/share/doc/parted/
-rw-r--r-- root/root      1880 2002-03-07 14:20:08 ./usr/share/doc/parted/README.Debian
-rw-r--r-- root/root      1347 2002-02-27 01:40:50 ./usr/share/doc/parted/copyright
-rw-r--r-- root/root      6444 2002-03-28 13:37:33 ./usr/share/doc/parted/changelog.Debian.gz
-rw-r--r-- root/root     15523 2002-03-28 02:36:43 ./usr/share/doc/parted/changelog.gz

It must be the last file in the deb archive.

2.3. control.tar.gz

In our example this file has the following content:

-rw-r--r--    1 root     root         1336 Mar 28  2002 control
-rw-r--r--    1 root     root          388 Mar 28  2002 md5sums
-rwxr-xr-x    1 root     root          253 Mar 28  2002 postinst
-rwxr-xr-x    1 root     root          194 Mar 28  2002 prerm

'md5sums' contains for each file in data.tar.gz the md5sum. In our example the content looks like this:

1d15dcfb6bb23751f76a2b7b844d3c57  sbin/parted
4eb9cc2e192f1b997cf13ff0b921af74  usr/share/man/man8/parted.8.gz
2f356768104a09092e26a6abb012c95e  usr/share/doc/parted/README.Debian
a6259bd193f8f150c171c88df2158e3e  usr/share/doc/parted/copyright
7f8078127a689d647586420184fc3953  usr/share/doc/parted/changelog.Debian.gz
98f217a3bf8a7407d66fd6ac8c5589b7  usr/share/doc/parted/changelog.gz

Don't worry, the 'md5sum' file as well as the 'postinst' and 'prerm' files are not mandatory for your first package. But please take a note of their existence, every proper official Debian package has them for good reasons.

'prerm' and 'postinst' seem to take care of removing old documentation files and adding a link from doc to share/doc.

$ cat postinst
#!/bin/sh
set -e
# Automatically added by dh_installdocs
if [ "$1" = "configure" ]; then
  if [ -d /usr/doc -a ! -e /usr/doc/parted -a -d /usr/share/doc/parted ]; then
    ln -sf ../share/doc/parted /usr/doc/parted
  fi
fi
# End automatically added section

$ cat prerm
#!/bin/sh
set -e
# Automatically added by dh_installdocs
if [ \( "$1" = "upgrade" -o "$1" = "remove" \) -a -L /usr/doc/parted ]; then
  rm -f /usr/doc/parted
fi
# End automatically added section

And finally the most interesting file:

$ cat control
Package: parted
Version: 1.4.24-4
Section: admin
Priority: optional
Architecture: i386
Depends: e2fsprogs (>= 1.27-2), libc6 (>= 2.2.4-4), libncurses5 (>= \
5.2.20020112a-1), libparted1.4 (>= 1.4.13+14pre1), libreadline4 (>= \
4.2a-4), libuuid1
Suggests: parted-doc
Conflicts: fsresize
Replaces: fsresize
Installed-Size: 76
Maintainer: Timshel Knoll <[email protected]>
Description: The GNU Parted disk partition resizing program
 GNU Parted is a program that allows you to create, destroy,
 resize, move and copy hard disk partitions. This is useful
 for creating space for new operating systems, reorganizing
 disk usage, and copying data to new hard disks.
 .
 This package contains the Parted binary and manual page.
 .
 Parted currently supports DOS, Mac, Sun, BSD, GPT and PC98
 disklabels/partition tables, as well as a 'loop' (raw disk)
 type which allows use on RAID/LVM. Filesystems supported are
 ext2, ext3, FAT (FAT16 and FAT32) and linux-swap. Parted can
 also detect HFS (Mac OS), JFS, NTFS, ReiserFS, UFS and XFS
 filesystems, but cannot create/remove/resize/check these
 filesystems yet.
 .
 The nature of this software means that any bugs could cause
 massive data loss. While there are no known bugs at the moment,
 they could exist, so please back up all important files before
 running it, and do so at your own risk.

Further information about the control file can be obtained via 'man 5 deb-control'.

3. Hands On

Now it is time to get practical ourselves. I have a simple shell script named 'linuxstatus' which I want to install as '/usr/bin/linuxstatus'. So first let's create a directory named 'debian' next to the file 'linuxstatus'.

$ mkdir -p ./debian/usr/bin
$ cp linuxstatus ./debian/usr/bin

3.1. control

Let's start with the control file. The version number must have a dash with an additional Debian package version number, e.g. '1.1-1'. If your program consists e.g. only of portable shell scripts, use 'all' as its 'Architecture'.

For 'Depends' you might need to find out to which package a certain file or program your new package relies onto belongs to. You can use 'dpkg -S <file>' for this to find this out, e.g.:

$ dkpg -S /bin/cat
coreutils: /bin/cat

Then to find out more about package 'coreutils' you can use the command 'apt-cache showpkg coreutils', which will tell you among other things the current version number that is installed on the system.

As a side note, there are two more ways to find the same information. There is a web page where you can search for Debian files: http://www.debian.org/distrib/packages. Go to the bottom of that page to fill out the web form.

Last not least there is a nice GUI application named 'kpackage', which provides convenient package browsing options and also allows to search after packages given individual file names.

'Suggests', 'Conflicts', and 'Replaces' etc. can be left out if not needed.

So here is the result of our first 'control' file:

Package: linuxstatus
Version: 1.1-1
Section: base
Priority: optional
Architecture: all
Depends: bash (>= 2.05a-11), textutils (>= 2.0-12), awk, procps (>= \
1:2.0.7-8), sed (>= 3.02-8), grep (>= 2.4.2-3), coreutils (>= 5.0-5)
Maintainer: Chr. Clemens Lee <[email protected]>
Description: Linux system information
 This script provides a broad overview of different
 system aspects.

The 'control' file gets copied into a directory called 'DEBIAN' inside the other 'debian' directory.

$ mkdir -p debian/DEBIAN
$ find ./debian -type d | xargs chmod 755   # this is necessary on Debian Woody, don't ask me why
$ cp control debian/DEBIAN

If you expect your package to have a bigger audience in the future it might help to read this Writing Debian package descriptionsarticle.

3.2. dpkg-deb

Now it is almost done. Just type:

$ dpkg-deb --build debian
dpkg-deb: building package `linuxstatus' in `debian.deb'.
$ mv debian.deb linuxstatus_1.1-1_all.deb

Uh, that was all easier than expected. Now we just have to install this package on our box and we are done:

root# dpkg -i ./linuxstatus_1.1-1_all.deb

Type 'linuxstatus' or 'ls -l /usr/bin/linuxstatus' to see if it worked. If you don't like your package any more, just type 'dpkg -r linuxstatus' and check again that the package is deinstalled. If you install a newer version you don't have to remove the old one first, thought.

If you are curious about the version numbering scheme and naming conventions for a Debian package, have a read at this sectionin The Debian Reference.


4. Double Check

Now that you have gotten a first impression and build your own binary package, it is time to get a little bit more serious and have a look at the quality of the package that we have produced.

4.1. lintian

Luckily for us the Debian project provides a 'lint' like tool for checking Debian packages. This tool is named 'lintian'. If you have not installed it yet on your system, this is a good moment (apt-get install lintian).

Now we use this little treasure tool on our new package file:

$ lintian linuxstatus_1.1-1_all.deb
E: linuxstatus: binary-without-manpage linuxstatus
E: linuxstatus: no-copyright-file
W: linuxstatus: prerm-does-not-remove-usr-doc-link
W: linuxstatus: postinst-does-not-set-usr-doc-link

Uh, doesn't look so perfect. We miss a man page, copyright file, and also those 'prerm' and 'postinst' scripts.

4.2. Minimal Documentation

This is not the place to say much about writing and creating man pages, there are many books that have one or another chapter related to this topic and there is also The Linux MAN-PAGE-HOWTO online. So lets do a little time warp and assume you have now a perfect man page for your script at location ./man/man1/linuxstatus.1.

The same for a 'copyright' file. You can find enough examples under the /usr/share/doc directory with this command: find /usr/share/doc -name "copyright"

So here is our own example of a 'copyright' file:

linuxstatus

Copyright: Chr. Clemens Lee <[email protected]>

2002-12-07

The home page of linuxstatus is at: 
http://www.kclee.de/clemens/unix/index.html#linuxstatus

The entire code base may be distributed under the terms of the GNU General
Public License (GPL), which appears immediately below.  Alternatively, all
of the source code as any code derived from that code may instead be
distributed under the GNU Lesser General Public License (LGPL), at the
choice of the distributor. The complete text of the LGPL appears at the
bottom of this file.

See /usr/share/common-licenses/(GPL|LGPL)

For the 'prerm' and 'postinst' scripts we copy one to one the examples from the 'parted' package above into files with the same name in our own project directory. These files should work for us just as well.

Now we create the debian package again. In the 'control' file we first increase the version number from 1.1-1 to 1.2-1 (since we have written a new man page we increase our internal release number). We also need to copy the new files to their appropriate places:

$ mkdir -p ./debian/usr/share/man/man1
$ mkdir -p ./debian/usr/share/doc/linuxstatus
$ find ./debian -type d | xargs chmod 755
$ cp ./man/man1/linuxstatus.1 ./debian/usr/share/man/man1
$ cp ./copyright ./debian/usr/share/doc/linuxstatus
$ cp ./prerm ./postinst ./debian/DEBIAN
$ gzip --best ./debian/usr/share/man/man1/linuxstatus.1
$
$ dpkg-deb --build debian
dpkg-deb: building package `linuxstatus' in `debian.deb'.
$ mv debian.deb linuxstatus_1.2-1_all.deb

Gzip is necessary because lintian expects man page files to be compressed as small as possible.

4.3. fakeroot

Now lets see if our package has become a better Debian citizen:

$ lintian linuxstatus_1.2-1_all.deb
E: linuxstatus: control-file-has-bad-owner prerm clemens/clemens != root/root
E: linuxstatus: control-file-has-bad-owner postinst clemens/clemens != root/root
E: linuxstatus: bad-owner-for-doc-file usr/share/doc/linuxstatus/ clemens/clemens != root/root
E: linuxstatus: bad-owner-for-doc-file usr/share/doc/linuxstatus/copyright clemens/clemens != root/root
E: linuxstatus: debian-changelog-file-missing

Ups, new complains. OK, we will not give up. Actually most errors seem to be the same problem. Our files are all packaged for user and group 'clemens', while I assume most people would prefer having them installed as 'root/root'. But this is easily fixed using the tool 'fakeroot'. So lets fix and check this quickly (while ignoring the changelog issue):

$ fakeroot dpkg-deb --build debian
dpkg-deb: building package `linuxstatus' in `debian.deb'.
$ mv debian.deb linuxstatus_1.2-1_all.deb
$ lintian linuxstatus_1.2-1_all.deb
E: linuxstatus: debian-changelog-file-missing

Fine, but we have yet another file to add to the package.

4.4. More Documentation

Let me tell you already that next to a 'changelog' file in the 'doc/linuxstatus' directory a 'changelog.Debian' file is also required. Both should be gzipped as well.

Here are two example files, 'changelog':

linuxstatus (1.2-1)

  * Made Debian package lintian clean.

 -- Chr. Clemens Lee <[email protected]>  2002-12-13

and 'changelog.Debian':

linuxstatus Debian maintainer and upstream author are identical.
Therefore see also normal changelog file for Debian changes.

The Debian Policy file has more details regarding the format of the changelog file.

Now hopefully our last step will be:

$ cp ./changelog ./changelog.Debian ./debian/usr/share/doc/linuxstatus
$ gzip --best ./debian/usr/share/doc/linuxstatus/changelog 
$ gzip --best ./debian/usr/share/doc/linuxstatus/changelog.Debian
$ fakeroot dpkg-deb --build ./debian
dpkg-deb: building package `linuxstatus' in `debian.deb'.
$ mv debian.deb linuxstatus_1.2-1_all.deb
$ lintian linuxstatus_1.2-1_all.deb

Ah, we get no more complains :-). As root you can install now this package over the old one, again with the standard 'dpkg -i' command.

root# dpkg -i ./linuxstatus_1.2-1_all.deb
(Reading database ... 97124 files and directories currently installed.)
Preparing to replace linuxstatus 1.1-1 (using linuxstatus_1.2-1_all.deb) ...
Unpacking replacement linuxstatus ...
Setting up linuxstatus (1.2-1) ...

5. Summary

Not to get confused, let us recapture all steps we have taken to build our binary Debian package.

Prerequisite files:

  1. one or more binary executable or shell script files

  2. a man page for each executable file

  3. a 'control' file

  4. a 'copyright' file

  5. a 'changelog' and 'changelog.Debian' file

Setup temporary 'debian' directories:

  1. create 'debian/usr/bin' directory (or wherever you plan to place your executable files)

  2. create 'debian/usr/share/man/man1' (or whatever section your man page belongs into)

  3. create 'debian/DEBIAN' directory

  4. create 'debian/usr/share/doc/<package_name>'

  5. make sure all sub directories of 'debian' have file permission 0755

Copy files into temporary 'debian' tree:

  1. copy executable file into 'debian/usr/bin' directory (or wherever you plan to place your executable files)

  2. copy man page file into 'debian/usr/share/man/man1' directory

  3. copy 'control' file into 'debian/DEBIAN' directory

  4. copy 'copyright', 'changelog', and 'changelog.Debian' files into 'debian/usr/share/doc/<package_name>'

  5. gzip man page, 'copyright', 'changelog', and 'changelog.Debian' files with option '--best' inside the temporary 'debian' tree

Build and check binary Debian package:

  1. invoke 'dpkg-deb --build' using 'fakeroot' on the 'debian' directory

  2. rename resulting 'debian.deb' file to its final package name including version and architecture information

  3. check resulting .deb package file for Debian policy compliance using 'lintian'



相關推薦

製作deb安裝Debian Binary Package全過程

1.Getting Started From the Debian Reference 2.2.2 2002-11-30: "The internals of this Debian binary package format are described in the de

使用Advanced Installer製作IIS安裝一:配置IIS和Web.config

前言:大過年的,寫篇文章不容易,還是給自己點個贊~~年前找了下.net安裝包的製作方法,發現Visual Studio自帶的製作工具使用起來非常麻煩,需要單獨下載安裝包,並且什麼啟用認證等等屁事相當麻煩,最坑爹的是它的自定義dialog使用起來有很多的侷限性,所以找了很久,終於找到了Advanced Inst

使用Advanced Installer製作IIS安裝二:配置安裝依賴項和自定義dll

前言:上篇使用Advanced Installer製作IIS安裝包(一:配置IIS和Web.config)介紹了下使用Advanced Installer配置IIS和Web.config的過程,操作起來是相對比較簡單的,只要知道了博主提供的方法,相信都不是問題,其實博主當初尋找相關方法配置IIS和Web.co

Android Studio生成簽名安裝Generate Signed APK

打開 對話 store microsoft oid 選擇 安裝 height androi 一 打開構建對話框。 二 創建新的密鑰庫(key store) 可以選擇已創建的密鑰庫,也可以選擇創建新的密鑰庫。 創建完成後,自動導入。

IIS允許下載APK安裝MIME型別配置

.apk檔案就是安卓(Android)的應用程式字尾名,預設情況下,使用IIS作為Web伺服器的無法下載此檔案。如果需要下載此檔案則需要對IIS的MIME型別進行配置。IIS6.0  MIME配置過程:開啟IIS服務管理器,找到伺服器,右鍵-屬性,開啟IIS服務屬性;單擊MI

R 安裝上傳資料失敗時的解決方法

R中控制代碼錯誤: 提示程式碼: Error in curl::curl_fetch_memory(url, handle = handle) : Problem with the SSL CA cert (path? access rights?)| Leaving

Ubuntu 安裝deb格式的安裝收集

pack cin 沒有 版本 pkg 格式 pos ive 搜索 備註:依賴問題沒有解決 Ubuntu軟件包格式為deb,安裝方法如下: sudo dpkg -i package.deb dpkg的詳細使用方法,網上有很多,下面簡單列了幾個: dpkg

詳解Linux下auto工具製作Makefile原始碼工具安裝

收藏於 2012-03-25 遷移自個人的百度空間 ------------------------------- 一、引子 咱們都知道make好用,但是大型的軟體make是很麻煩的,為了解決這個問題,先人們就發明了autoconf與automake工具,用這些工具可以非常方便的製作

NSIS製作安裝

NSIS簡介: NISIS是win32免費的安裝,解除安裝系統。他的特點是指令碼簡潔高效;系統開銷小。當然進行安裝、解除安裝、系統設定、解壓檔案都沒有問題,幾乎可以做所有的事情。更多的功能請閱讀《NSIS幫助文件》 工具: NIS Edit + NSIS 思路: 基本上製作

rpm打包過程詳解——製作原始碼安裝

製作原始碼安裝包(.tar.gz) 1.      解決依賴的軟體: 系統環境:[紅帽企業Linux.6.4.64位伺服器版].rhel-server-6.4-x86_64 原始碼製作中使用到的軟體為GNU M4,GNU autoconf,GNU automake;GNU

ubuntu deb安裝製作方法介紹

方案一,基於dpkg-buildpackage 1.準備工作 1)重新命名目標原始碼目錄,目錄名規則為檔名加大版本號,如下: 2)測試編譯程式碼,清楚殘餘無用檔案 安裝libcurl開發包: apt-get install libcurl4-gnu

自己動手,製作真正的.net Framework 3.5 SP1離線安裝

.NET Framework 3.5 SP1釋出了,興沖沖…下載,當然是完全離線安裝包.net Framework 3.5 Service pack 1(Full Package) 231MB,網路慢呀!終於下載完了,安裝….遇到新情況,還要連線網路下載,不是完全離線安裝包嗎

MinGW-w64非官方編譯器集成安裝很清楚

edits oos api 線程 原則 c/c++ cts net reads 官方鏈接[編輯] MinGW 官方網站。 SourceForge.net上的MinGW官方的下載站點(Win32系統)。 MinGW-w64官方的下載站點[編輯] MinGW-w

使用Qt installer framework制作安裝不知道是否適合Mac和Linux?

star spl config文件 priority class error ctu imu lac 一、介紹 使用Qt庫開發的應用程序,一般有兩種發布方式:(1)靜態編譯發布。這種方式使得程序在編譯的時候會將Qt核心庫全部編譯到一個可執行文件中。其優勢是簡單單一

6.linux安裝deb安裝

purge linux class 檢查 lin blog div 文件 提取 原文地址:http://www.xitongzhijia.net/xtjc/20150206/37464.html 1、下載需要安裝的deb包,輸入以下命令安裝: sudo dpkg -i

ubuntu deb 安裝的命令列安裝

如果ubuntu要安裝新軟體,已有deb安裝包(例如:iptux.deb),但是無法登入到桌面環境。那該怎麼安裝?答案是:使用dpkg命令。 首先要使用 cd 命令到安裝包所在的檔案目錄,然後參考下面的命令進行操作: dpkg命令常用格式如下: sudo dpkg -I iptux.deb #檢

Installshield製作更新安裝

對於InstallScript MSI Project安裝包,只需要做兩步,即可做更新安裝包。 1.修改版本號,注意需要修改第一個數字或者第二個數字。 2.設定Enable Maintenance的值為Yes. 解決問題的時候看到的一個坑,暫時沒碰到。(只覆蓋少數檔案)

如何製作pip安裝 --python

1、新建一個資料夾,檔名可以自定義,用來存放文件。 2、再新建一個資料夾,資料夾名自定義,但此處一般為工程名,我命名為packer。 3、分別新建LICENCE、README.md(markdown檔案)、requirements.txt、setup.py檔案,注意檔案尾綴。

詳解Linux下auto工具製作Makefile原始碼製作

收藏於 2012-03-25 遷移自個人的百度空間 -------------------------------- 一、 概述 為了更好的製作configure與Makefile,我先把製作流程給寫在這裡,好讓大夥都有個心理準備。這裡只說流程,不做解釋。(附圖供參考) 1

黑蘋果安裝MaxOS及教程——如何在非蘋果電腦上安裝MaxOS系統

安裝前說明      相信看到這篇文章的小夥伴們都是和博主一樣有一顆不安分的心靈,想要嘗試各種不可能,或許你是因為喜歡MaxOS系統但無奈自己是windows系統,想要體驗一下MaxOS系統,又或許你是因為想要嘗試突破自己,嘗試一些新鮮技術,本安裝包及教