4. 动手实践

现在是时候开始实践了。我有一个简单的 shell 脚本,名为 'linuxstatus',我想将其安装为 '/usr/bin/linuxstatus'。所以首先让我们在文件 'linuxstatus' 旁边创建一个名为 'debian' 的目录。

$ 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。转到该页面的底部填写 Web 表单。

最后但并非最不重要的是,有一个名为 '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 <clemens@kclee.de>
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   # this is necessary on Debian Woody, don't ask me why
$ cp control debian/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 参考手册