Reliable way to determine native packaging system

Bryn M. Reeves bmr at redhat.com
Thu Mar 14 17:39:10 UTC 2013


On 03/14/2013 04:43 PM, Michael Schwendt wrote:
> On Thu, 14 Mar 2013 16:09:24 +0100, Reindl Harald wrote:
>> presence of /var/lib/rpm
>> /etc/os-release
>> /etc/redhat-release
>
> And perhaps a run-time check, such as an RPM based query, which would
> only work if the RPM database is filled with details about installed
> files.
>
>    $ rpm -qa|wc -l
>    1601
>    $ rpm -qf /sbin/init
>    systemd-198-3.fc19.x86_64
>    $ rpm -qf $(which bash)
>    bash-4.2.45-1.fc19.x86_64
>

There's no standard way I know of that's guaranteed to work (I think LSB
has some bits that could help but since you can't depend on them being
installed or even available everywhere it's pretty much useless).

You could take a look at how sos does this:

https://github.com/sosreport/sosreport

Sos is a support data collection tool written in python. The upstream
version now runs on Fedora, RHEL, RHEV, RHS, Debian, Ubuntu, Mac OSX,
and Windows. It abstracts package management in a policy class - each
target defines a policy which probes the environment to determine
whether it should be the active policy. So for e.g. if
/etc/fedora-release or /etc/redhat-release exists the redhat policy is
activated.

This is fairly robust and lets you define hierarchies (e.g. the Ubuntu
policy extends Debian policy, and both Debian and Red Hat policies
inherit from a common LinuxPolicy) so that policies can share common
bits of implementation.

The downside is that you have to create and maintain the policies and
either add support for each new flavour or provide generic fall backs
that do a reasonable job on unknown hosts.

Regards,
Bryn.



More information about the users mailing list