Software-Installation

dpkg –dry-run 選項未正確模擬安裝

  • January 31, 2019

給定一個隨機的 .DEB 文件,我們如何在沒有實際安裝到設備上的情況下檢查安裝是否會成功完成?請參閱以下程式碼段:

root@VirtualBox:/Folder# dpkg -i mysql-workbench_6.2.3+dfsg-7_armhf.deb 
Selecting previously unselected package mysql-workbench.
(Reading database ... 48937 files and directories currently installed.)
Preparing to unpack mysql-workbench_6.2.3+dfsg-7_armhf.deb ...
Unpacking mysql-workbench (6.2.3+dfsg-7) ...
dpkg: dependency problems prevent configuration of mysql-workbench:
mysql-workbench depends on libatkmm-1.6-1 (>= 2.22.1); however:
 Package libatkmm-1.6-1 is not installed.
mysql-workbench depends on libcairo2 (>= 1.14.0); however:
 Package libcairo2 is not installed.
mysql-workbench depends on libcairomm-1.0-1 (>= 1.6.4); however:
 Package libcairomm-1.0-1 is not installed.
mysql-workbench depends on libctemplate2; however:
 Package libctemplate2 is not installed.
mysql-workbench depends on libgdal1h (>= 1.8.0); however:
 Package libgdal1h is not installed.
mysql-workbench depends on libgdk-pixbuf2.0-0 (>= 2.22.0); however:
 Package libgdk-pixbuf2.0-0 is not installed.
mysql-workbench depends on libgl1-mesa-glx | libgl1; however:
 Package libgl1-mesa-glx is not installed.
 Package libgl1 is not installed.
mysql-workbench depends on libglibmm-2.4-1c2a (>= 2.42.0); however:
 Package libglibmm-2.4-1c2a is not installed.
mysql-workbench depends on libgnome-keyring0 (>= 2.22.2); however:
 Package l
dpkg: error processing package mysql-workbench (--install):
dependency problems - leaving unconfigured
Processing triggers for mime-support (3.58) ...
Processing triggers for shared-mime-info (1.3-1) ...
Errors were encountered while processing:
mysql-workbench
root@VirtualBox:/Folder# echo $?
1
root@VirtualBox:/Folder# dpkg --dry-run -i mysql-workbench_6.2.3+dfsg-7_armhf.deb 
(Reading database ... 49115 files and directories currently installed.)
Preparing to unpack mysql-workbench_6.2.3+dfsg-7_armhf.deb ...
root@VirtualBox:/Folder# echo $?
0
root@VirtualBox:/Folder# dpkg --dry-run --simulate -i mysql-workbench_6.2.3+dfsg-7_armhf.deb 
(Reading database ... 49115 files and directories currently installed.)
Preparing to unpack mysql-workbench_6.2.3+dfsg-7_armhf.deb ...
root@VirtualBox:/Folder# echo $?
0
root@VirtualBox:/Folder# 

當我使用該dpkg -i選項時,命令失敗,返回值為 1,但與 a 相同的命令--dry-run返回零。添加該--simulate選項似乎也不會改變行為。有關如何始終檢查 .DEB 文件的安裝是否會正確完成而不實際安裝軟體包的任何指示?

我在 Raspberry Pi 模擬器上執行它。

root@VirtualBox:/Folder# cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

要確定是否可以安裝軟體包而不需要安裝其他依賴項,最好的辦法是使用“模擬”模式apt

apt -s install ./mysql-workbench_6.2.3+dfsg-7_armhf.deb

(注意./這是重要的)。這將輸出dpkg實際安裝將執行的操作。軟體包安裝標有Inst; 如果其中有多個,則無法單獨安裝該軟體包。

現在,進入最重要的部分……你不能使用dpkg它,不是因為dpkg不知道依賴關係(它肯定知道),而是因為依賴關係不夠強大。當一個包依賴於另一個包時,如果包不滿足,依賴不會阻止它被安裝,它會阻止它被配置。請參閱Debian 政策的第 7.2 節

只有在需要配置包時,Depends欄位才會生效。它不會阻止一個包在其依賴關係不滿足時處於未配置狀態的系統上,並且可以將一個依賴關係滿足並且正確安裝的包替換為依賴關係不滿足和不能滿足的不同版本;完成此操作後,依賴包將保持未配置狀態(因為嘗試配置它會出錯)並且無法正常執行。

您可以在自己的測試中看到這一點:該過程失敗了

dpkg: dependency problems prevent configuration of mysql-workbench

注意“配置”,而不是“安裝”。如果您查看 的輸出dpkg -l mysql-workbench,您應該會看到iU,這意味著軟體包已安裝但未配置。

當您在 中啟用“模擬”模式時dpkg,它基本上以只讀模式執行。它通過設置一個f_noact標誌來做到這一點;您可以在原始碼中查找此內容。安裝包時,模擬完成安裝動作(不寫任何東西),然後進入配置階段;但這只是假裝成功,這是模擬唯一可以做的事情——配置涉及在包中執行維護者腳本,並且很難確保這些腳本沒有進行更改,或者確保可以確定它們的成功不允許他們進行更改。因此,在您的情況下,模擬會安裝成功的包(如在您的非模擬測試中),並偽造配置。因此沒有檢測到錯誤…

引用自:https://unix.stackexchange.com/questions/404784