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 中每个文件的 md5sum 值。在我们的示例中,内容如下所示

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

不用担心,'md5sum' 文件以及 '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 <timshel@debian.org>
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'.