Sindhu S
Sindhu S

Reputation: 1012

Reliable way of finding out debian release name

I have a script that needs to know what is the release name of a debian system (example: trusty, sid, wheezy etc). I know that I can find out if I am on a Debian based system by looking for /etc/debian_version, but:

cat /etc/debian_version

cat /etc/issue

on Debian Stable produces:

root@07156660e2cd:/# cat /etc/debian_version 7.8 root@07156660e2cd:/# cat /etc/issue
Debian GNU/Linux 7 \n \l

on Ubuntu produces:

```root@a81e3f32b147:/# cat /etc/issue Ubuntu 14.04.2 LTS \n \l

root@a81e3f32b147:/# cat /etc/debian_version jessie/sid ```

How I get Ubuntu's codename (in this case 'Trusty')? I don't want to have to maintain a dictionary of release versions to names please. Is there a way in the system to find this information out?

Thanks!

Upvotes: 0

Views: 884

Answers (3)

Valeriy Solovyov
Valeriy Solovyov

Reputation: 5648

In docker images I can't use uname or another things. So I am using:

DEBIAN_RELEASE=$(awk -F'[" ]' '/VERSION=/{print $3}'  /etc/os-release | tr -cd '[[:alnum:]]._-' )

or not depending on /etc/os-release

awk -F'[" ]' '/VERSION=/{print $3}'  /etc/*-release | head -1 |tr -cd '[[:alnum:]]._-'

PS:

For docker images based on Debian I am using:

RUN export  DEBIAN_FRONTEND=noninteractive && \
     export DEBIAN_RELEASE=$(awk -F'[" ]' '/VERSION=/{print $3}'  /etc/os-release | tr -cd '[[:alnum:]]._-' ) &&
     echo "remove main from /etc/apt/sources.list" && \
     sed -i '/main/d' /etc/apt/sources.list && \
     echo "remove contrib from /etc/apt/sources.list" && \
     sed -i '/contrib/d' /etc/apt/sources.list && \
     echo "remove non-free from /etc/apt/sources.list" && \
     sed -i '/non-free/d' /etc/apt/sources.list && \
     echo "deb http://httpredir.debian.org/debian ${DEBIAN_RELEASE} main contrib non-free"  >> /etc/apt/sources.list && \
     echo "deb http://httpredir.debian.org/debian ${DEBIAN_RELEASE}-updates main contrib non-free"  >> /etc/apt/sources.list && \
     echo "deb http://security.debian.org ${DEBIAN_RELEASE}/updates main contrib non-free"  >> /etc/apt/sources.list && \
    set -x &&\
    apt-get update 

Upvotes: 0

exussum
exussum

Reputation: 18560

@svlasov answer returns a little too much

lsb_release -sc returns just the code name

example

$ lsb_release -sc
utopic

Upvotes: 0

svlasov
svlasov

Reputation: 10455

Use lsb_release:

lsb_release -c

Upvotes: 1

Related Questions