I
I
iandriyanov2012-09-29 17:49:29
linux
iandriyanov, 2012-09-29 17:49:29

linux. OS version check

I want to write a script that, depending on the OS (gentoo or deb), installed packages.

There are some sketches, but there is definitely something wrong with them.

#!/bin/sh

WHERE_IS=`whereis lsb_release | awk {'print $2'}`
EMERGE="emerge -av `eix lsb | grep release | awk {'print $2'}`"


if [ -z $WHERE_IS ]; then
    echo "$n не существует."
    $EMERGE
else
    echo "$n существует."
    echo $WHERE_IS
fi



I ask for ideas, or some ready-made solutions. I saw something similar somewhere, but I don't remember where.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
I
iandriyanov, 2012-10-01
@iandriyanov

A decent Skeleton, to the public's judgment:

#!/bin/sh

cmd0=`whereis emerge | awk {'print $2'}`

_new_check_lsb()
{
echo "Какая у вас ОС - Ubuntu или Gentoo? Или Help для того чтобы узнать какая у вас ОС"
read -p "Введите название: " yn

    case "${yn,,}" in
        gentoo)
            echo "test - gentoo"
            ;;
        ubuntu)
            echo "test - ubuntu"
            ;;
        help)
            if [ "$cmd0" = "" ]; then
                echo "Ubuntu"
            else
                echo "Gentoo"
            fi
            _new_check_lsb
            ;;
        *)
            echo "Вы не чего не ввели"
            ;;
    esac

}
_new_check_lsb

A
Andrey Burov, 2012-09-30
@BuriK666

#!/bin/bash
if [ -e /etc/gentoo-release ]; then 
    echo "Gentoo"
elif [ -e /etc/debian_version ]; then 
        echo "Debian"
fi

R
rasa, 2012-09-29
@rasa

Didn't you encounter something similar here ?

G
Golden, 2012-09-29
@g0lden

I would take the output of "uname -a" as a basis, unless of course it is too primitive within the framework of the task.
You can also look into the script from virtualbox for guest OSes, as far as I remember, it determines in which OS it is launched, although I could be mistaken, there is no way to look now.

D
DeGato, 2012-09-29
@DeGato

There is this:
cat /etc/issue
by default there is usually an OS version

G
gricom, 2012-09-29
@gricom

gcc usually helps me when I want to know the OS version. Just parse the output of gcc --version

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question