歡迎您光臨本站 註冊首頁

如何創建Debian二進位包

←手機掃碼閱讀     火星人 @ 2014-03-24 , reply:0

1 簡介
我們採用這樣的方法所創建的文檔的用途只是安裝在我們自己的系統上,而不是將他們提交到Debian的官方版本中。如果我們要進行官方的開發,我們就需要參考Debian New Maintainers' Guide。
通常Debian的軟體包可以得到一個適當的源碼包,在這個源碼包中包含有在創建Debian的二進位包時自動處理所調用步驟的debian/rules文件。在這裡我們只是簡單的顯示一下如何將一個簡單的Shell腳本或是二進位可執行文件打包到一個簡單的二進位包中。
在這裡我們假定我們知道了如何使用tar,man等命令以及知道.tar.gz文件以及Debian是什麼,但是我們卻假定我們並沒有接觸過任何類似於ar或是dpkg的程序。
1.1 Web上的資源
The Debian Reference提供了Debian各種詳細的信息。
創建我們自己的Debian軟體包的官方文檔是Debian New Maintainers' Guide。

2 開始
從Debian的參考2.2.2 2002-11-30中我們可以知道:Debian二進位軟體包的內問格式在deb(5)手冊頁中進行了描述。因為這個內部格式是一個會改變的主題(在Debian的主發行版本之間),所以總是使用dpkg-deb(8)來操作deb文件。
從而dpkg-deb的手冊頁中我們可以知道:dpkg-deb打包,解包以及提供Debian歸案的各種信息。如果必須,deb文件也可以單獨用ar或tar來進行操作。使用dpkp安裝或是從我們的系統移除軟體包。
我們可以在'/var/cache/apt/archives/'目錄下發現許多deb文件。使用'dpkg-deb -I somepackage.deb'得到這個軟體包在通常情況下所提供內容的一個概覽。'dpkg-deb -c somepackage.deb'會列出將要安裝的所有文件。
我們可以使用'ar tv somepackage.deb'來列出deb文件中內容。使用』x』選項可解壓這些文件。
3 軟體包結構
下面讓我們更近一些的來檢測一些軟體包。例如,文件'parted_1.4.24-4_i386.deb'包含下面的三個文件:

$ 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

現在我們解壓出所有的文件,包括tar文件中的內容。

3.1 debian-binary
這個文件的內容是"2.0\n"。這顯示了deb文件格式的版本。對於2.0,所有其他的行都被忽略了。

3.2 data.tar.gz
data.tar.gz文件包含了所有將要被安裝到目標路徑中的文件:

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

他必須是deb歸案中的最後一個文件。

3.3 control.tar.gz
在我們的這個例子中,這個文件包含下面的內容:

-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'包含data.tar.gz中每一個文件的MD5校驗碼。在我們的這個例子中他的內容如下:

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

不要擔心,md5sums文件以及postinst與prerm文件對於我們的第一個包來說並不是託管的。但是我們要注意到他們的存在,每一個官方的Debian軟體包都會有他們存在的合適理由。
prerm與postinst小心的移除舊的文檔文件,並且添加一個由doc指向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

而最後是最有趣的文件:

$ 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
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.

關於control文件的更為深入的信息我們可以通過命令'man 5 deb-control'來得到。

4 修改
現在是我們實驗的時候了。在這裡我們有一個簡單的名為'linuxstatus』的Shell腳本,我們希望將他安裝到'/usr/bin/linuxstatus'。所以首先我們要創建一個包含linuxstatus文件的名為debbian的目錄:

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

4.1 control
我們首先從control文件開始。版本號與另外的Debian包版本號之間必須有一個短橫線,如'1.1-1'。如果我們的程序只包含可移植的Shell腳本,我們可以使用'all'作為他的'Architecture'。
對於'Depends',我們需要查出我們新的軟體包依賴於哪一個特定的文件或是程序。我們可以使用'dpkg -S '來完成。如:

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

然後如果我們要得到關於coreutils軟體包更多的信息,我們可以使用命令'apt-cache showpkg coreutils'來進行查詢,這個命令會告訴我們在我們當前的系統上所安裝的版本號以及其他的一些信息。

另外還有其他的辦法來得到同樣的信息。有一個我們可以用來搜索Debian文件的網頁:http://www.debian.org/distrib/packages。我們可以到這個頁面的底部並填寫相應的表單就可以查找我們要找的文件了。

最後還有一個名為'kpackage'的漂亮的GUI程序,這個程序提供了一個方便的包瀏覽選項,並且允許我們通過提供單個的文件名來查找相應的軟體包。

『Suggests', 'Conflicts', 與 'Replaces'等內容,如果不是必須的,我們就可以忽略掉。

所以我們的第一個'control'的結果如下:

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
Description: Linux system information
This script provides a broad overview of different
system aspects.

將control文件拷貝到另一個debian目錄下的名為DEBIAN的目錄。

$ mkdir -p debian/DEBIAN
$ find ./debian -type d | xargs chmod 755
$ cp control debian/DEBIAN

4.2 dpkg-deb

現在已經基本上完成了。我們只需要輸入:

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

呵呵,這要比我們想像的容易得多。現在我們就可以將這個軟體包安裝到我們的系統了,而我們的工作也就完成了。

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

我們可以輸入'linuxstatus'或是'ls -l /usr/bin/linuxstatus'來查看一下他是否可以正常工作。如果我們不再喜歡這個軟體包,我們只需要輸入'dpkg -r linuxstatus',然後檢查一個這個軟體包是否已經被卸載。如果我們要安裝一個新版本,我們並不需要先移除舊的版本。

如果我們對於Debian軟體包的版本號約定以及命名原則感興趣,我們可以查看Debian引用中的相關部分。

5 雙檢測(Double Check)

現在我們得到了最初的印象,並且已經創建了我們自己的二進位包,現在我們需要更為嚴肅的來看一下我們所創建的軟體包的質量。

5.1 lintian

Debian工程提供了一個lint工具來檢查Debian軟體包。這個工具名為lintian。如果在我們當前的系統上並沒有安裝這個工具,這是一個很好的時刻(apt-get install lintian).

現在我們在我們的新的軟體包文件上使用這個工作:

$ 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

?蓿?雌鵠床⒉皇峭昝賴摹N頤嵌?Я?an手冊,copyright文件以及prerm與postinst腳本。

5.2 最小的文檔

這裡並不是討論如何創建man手冊的地方,而會有其他更多的相關的書籍來討論這個話題。所以在這裡我們作了一個小小的時間變形(time warp),假定我們已經在./man/man1/linuxstatus.1為我們的腳本創建一個完美的手冊頁。

同樣的想法用於copyright文件。我們可以通過命令find /usr/share/doc -name "copyright"在/usr/share/doc目錄發現足夠多的例子。

所以下面的是我們的一個copyright文件的例子:

linuxstatus

Copyright: Chr. Clemens Lee

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)

對於prerm和postinst腳本,我們可以從上面的'parted'軟體包中用同樣的名字拷貝到我們的工程目錄下。這些文件也可以很好的為我們工作。

現在我們可以再一次創建我們的軟體包。在control文件中我們第一次將我們的版本號由1.1-1升到1.2-1(因為我們編寫了一個新的手冊頁,所以我們增加了我們的內部發行號)。我們也需要拷貝這些新文件到合適的位置:

$ 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是必須的,因為lintian希望手冊頁儘可能小的進行壓縮。

5.3 fakeroot

現在我們的軟體包就成了一個比較而言好一些的軟體包了:

$ 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

出現了新的問題。當然我們並不會放棄。事實大問分的錯誤看起來都是一個問題。我們的文件是為用戶和'clemens'組而打包的,然而我們假設大多數的用戶希望將他們安裝為'root/root'。這個問題可以很容易的使用fakeroot工具來進行解決。讓我們來修正這個問題:

$ 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

不錯,但是我們還需要添加另一個文件到軟體包中。

5.4 更多的文檔

在'doc/linuxstatus'目錄下了除了'changelog'文件還需要一個'changelog.Debian'文件,這些都需要使用gizp進行壓縮。

下面的是兩個例子文件,'changelog':

linuxstatus (1.2-1)

* Made Debian package lintian clean.

-- Chr. Clemens Lee 2002-12-13

'changelog.Debian':

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

現在我們最後一步如下:

$ 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

現在沒有問題了。現在我們就可以使用root用戶來安裝這個新的軟體包了。

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) ...
6 小結

下面我們來小結一下我們創建一個Debian軟體包所需的文件以及步驟:

所需的文件:

1 一個或是多個可執行的文件或是Shell腳本。
2 對於每一個可執行文件的手冊頁。
3 一個'control'文件。
4 一個'copyright'文件。
5 'changelog'與'changelog.Debian'文件。

設置臨時的debian目錄:

1 創建'debian/usr/bin'目錄。
2 創建'debian/usr/share/man/man1'目錄。
3 創建'debian/DEBIAN'目錄。
4 創建'debian/usr/share/doc/』。
5 確保debian目錄的所有子目錄的許可權為0755。
拷貝文件到臨時debian樹:

1 拷貝可執行文件到'debian/usr/bin'目錄。
2 拷貝手冊頁文件到'debian/usr/share/man/man1'目錄。
3 拷貝'control'到'debian/DEBIAN'目錄。
4 拷貝'copyright', 'changelog',與'changelog.Debian'文件到'debian/usr/share/doc/』下。
5 在臨時debian樹下用'--best'選項壓縮手冊頁,'copyright', 'changelog',與'changelog.Debian'。

創建與檢測二進位Debian軟體包:

1 在'debian'目錄上使用'fakeroot'調用'dpkg-deb --build'。
2 將生成的'debian.deb'重命名為最終包含版本號與結構信息的軟體包名。
3 使用'lintian』檢測生成的deb軟體包。

[火星人 ] 如何創建Debian二進位包已經有601次圍觀

http://coctec.com/docs/linux/show-post-133554.html