The Debian package is not only an archive of files intended for installation. It is part of a larger whole and describes its relationship with other Debian packages (requisites, dependencies, conflicts, suggestions). It also provides scripts that enable the execution of commands at different stages in the package's lifecycle (installation, upgrade, removal). 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) and is fully described in the Debian Policy and the manual pages
deb-control(5) and
deb822(5).
For example, for apt, the control
file looks like the following:
$
apt-cache show apt
Package: apt
Version: 1.8.2
Installed-Size: 4064
Maintainer: APT Development Team <deity@lists.debian.org>
Architecture: amd64
Replaces: apt-transport-https (<< 1.5~alpha4~), apt-utils (<< 1.3~exp2~)
Provides: apt-transport-https (= 1.8.2)
Depends: adduser, gpgv | gpgv2 | gpgv1, debian-archive-keyring, libapt-pkg5.0 (>= 1.7.0~alpha3~), libc6 (>= 2.15), libgcc1 (>= 1:3.0), libgnutls30 (>= 3.6.6), libseccomp2 (>= 1.0.1), libstdc++6 (>= 5.2)
Recommends: ca-certificates
Suggests: apt-doc, aptitude | synaptic | wajig, dpkg-dev (>= 1.17.2), gnupg | gnupg2 | gnupg1, powermgmt-base
Breaks: apt-transport-https (<< 1.5~alpha4~), apt-utils (<< 1.3~exp2~), aptitude (<< 0.8.10)
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,
scope::application, scope::utility, suite::debian, use::downloading,
use::organizing, use::playing, use::searching, works-with-format::html,
works-with::audio, works-with::software:package, works-with::text
Section: admin
Priority: required
Filename: pool/main/a/apt/apt_1.8.2_amd64.deb
Size: 1418108
MD5sum: 0e80dedab6ec1e66a8f6c15f1925d2d3
SHA256: 80e9600822c4943106593ca5b0ec75d5aafa74c6130ba1071b013c42c507475e
5.2.1.1. وابستگیها: فیلد Depends
The dependencies are defined in the Depends
field in the package header. It 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, tools, drivers, etc. 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:
<<
: کوچکتر از;
<=
: کوچکتر یا مساوی;
=
: مساوی;
>=
: بزرگتر یا مساوی;
>>
: بزرگتر از.
In a list of conditions to be met, the comma serves as a separator. It must be interpreted as a logical “and”. In conditions, the vertical bar (“|”) expresses a logical “or” (it is an inclusive “or”, not an exclusive “either/or”). Carrying greater priority than “and”, it can be used as many times as necessary. Thus, the dependency “(A or B) and C” is written
A | B, C
. In contrast, the expression “A or (B and C)” should be written as “(A or B) and (A or C)”, since the
Depends
field does not tolerate parentheses that change the order of priorities between the logical operators “or” and “and”. It would thus be written
A | B, A | C
.
سیستم وابستگیها مکانیزم خوبی برای تضمین عملکرد یک برنامه است اما کاربرد دیگری با “meta-packages” نیز دارد. اینها بستههای خالی هستند که تنها به توضیح وابستگیها میپردازند. آنها فرآیند نصب گروهی از برنامهها که توسط نگهدارندهشان انتخاب شده است، تسهیل میبخشند؛ به همین دلیل، apt install meta-package
به صورت خودکار تمام برنامههای مورد نیاز meta-package را نصب میکند. gnome، kde-full و linux-image-amd64 نمونههایی از meta-packages هستند.
5.2.1.2. تداخلها: فیلد Conflicts
The Conflicts
field indicates when a package cannot be installed simultaneously with another. The most common reasons for this are that both packages include a file of the same name and path, or provide the same service on the same TCP port, or would hinder each other's operation.
dpkg
در صورتی که بسته مورد نظر با بسته دیگری تداخل داشته باشد، اقدام به نصب آن نمیکند بجز حالتی که بسته جدید جایگزین نسخه قبلی آن شود که در این صورت dpkg
بسته قدیمی را با جدید جایگزین خواهد کرد. apt
همیشه از دستورالعملهای شما پیروی میکند: اگر انتخاب کنید که بسته جدیدی نصب گردد، به صورت خودکار پیشنهاد حذف بستههای دردسرساز را به شما میدهد.
5.2.1.3. ناسازگاریها: فیلد Breaks
فیلد Breaks
تاثیر مشابه مانند فیلد Conflicts
دارد، اما به طور متفاوتی. نشان میدهد که نصب یک بسته، بسته دیگری را “break” میکند (یا نسخه مشخصی از آن را). به طور کلی، این عدم سازگاری بین دو بسته، موقتی است و رابطه Breaks
به صورت خاص اشاره به نسخههای ناسازگار از آنها دارد.
dpkg
از نصب برنامهای که با سایر بستهها ناسازگاری داشته و موجب خرابی آنها میشود، جلوگیری کرده و apt
با بروزرسانی بسته خراب به نسخه جدیدتر (که این ناسازگاری را رفع کرده است) تلاش برای حل این مساله میکند.
این گونه شرایط ممکن است در حالتی رخ دهد که بروزرسانی بدون توجه به سازگاری با نسخههای قدیمیتر اجرا شده باشد: مانند حالتی که نسخه جدید با نسخه قدیم دیگر سازگاری نداشته باشد و باعث خرابی در برنامه دیگری شود بدون آنکه هیچ اطلاعی راجع به آن کسب کند. فیلد Breaks
کاربر را در ورود به چنین شرایطی آگاه میسازد.
5.2.1.4. گزینههای فراهمشده: فیلد Provides
این فیلد، مفهوم بسیار جالب “بسته مجازی” را معرفی میکند. این بستهها نقشهای متفاوتی ایفا میکنند، اما دو نقش آن از اهمیت خاصی برخوردار هستند. نقش اول شامل کاربرد یک بسته مجازی برای انطباق با یک سرویس عمومی است (بسته، سرویس را “فراهم” میکند). نقش دوم نشان میدهد که یک بسته جایگزین دیگری میشود، و با تمام وابستگیهای بسته قدیم سازگار خواهد بود. بنابراین این امکان وجود دارد که بدون بکاربردن نام واقعی یک بسته، جایگزینی برای آن تعریف کرد.
5.2.1.4.1. فراهمآوردن یک “سرویس”
بیاید در مورد اول با جزئیات بیشتری به همراه یک مثال بحث کنیم: گفته میشود که تمام سرورهای ایمیل مانند postfix یا sendmail بسته مجازی mail-transport-agent را “فراهم میآورد”. بنابراین، هر بستهای که به این سرویس نیاز داشته باشد (مانند میلینگلیست smartlist یا sympa) به سادگی وابستگیهای خود را در قالب بسته مجازی mail-transport-agent بیان میکند تا اینکه بخواهد به فهرست بلندبالا و ناسازگاری از راهکارهای موجود اشاره کند (مانند postfix | sendmail | exim4 | …
). علاوه بر این، نصب دو سرور ایمیل روی یک ماشین کار بیهودهای است که به همین دلیل هر کدام از این بستهها، ناسازگاری خود را با بسته مجازی mail-transport-agent نشان میدهد. مغایرت یک بسته با خودش از طرف سیستم نادیده گرفته میشود، اما این تکنیک از نصب دو سرور ایمیل در کنار یکدیگر جلوگیری بعمل میآورد.
5.2.1.4.2. قابلیت تعویض با بستهای دیگر
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.28 present in Buster). 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. محدودیتهای سابق
بستههای مجازی سابق بر این از برخی محدودیتها رنج میبردند، که مهمترین آنها نبود شماره نسخه بود. در بازگشت به مثال فوق، یک وابستگی مانند Depends: libdigest-md5-perl (>= 1.6)
برخلاف وجود Perl 5.10، توسط سیستم بستهبندی هیچگاه درنظر گرفته نمیشود - با اینکه اینطور بنظر میرسد. سیستم بستهبندی، بدون آگاهی از این موضوع، آخرین گزینه موجود را بررسی میکند که منجر به عدم تطابق نسخهها میگردد.
This limitation has been lifted in dpkg 1.17.11, and is no longer relevant. 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
فیلد Replaces
بیان میکند بسته شامل فایلهایی است که در سایر بستهها وجود دارد، اما بسته بصورت قانونی اقدام به جایگزینی آنها میکند. بدون این مشخصات، dpkg
در عملیات خود با شسکت روبهرو میشود با بیان اینکه نمیتواند روی سایر فایلهای بستههای دیگر بنویسد (به لحاظ فنی، امکان اجرای آن با استفاده از گزینه --force-overwrite
وجود دارد، اما عملیات استانداردی بحساب نمیآید). این امر، امکان شناسایی مشکلات باالقوه را میدهد و نگهدارنده بسته را ملزم میسازد که قبل از اضافه کردن چنین فیلدی، به نتایج آن پی ببرد.
استفاده از این فیلد در صورت تغییر نام بسته یا بکاررفتن آن در بسته دیگری، توجیه پذیر است. همچنین در شرایطی که نگهدارنده بسته تصمیم میگیرد فایلهای جداگانهای در کنار بستههای باینری تولید شده از بسته سورس قرار دهد: یک فایل جایگزین شده دیگر متعلق به بسته قدیم نیست، بلکه تنها به بسته جدید تعلق دارد.
اگر تمام فایلهای یک بسته موجود تغییر کنند، بسته در شرایط حذف قرار میگیرد. در نهایت، این فیلد به dpkg
کمک میکند در شرایط بروز تداخل با سایر بستهها، آن را حذف کند.
5.2.2. اسکریپتهای پیکربندی
In addition to the
control
file, the
control.tar.gz
archive for each Debian package may contain a number of scripts, called by
dpkg
at different stages in the processing of a package. The Debian Policy describes the possible cases
in detail, specifying the scripts called and the arguments that they receive. These sequences may be complicated, since if one of the scripts fails,
dpkg
will try to return to a satisfactory state by canceling the installation or removal in progress (insofar as it is possible).
In general, the preinst
script is executed prior to installation of the package, while postinst
follows it. Likewise, prerm
is invoked before removal of a package and postrm
afterwards. An update of a package is equivalent to removal of the previous version and installation of the new one. It is not possible to describe in detail all the possible scenarios here, but we will discuss the most common two: an installation/update and a removal.
این اتفاقی است که در حین نصب (یا بروزرسانی) میافتد:
برای بروزرسانی، dpkg
به فراخوانی old-prerm upgrade new-version
میپردازد.
هنوز برای بروزرسانی، dpkg
به فراخوانی new-preinst upgrade old-version
میپردازد؛ برای اولین مرتبه نصب، new-preinst install
را اجرا میکند. ممکن است نسخه قدیم را در آخرین پارامتر قرار دهد، اگر بسته نصب یا به تازگی حذف شده باشد (اما purge نشده باشد، که در این حالت فایلهای پیکربندی باقی میمانند).
فایلهای بسته جدید از حالت فشرده خارج میشوند. اگر فایلی موجود باشد، جایگزین میگردد اما در همین حالت یک نسخه پشتیبان از آن گرفته میشود.
برای بروزرسانی، dpkg
به فراخوانی old-postrm upgrade new-version
میپردازد.
dpkg
تمام دادههای داخلی (فهرست فایلها، اسکریپتهای پیکربندی و ...) را بروزرسانی و فایلهای پشتیبان از نسخههای موجود را حذف میکند. این نقطهای است که دیگر بازگشتی وجود ندارد: dpkg
دیگر به تمام اجرای ضروری جهت بازگشت به حالت قبلی دسترسی نخواهد داشت.
در نهایت، dpkg
به فراخوانی new-postinst configure last-version-configured
میپردازد تا بسته را پیکربندی کند.
این اتفاقی است که در حین حذف بسته میافتد:
dpkg
به فراخوانی prerm remove
میپردازد.
dpkg
تمام فایلهای بسته را پاک میکند، به جز فایلهای پیکربندی و اسکریپتهای پیکربندی.
dpkg
به فراخوانی postrm remove
میپردازد. تمام اسکریپتهای پیکربندی، به جز postrm
حذف میشوند. اگر کاربر از گزینه “purge” استفاده نکرده باشد، فرآیند در همین نقطه به پایان میرسد.
برای حذف کامل یک بسته (دستوری که به صورت dpkg --purge
یا dpkg -P
اجرا میشود)، فایلهای پیکربندی نیز حذف میگردند، همچنین تعدادی از کپیهای (*.dpkg-tmp
، *.dpkg-old
و *.dpkg-new
) و فایلهای موقت؛ dpkg
سپس به اجرای postrm-purge
میپردازد.
چهار اسکریپتی که در بالا به توضیحشان پرداختیم توسط اسکریپت config
کامل میشوند، که توسط بستههای مورد استفاده debconf
جهت جمعآوری اطلاعات پیکربندی از کاربر گرفته میشود. در زمان نصب، این اسکریپت پرسشهای مورد نیاز توسط debconf
را تعریف میکند. پاسخها نیز در پایگاهداده debconf
برای ارجاع بعدی ذخیره میگردند. اسکریپت معمولاً توسط apt
اجرا میگردد و درست قبل از نصب بستهها به صورت ترتیبی و یک به یک پرسشها مطرح میشود. اسکریپتهای پیش و پس از نصب میتوانند از این اطلاعات جهت شخصیسازی تنظیمات کاربر استفاده کنند.
5.2.3. Checksums، فهرستی از فایلهای پیکربندی
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.4.1, “بازرسی بستهها با استفاده از dpkg --verify
”
) and
debsums
(from the package of the same name; see
قسمت 14.3.4.2, “بازرسی بستهها: debsums
و محدودیتهای آن”
) 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
lists package files that must be handled as configuration files (see also deb-conffiles(5)). Configuration files can be modified by the administrator, and dpkg
will try to preserve those changes during a package update.
در این وضعیت، dpkg
به صورت هوشمندانه عمل میکند: اگر فایل پیکربندی استاندارد بین دو نسخه تغییری نکرده باشد، کاری انجام نمیدهد. اگر، در هر صورت، فایل تغییر کرده باشد، تلاش میکند تا آن را بروز نماید. دو حالت ممکن پیش میآید: یا مدیرسیستم اقدام به تغییر آن نکرده است که در این حالت dpkg
به صورت خودکار نسخه جدید را نصب میکند؛ یا فایل تغییر کرده است، که در این حالت dpkg
از مدیرسیستم میپرسد کدام نسخه را میخواهد نگهداری کند (نسخه قدیم با تغییرات یا نسخه جدید همراه با بسته). برای راهنمایی در اتخاذ این تصمیم، dpkg
پیشنهاد میکند که یک “diff
” از اختلاف بین دو فایل نمایش داده شود. اگر کاربر اقدام به حفظ نسخه قدیم کند، نسخه جدید در همان مسیر با پسوند .dpkg-dist
ذخیره میگردد. اگر کاربر نسخه جدید را انتخاب کند، نسخه قدیم با پسوند .dpkg-old
در همان مسیر ذخیره میگردد. یک اقدام دیگر این است که با توقف فعالیت dpkg
اقدام به ویرایش فایل در آن لحظه کرده و سپس عملیات مرتبط با فراخوانی اختلاف بین دو فایل (که توسط diff
مشخص گردید) را اجرا کنیم.