Finding about which OS is running via shell script
Bill Dengler(arch Gnu/Linux)
billkd2008 at gmail.com
Sat Apr 27 03:44:13 UTC 2013
#The following is a script in one of my projects that detects what
package manager you have and installs the packages based on what it
thinks your distro is.
#Copyright 2013 - Bill Dengler
#raspberrymem is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#raspberrymem is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with raspberrymem. If not, see http://www.gnu.org/licenses
#usage info
if [ $1 == "--help" ]
then
exec echo "usage : installpkg <packages>"
fi
#if we have the --no-depcheck flag exit because we're on a slow
connection on a test platform and we know we have everything we need
if [ $1 == "--no-depcheck" ]
then
exit
fi
#find your package manager and install stuff with it
#Debian based systems
which apt-get &> /dev/null
if [ $? == 0 ]
then
exec apt-get --fix-missing --force-yes -qqqqq -yy install $@
fi
#fedora/red hat/CENT OS
which yum &> /dev/null
if [ $? == 0 ]
then
exec yum -y install $@ &> /dev/null
fi
#gentoo - keep output for debugging as things could go wrong
which emerge &> /dev/null
if [ $? == 0 ]
then
exec emerge $@
fi
#arch linux - todo : support an aurhelpper as well here
which pacman &> /dev/null
if [ $? == 0 ]
then
exec pacman -Syy $@
fi
#suse - never used it so VERY BLOODY!!!
which yast &> /dev/null
if [ $? == 0 ]
then
exec yast -i $@
fi
#add additional package managers here
#we're here because we couldn't detect which package manager to use
echo "I couldn't detect your package manager. Oh no!"
#Bill
On 04/26/13 18:44, Gene Heskett wrote:
> On Friday 26 April 2013 18:44:10 Paul Smith did opine:
>
>> On Fri, 2013-04-26 at 14:04 -0600, JD wrote:
>>> On 04/26/2013 01:46 PM, Kevin Wilson wrote:
>>>> Hello,
>>>> My aim is to right a script that will behave differently
>>>> when running it on Fedora or running it on Ubuntu.
>>>> Is there a way to know from Bash whether the OS is ubuntu or
>>>> Fedora (besides parsing /etc/issue ) ?
>>> A quick way is to run uname
>> This is not reliable though. The only way you can find the distribution
>> is if your distribution just happens to set its name in the kernel
>> version string when they build their kernel. There's no standardization
>> around this.
>>
>> On my CentOS systems, they don't set it at all:
>>
>> $ uname -v
>> #1 SMP Fri Jul 20 01:55:29 UTC 2012
>>
>> On my Mint systems, they use Ubuntu's kernel so the kernel says
>> "Ubuntu".
>>
>> Etc.
> You will sometimes find more accurate info by 'cat /etc/issue'.
>
> Cheers, Gene
More information about the ubuntu-users
mailing list