The Debian package is not only an archive of files intended for installation. It is part of a larger whole, and it describes its relationship with other Debian packages (dependencies, conflicts, suggestions). It also provides scripts that enable the execution of commands at different stages in the package's lifecycle (installation, removal, upgrades). These data are used by the package management tools but are not part of the packaged software; they are, within the package, what is called its “meta-information” (information about other information).
5.2.1. وصف: الملف control
This file uses a structure similar to email headers (as defined by RFC 2822). For example, for apt, the control
file looks like the following:
$
apt-cache show apt
Package: apt
Version: 1.0.9.6
Installed-Size: 3788
Maintainer: APT Development Team <deity@lists.debian.org>
Architecture: amd64
Replaces: manpages-it (<< 2.80-4~), manpages-pl (<< 20060617-3~), openjdk-6-jdk (<< 6b24-1.11-0ubuntu1~), sun-java5-jdk (>> 0), sun-java6-jdk (>> 0)
Depends: libapt-pkg4.12 (>= 1.0.9.6), libc6 (>= 2.15), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.9), debian-archive-keyring, gnupg
Suggests: aptitude | synaptic | wajig, dpkg-dev (>= 1.17.2), apt-doc, python-apt
Conflicts: python-apt (<< 0.7.93.2~)
Breaks: manpages-it (<< 2.80-4~), manpages-pl (<< 20060617-3~), openjdk-6-jdk (<< 6b24-1.11-0ubuntu1~), sun-java5-jdk (>> 0), sun-java6-jdk (>> 0)
Description-en: commandline package manager
This package provides commandline tools for searching and
managing as well as querying information about packages
as a low-level access to all features of the libapt-pkg library.
.
These include:
* apt-get for retrieval of packages and information about them
from authenticated sources and for installation, upgrade and
removal of packages together with their dependencies
* apt-cache for querying available information about installed
as well as installable packages
* apt-cdrom to use removable media as a source for packages
* apt-config as an interface to the configuration settings
* apt-key as an interface to manage authentication keys
Description-md5: 9fb97a88cb7383934ef963352b53b4a7
Tag: admin::package-management, devel::lang:ruby, hardware::storage,
hardware::storage:cd, implemented-in::c++, implemented-in::perl,
implemented-in::ruby, interface::commandline, network::client,
protocol::ftp, protocol::http, protocol::ipv6, role::program,
role::shared-lib, scope::application, scope::utility, sound::player,
suite::debian, use::downloading, use::organizing, use::searching,
works-with::audio, works-with::software:package, works-with::text
Section: admin
Priority: important
Filename: pool/main/a/apt/apt_1.0.9.6_amd64.deb
Size: 1107560
MD5sum: a325ccb14e69fef2c50da54e035a4df4
SHA1: 635d09fcb600ec12810e3136d51e696bcfa636a6
SHA256: 371a559ce741394b59dbc6460470a9399be5245356a9183bbeea0f89ecaabb03
5.2.1.1. الاعتماديات: حقل Depends
The dependencies are defined in the Depends
field in the package header. This is a list of conditions to be met for the package to work correctly — this information is used by tools such as apt
in order to install the required libraries, in appropriate versions fulfilling the dependencies of the package to be installed. For each dependency, it is possible to restrict the range of versions that meet that condition. In other words, it is possible to express the fact that we need the package libc6 in a version equal to or greater than “2.15” (written “libc6 (>= 2.15)
”). Version comparison operators are as follows:
تخدم الفاصلة كحرف فصل في لائحة الشروط الواجب تحقيقها. يمكن تفسير معناها على أنها ”and“ منطقية. وفي لائحة الشروط أيضًا، يعبِّر الخط الشاقولي (”|“) عن عملية ”or“ المنطقية (عملية ”أو“ تضمنية ”inclusive or“ وليست عملية ”إما كذا أو كذا exclusive or“). ولأن أولويتها أكبر من أولوية ”and“، يمكن استخدامها قدر الحاجة. بالتالي، تُكتَب الاعتمادية ”A or B) and C)“ بالشكل
A | B, C
. وفي المقابل، التعبير ”(A or (B and C“ يجب كتابته بالشكل ”(A or B) and (A or C)“، لأن حقل
Depends
لا يسمح بالأقواس التي تُغيِّر ترتيب الأولويات بين العمليات المنطقية ”or“ و ”and“. سيُكتب إذاً كالتالي
A | B, A | C
.
The dependencies system is a good mechanism for guaranteeing the operation of a program, but it has another use with “meta-packages”. These are empty packages that only describe dependencies. They facilitate the installation of a consistent group of programs preselected by the meta-package maintainer; as such, apt install meta-package
will automatically install all of these programs using the meta-package's dependencies. The gnome, kde-full and linux-image-amd64 packages are examples of meta-packages.
5.2.1.2. تضارب: حقل Conflicts
يبين الحقل Conflicts
أن الحزمة لا يمكن تثبيتها على النظام عند وجود حزمة أخرى. أكثر الأسباب شيوعاً لهذا التضارب هي أن الحزمتين تحويان ملفاً له الاسم نفسه، أو تقدمان الخدمة ذاتها على نفس منفذ TCP، أو أنهما تتعارضان في عملهما.
dpkg
will refuse to install a package if it triggers a conflict with an already installed package, except if the new package specifies that it will “replace” the installed package, in which case dpkg
will choose to replace the old package with the new one. apt
always follows your instructions: if you choose to install a new package, it will automatically offer to uninstall the package that poses a problem.
5.2.1.3. عدم التوافق: حقل Breaks
تأثير الحقل Breaks
يشبه تأثير الحقل Conflicts
، لكن له معنى خاص. يشير هذا الحقل إلى أن تثبيت الحزمة سوف ”يعطب“ حزمة أخرى (أو نسخة محددة منها). عموماً، هذا النوع من عدم التوافق بين الحزم انتقالي، وغالباً ما تحدد علاقة Breaks
الإصدارات غير المتوافقة فيما بينها.
dpkg
will refuse to install a package that breaks an already installed package, and apt
will try to resolve the problem by updating the package that would be broken to a newer version (which is assumed to be fixed and, thus, compatible again).
يحدث هذا النوع من الحالات في حال صدور تحديثات بدون توافق عكسي: هذا ما يحدث عندما لا تتوافق النسخة الجديدة مع النسخة القديمة، وتسبب أعطالاً في برامج أخرى ما لم تتخذ الاحتياطات المناسبة. يستخدم الحقل Breaks
لمنع المستخدم من الخوض في هذه المشاكل.
5.2.1.4. العناصر المقدَّمة: حقل Provides
يقدم هذا الحقل مفهوم ”الحزمة الظاهرية“. لهذا الحقل أدوار عديدة، لكن اثنين منها لهما أهمية خاصة. يتمثل الدور الأول في استخدام الحزمة الظاهرية لربطها مع خدمة عامة (الحزمة ”توفر provides“ الخدمة). أما الدور الثاني فهو أن هذا الحقل يشير إلى أن الحزمة تستبدل حزمة أخرى بالكامل، وأنها تستطيع أيضاً تلبية اعتماديات الحزم التي تعتمد على الحزمة المُستَبدَلَة. بالتالي، يمكن إنشاء حزمة بديلة دون الاضطرار لاستخدام اسم الحزمة نفسه.
Let us discuss the first case in greater detail with an example: all mail servers, such as postfix or sendmail are said to “provide” the mail-transport-agent virtual package. Thus, any package that needs this service to be functional (e.g. a mailing list manager, such as smartlist or sympa) simply states in its dependencies that it requires a mail-transport-agent instead of specifying a large yet incomplete list of possible solutions (e.g. postfix | sendmail | exim4 | …
). Furthermore, it is useless to install two mail servers on the same machine, which is why each of these packages declares a conflict with the mail-transport-agent virtual package. A conflict between a package and itself is ignored by the system, but this technique will prohibit the installation of two mail servers side by side.
The Provides
field is also interesting when the content of a package is included in a larger package. For example, the libdigest-md5-perl Perl module was an optional module in Perl 5.6, and has been integrated as standard in Perl 5.8 (and later versions, such as 5.20 present in Jessie). As such, the package perl has since version 5.8 declared Provides: libdigest-md5-perl
so that the dependencies on this package are met if the user has Perl 5.8 (or newer). The libdigest-md5-perl package itself has eventually been deleted, since it no longer had any purpose when old Perl versions were removed.
هذه الميزة مفيدة جداً، لأنه لا يمكن أبداً التنبؤ بتقلبات التطوير، ومن المهم أن يكون هناك مجال للتكيف مع إعادة التسمية وغيرها من الاستبدالات الآلية للبرمجيات الميتة.
5.2.1.4.3. Past Limitations
Virtual packages used to suffer from some limitations, the most significant of which was the absence of a version number. To return to the previous example, a dependency such as Depends: libdigest-md5-perl (>= 1.6)
, despite the presence of Perl 5.10, would never be considered as satisfied by the packaging system — while in fact it most likely is satisfied. Unaware of this, the package system chose the least risky option, assuming that the versions do not match.
This limitation has been lifted in dpkg 1.17.11, and is no longer relevant in Jessie. Packages can assign a version to the virtual packages they provide with a dependency such as Provides: libdigest-md5-perl (= 1.8)
.
5.2.1.5. استبدال الملفات: حقل Replaces
The Replaces
field indicates that the package contains files that are also present in another package, but that the package is legitimately entitled to replace them. Without this specification, dpkg
fails, stating that it can not overwrite the files of another package (technically, it is possible to force it to do so with the --force-overwrite
option, but that is not considered standard operation). This allows identification of potential problems and requires the maintainer to study the matter prior to choosing whether to add such a field.
يُبرَّر استخدام هذا الحقل عند تغيير اسم الحزمة أو عند تضمين حزمة في حزمة أخرى. كما يحدث هذا أيضاً عندما يقرر المشرف توزيع الملفات الناتجة عن حزمة مصدرية واحدة بشكل متفاوت بين عدة حزم ثنائية متنوعة: لم يعد الملف المستبدل ينتمي للحزمة القديمة، بل فقط للحزمة الجديدة.
إذا استبدلت جميع ملفات إحدى الحزم المثبتة، تعتبر الحزمة مزالة. أخيراً، يشجع هذا الحقل dpkg
على إزالة الحزمة المستبدَلَة عند حدوث تضارب.
بالإضافة إلى ملف control
، قد يحتوي أرشيف control.tar.gz
الموجود في كل حزمة دبيان على عدد من السكربتات، يستدعيها dpkg
في مراحل مختلفة من معالجة الحزمة. تصف سياسة دبيان الحالات المحتملة بالتفصيل، مُحدِّدَةً السكربتات المستدعاة والمتغيرات التي تستقبلها. هذه التسلسلات قد تكون معقدة، لأنه إذا فشل تنفيذ أحد السكربتات، سيحاول dpkg
العودة إلى حالة مُرضِيَة عبر إلغاء عملية التثبيت أو الإزالة الجارية (طالما كان ذلك ممكناً).
عموماً، يُنفَّذ السكربت preinst
قبل تثبيت الحزمة، في حين يتبعه postinst
. كذلك، يُستدعى prerm
قبل إزالة الحزمة و postrm
بعد ذلك. تحديث الحزمة يكافئ إزالة النسخة القديمة وتثبيت الجديدة. لا يمكن وصف جميع الحالات الممكنة هنا، لكننا سنناقش الحالتين الأكثر شيوعاً: التثبيت أو التحديث، والإزالة.
5.2.2.1. التثبيت والتحديث
إليك ما يحدث خلال التثبيت (أو التحديث):
بالنسبة للتحديث، يستدعي dpkg
الأمر old-prerm upgrade new-version
.
في التحديث أيضاً، ينفذ dpkg
بعدها new-preinst upgrade old-version
؛ أما بالنسبة للتثبيت للمرة الأولى فيستدعي new-preinst install
. قد يضيف dpkg
الإصدار القديم إلى ذيل البارامترات إذا كانت الحزمة مثبتة ومزالة من قبل (لكن لم يتم تطهيرها، أي أن ملفات إعداداتها لا تزال موجودة).
بعدها يفك الضغط عن ملفات الحزمة الجديدة. تستبدل الملفات الموجودة سابقاً، لكن مع الاحتفاظ بنسخة احتياطية مؤقتة.
بالنسبة للتحديث، يستدعي dpkg
الأمر old-postrm upgrade new-version
.
يُحدِّث dpkg
جميع البيانات الداخلية (لائحة الملفات، سكربتات الإعداد، الخ) ويحذف النسخ الاحتياطية للملفات المستبدلة. هذه هي نقطة اللاعودة: عند هذه اللحظة لا يعود dpkg
قادراً على الوصول إلى جميع العناصر اللازمة للرجوع إلى الحالة السابقة.
أخيراً، يضبط dpkg
الحزمة بتنفيذ new-postinst configure last-version-configured
.
إليك ما يحدث أثناء إزالة حزمة:
يستدعي dpkg
الأمر prerm remove
.
يزيل dpkg
جميع ملفات الحزمة، عدا ملفات الضبط وسكربتات الإعداد.
ينفذ dpkg
الأمر postrm remove
. تُحذَف جميع سكربتات الإعداد، عدا postrm
. إذا لم يطلب المستخدم خيار ”التطهير“، تنتهي العملية هنا.
لتطهير الحزمة بالكامل (يطلب هذا الأمر بالشكل dpkg --purge
أو dpkg -P
)، تُحذَف ملفات الإعدادات أيضاً، بالإضافة لعدد معين من النسخ (dpkg-tmp.*
، dpkg-old.*
، dpkg-new.*
) والملفات المؤقتة؛ بعدها ينفذ dpkg
الأمر postrm purge
.
هناك سكربت config
يكمل السكربتات الأربعة المذكورة سابقاً، توفره الحزم التي تعتمد على debconf
للحصول على معلومات من المستخدم لضبط الحزمة. يُحدِّد هذا السكربت أثناء التثبيت الأسئلة التي تطرحها debconf
بالتفصيل. تُسجَّل الإجابات في قاعدة بيانات debconf
للرجوع إليها مستقبلاً. تستدعي apt
هذا السكربت عموماً قبل تثبيت الحزم واحدة تلو الأخرى وذلك لتجميع كل الأسئلة وطرحها جميعاً على المستخدم في بداية العملية. يمكن بعدها أن تستفيد سكربتات ما قبل وما بعد التثبيت من هذه المعلومات حتى تتبع رغبات المستخدم.
5.2.3. شفرات التحقق، لائحة ملفات الضبط
In addition to the maintainer scripts and control data already mentioned in the previous sections, the
control.tar.gz
archive of a Debian package may contain other interesting files. The first,
md5sums
, contains the MD5 checksums for all of the package's files. Its main advantage is that it allows
dpkg --verify
(which we will study in
قسم 14.3.3.1, “Auditing Packages with dpkg --verify
”) to check if these files have been modified since their installation. Note that when this file doesn't exist,
dpkg
will generate it dynamically at installation time (and store it in the dpkg database just like other control files).
يسرد الملف conffiles
ملفات الحزمة التي يجب معاملتها كملفات ضبط. قد يُعدِّل مدير النظام ملفات الضبط، وسوف يحاول dpkg
الحفاظ على هذه التعديلات عند تحديث الحزمة.
في الواقع، يتصرف dpkg
بأذكى ما يمكن في هذه الحالات: إذا لم يتغيَّر ملف الإعدادات القياسي بين النسختين، لا يفعل أي شيء. لكن إذا تَغيَّر الملف، سيحاول تحديث هذا الملف. هناك احتمالين هنا: إما أن مدير النظام لم يلمس ملف الإعداد هذا، وفي تلك الحالة يُثبِّت dpkg
النسخة الجديدة آلياً؛ أو أن الملف قد عُدِّل، وفي تلك الحالة يسأل dpkg
مدير النظام عن النسخة التي يريد أن يستخدمها (النسخة القديمة المعدلة، أو الجديدة الموفرة مع الحزمة). حتى يساعد dpkg
في اتخاذ هذا القرار، يعرض عليك إظهار ”diff
“ يُبيِّنُ الاختلاف بين النسختين. إذا اختار المستخدم إبقاء النسخة القديمة، سوف تُخزَّن الجديدة في نفس المكان في ملف له اللاحقة .dpkg-dist
. أما إذا اختار المستخدم النسخة الجديدة، تحفظ النسخة القديمة في ملف له اللاحقة .dpkg-old
. هناك خيار آخر متاح وهو مقاطعة dpkg
مؤقتاً لتحرير الملف ومحاولة استرجاع التعديلات المناسبة (التي تم التعرف عليها باستخدام diff
).