-   Programming (
-   -   Detect package manager in bash (

lusiads 09-20-2008 06:59 AM

Detect package manager in bash
I want to write a simple script that simplifies the installation process of some software from standard repos, which runs on different distros.

For example,
on Redhat based distro, I would call

yum -y install package-name
on Debian based, It would be

apt-get -y install package-name
similar to Gentoo

emerge package-name
How can I archive this goal?
Which is the best way to detect the default package manager on specific distro and how?
Keep in mind that parameters of these package managers are different.

Any help would be appreciated.

unSpawn 09-20-2008 07:15 AM

Most distro's will have a file in /etc that lists distribution like /etc/*release or /etc/*ersion. For an example grep for instance the Rootkit Hunter script for "REL_FILES". LSB-compliant releases can also be queried using 'lsb_release -irs'. From then on (or even without distro check) it's just testing a list of applications to use (which, test -x). Note network probs and updater configuration options like blacklisting so do run post checks instead of assuming the install succeeded.

lusiads 09-20-2008 08:07 AM

Thank you for such quickly reply.

Your information is somewhat useful to me.
I would try to detect distro then making assumption about its default package manager.

if [ -f /etc/redhat-release ] ; then
PKMGR=`which yum`
elif [ -f /etc/debian_version ] ; then
PKMGR=`which apt-get`

I'm just interested in LSB-complaint distros, is there any better way?

unSpawn 09-20-2008 08:15 AM

Your question is somewhat vague. Define "better".

lusiads 09-20-2008 01:57 PM

I'm sorry.
All I want is a script that installs some specific packages on different distros.
I want to install scim scim-m17n m17n-db and all their dependencies.Then checking if version of these installed packages are correct. If they are not, I will try to setup compilation environment and compile them from source.

How could I do this the easy way?

unSpawn 09-21-2008 04:41 AM

I think you're on the right track. If your script runs interactively you might want to add an option to ask the user for input to bypass or select a package manager?

lusiads 09-21-2008 08:54 AM

Okay, Thanks a lot.

All times are GMT -5. The time now is 03:53 AM.