How can I make dpkg automatically choose my own virtual package over an already installed one?

StackOverflow https://stackoverflow.com/questions/23128262

  •  05-07-2023
  •  | 
  •  

Pregunta

I have several packages that provide the same functionality - and in the device 'there can be only one' at the same time.

I have read about the 'Provides, Conflicts, Replaces' in the debian policy, but I have not found a way (using dpkg with commands/switches) to automatically replace an already installed virtual package without removing it manually first.

My package's control file specifies the following for all the packages in question:

Provides: myown-virtual-package
Conflicts: myown-virtual-package
Replaces: myown-virtual-package

Here is what I do, It seems to work, but I was wondering if there is a standard way using only dpkg

# remove any conflicting virtual packages
for i in /tmp/upgrade_software/*.deb
do
    # find out what package name and what it provides
    provides_line=$(dpkg --info $i | grep "^ Provides: ")
    package_line=$(dpkg --info $i | grep "^ Package: ")
    virt_package=${provides_line##*: }
    this_package=${package_line##*: }

    # skip if it is not a virtual package 
    [ -z "${virt_package}" ] && continue


    # remove any package that provides the same
    otherpackage_line=$(dpkg-query -W -f='${Provides}: ${Package}\n' \
        | grep "${virt_package}:" | grep -v ${this_package})
    if [ -n "${otherpackage_line}" ] ; then
        otherpackage=${otherpackage_line##*: }
        echo "    ------ removing ${otherpackage} because of conflict -------"
        dpkg --purge ${otherpackage}
        echo "    -------------"
    fi
    echo \'$virt_package\' checked for conflicts
done

Thanks in advance, jj

¿Fue útil?

Solución

dpkg will not take this kind of automatic conflict resolution measures. For these tasks, there is apt-get and aptitude. It may just work with

dpkg -i package.deb ; apt-get -f install

The latter command is supposed to resolve the conflicts. If it opts to remove your own package for resolution, you may even want to try

dpkg -i package.deb ; apt-get -f install <package>

I.e., tell apt to install your package (without a .deb extension) as it should now be visible to apt.

Otros consejos

This can be done with dpkg alone, by giving it enough information so that it can perform the operation. The way to prepare dpkg for this is via selections.

In this case you'd tell that removing the old provider is ok, and then when you install the new one dpkg will be able to remove the other package during the upgrade.

Try something like:

echo old-provider deinstall | dpkg --set-selections
dpkg -iB new-provider.deb

That should in principle do it, and no need for apt-get fixing it up (-f), or for pre purges (possibly with --force options if there are packages depending on the virtuals).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top