5. 再次检查

既然您已经有了初步印象并构建了自己的二进制软件包,现在是时候更认真地对待并检查我们生成的软件包的质量了。

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

呃,看起来不太完美。我们缺少 man page、版权文件,以及 'prerm' 和 'postinst' 脚本。

5.2. 最简文档

这里不是详细介绍编写和创建 man page 的地方,有很多书籍都有一个或多个章节与此主题相关,并且还有在线的 The Linux MAN-PAGE-HOWTO。所以让我们稍微快进一下,假设您现在在以下位置为您的脚本准备了一个完美的 man page./man/man1/linuxstatus.1.

对于 'copyright' 文件也是如此。您可以在以下位置找到足够的示例/usr/share/doc目录,使用此命令find /usr/share/doc -name "copyright"

这是我们自己的 'copyright' 文件示例

linuxstatus

Copyright: Chr. Clemens Lee <clemens@kclee.de>

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' 软件包中完全复制 示例 到我们自己项目目录中同名的文件中。这些文件应该对我们同样有效。

现在我们再次创建 debian 软件包。在 'control' 文件中,我们首先将版本号从 1.1-1 增加到 1.2-1(因为我们编写了一个新的 man page,所以我们增加了内部版本号)。我们还需要将新文件复制到它们适当的位置

$ 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 期望 man page 文件尽可能小地压缩。

5.3. fakeroot

现在让我们看看我们的软件包是否已成为更好的 Debian 公民

$ 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' 工具轻松修复。所以让我们快速修复并检查一下(暂时忽略 changelog 问题)

$ 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' 文件。两者也都应该使用 gzip 压缩。

这里有两个示例文件,'changelog'

linuxstatus (1.2-1)

  * Made Debian package lintian clean.

 -- Chr. Clemens Lee <clemens@kclee.de>  2002-12-13

和 'changelog.Debian'

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

Debian Policy 文件包含关于 changelog 文件格式 的更多详细信息。

现在希望我们的最后一步将是

$ 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 用户,您现在可以使用标准 'dpkg -i' 命令再次将此软件包安装在旧软件包之上。

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