12月 172010
 

作者: 秋风的家

一、前言

所谓的软件安装,不管是那个系统,都是通过一定的方法把文件从源复制到目的,然后做一些配置工作,使其能正常的运行,卸载。

对于Linux来说,其目录的高度组织化,以及各软件依赖关系的复杂性,使得软件包数据库显得非常重要。

简单来说,软件包数据库最主要记录两点:

   1. 软件包包含的文件列表
   2. 软件的依赖关系

对与debian的软件包数据库来说,要做的事情更多:

   1. 软件的安装状态
   2. 软件的配置状态
   3. 软件的post-uninstall

有很多原因会导致软件安装失败,但大多数都集中在:

   1. 安装时的post-install
   2. 卸载时的post-uninstall

虽然不会对系统造成问题,但是每次安装软件,或者升级软件的时候,都会提示有软件包需要配置,其实的确很烦人。

当然,大多数情况可以通过:

    dpkg-reconfigure PKG_NAME

来完成。更讨厌的是,有时候这个办法不是总十分有效。

这时候就需要手动修改软件包数据库,以达到完成配置,修复安装的目的。
二、原理

dpkg之所以能够对每个包的状态了如指,完全是因为dpkg数据库—>>/var/lib/dpkg/status
这个文本文件中记录了软件仓库中曾经安装过的软件包的安装状态。
所以,只需要改动这个文件就能够改变软件包的状态。

根据dpkg手册页的描述,软件包的状态有

    1、not-installed
    The package is not installed on your system.
    2、config-files
    Only the configuration files of the package exist on the system.
    3、half-installed
    The installation of the package has been started, but not com-
    pleted for some reason.
    4、unpacked
    The package is unpacked, but not configured.
    5、half-configured
    The package is unpacked and configuration has been started, but
    not yet completed for some reason.
    6、 triggers-awaited
    The package awaits trigger processing by another package.
    7、 triggers-pending
    The package has been triggered.
    8、 installed
    The package is unpacked and configured OK.

其中,half-installed和half-configured是常见的错误状态,不完全配置,或者不完全安装。

另外,软件包还有一个选择状态:

    1、install
    The package is selected for installation.
    2、deinstall
    The package is selected for deinstallation (i.e. we want to
    remove all files, except configuration files).
    3、purge The package is selected to be purged (i.e. we want to remove
    everything, even configuration files).

最后组合起来的错误状态大概就有6种,安装、删除出错都会将软件包的状态标记成其中之一!
它们的状态都要被修改成:install ok installed ; deinstall ok not-installed或purge ok not-installed。

最后需要注意的是:
软件包除了处在not-install 的状态,其余状态都是有完整的描述的。
要将错误状态修改成installed状态,需要查看一下软件包的描述是否有。(这个一般是有的)
要将错误状态修改成not-install状态,需要删除软件包的描述,删除Section行下面的全部。(不要把别人的删掉)
三、例子

    Package: libexempi3
    Status: purge ok half-installed
    Priority: optional
    Section: libs
    Installed-Size: 748
    Maintainer: Ubuntu Core Developers
    Architecture: i386
    Source: exempi
    Version: 2.0.2-2
    Depends: libc6 (>= 2.4), libexpat1 (>= 1.95.8), libgcc1 (>= 1:4.1.1), libstdc++6 (>= 4.2.1)
    Description: library to parse XMP metadata (Library)
    Exempi is a library to parse XMP metadata as defined by the
    specification.
    .
    XMP (Extensible Metadata Platform) facilitates embedding metadata in files
    using a subset of RDF. Most notably XMP supports embedding metadata in PDF
    and many image formats, though it is designed to support nearly any file type.
    Original-Maintainer: Asheesh Laroia
    Homepage: http://libopenraw.freedesktop.org/wiki/Exempi

色标记处就是一种错误的状态。把它修改成:

    Package: libexempi3
    Status: purge ok not-installed
    Priority: optional
    Section: libs

这个软件包的状态就修改好了,不会再报错了。

好了,写了这么多了,最后一个警告:编辑这个文件之前记得备份!

------此方法绝无毒副作用,可放心使用----

 回复

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>