LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-20-2008, 05:59 AM   #1
lusiads
LQ Newbie
 
Registered: Sep 2008
Posts: 17

Rep: Reputation: 0
Question 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
Code:
yum -y install package-name
on Debian based, It would be
Code:
apt-get -y install package-name
similar to Gentoo
Code:
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.
 
Old 09-20-2008, 06:15 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,019
Blog Entries: 54

Rep: Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766
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.

Last edited by unSpawn; 09-20-2008 at 06:18 AM. Reason: more is more
 
Old 09-20-2008, 07:07 AM   #3
lusiads
LQ Newbie
 
Registered: Sep 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Wink

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.
Code:
if [ -f /etc/redhat-release ] ; then
PKMGR=`which yum`
elif [ -f /etc/debian_version ] ; then
PKMGR=`which apt-get`
fi
I'm just interested in LSB-complaint distros, is there any better way?
 
Old 09-20-2008, 07:15 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,019
Blog Entries: 54

Rep: Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766
Your question is somewhat vague. Define "better".
 
Old 09-20-2008, 12:57 PM   #5
lusiads
LQ Newbie
 
Registered: Sep 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Red face

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?
 
Old 09-21-2008, 03:41 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,019
Blog Entries: 54

Rep: Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766
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?
 
Old 09-21-2008, 07:54 AM   #7
lusiads
LQ Newbie
 
Registered: Sep 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Okay, Thanks a lot.
 
  


Reply

Tags
bash


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Simple Package management with Synaptic Package Manager LXer Syndicated Linux News 0 12-05-2006 06:33 PM
latex2e package unavailable in package manager or apt-get cesine Debian 2 07-11-2006 02:31 PM
Poll: Yast Package Manager vs. Smart Package Manager in 10.1 agentchange Suse/Novell 6 06-02-2006 08:29 AM
synaptic package manager forcing me to delete a broken package mbman Linux - Software 6 04-25-2006 09:30 AM


All times are GMT -5. The time now is 11:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration