2

I need the Ubuntu codename for generating an apt source.

On Ubuntu, I can use lsb_release --codename --short, which will return (e.g.) trusty.

On (e.g.) Linux Mint, if I use lsb_release -cs, it returns (e.g.) rosa. If I want the upstream codename, I can use lsb_release -csu (which returns trusty).

However, if I use lsb_release -csu on Ubuntu, I get an error lsb_release: error: no such option: -u.

Is there a way to get the upstream-iest Ubuntu codename, including on Ubuntu?

Roger Lipscombe
  • 407
  • 5
  • 16
  • There is no mention of `-u` in http://manpages.ubuntu.com, http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/lsbrelease.html, and https://linux.die.net/man/1/lsb_release. So it seems to me that `-u` is a modification of the lsb_release code by Mint developers. Maybe Mint's man pages can shed some light on this option. – DK Bose Jun 16 '17 at 12:58

4 Answers4

5

On Linux Mint you can source /etc/os-release and access the Ubuntu codename that way:

source /etc/os-release
echo $UBUNTU_CODENAME # xenial

Alternatively, you could extract it with sed

sed 's/UBUNTU_CODENAME=//;t;d' /etc/os-release # xenial

On Linux Mint Sylvia, this is what /etc/os-release looks like:

NAME="Linux Mint"
VERSION="18.3 (Sylvia)"
ID=linuxmint
ID_LIKE=ubuntu
PRETTY_NAME="Linux Mint 18.3"
VERSION_ID="18.3"
HOME_URL="http://www.linuxmint.com/"
SUPPORT_URL="http://forums.linuxmint.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/linuxmint/"
VERSION_CODENAME=sylvia
UBUNTU_CODENAME=xenial
codehearts
  • 151
  • 1
  • 4
  • Doesn't work on trusty; doesn't have `UBUNTU_CODENAME`; you have to do something like this: `UBUNTU_CODENAME=$( (grep DISTRIB_CODENAME /etc/upstream-release/lsb-release || grep DISTRIB_CODENAME /etc/lsb-release) 2>/dev/null | cut -d'=' -f2 )` – Roger Lipscombe Mar 16 '18 at 20:25
1

Ubuntu trusty doesn't have UBUNTU_CODENAME in /etc/os-release (it's too old). Mint sylvia dropped support for the -u switch to lsb_release.

There is, on all the versions of Ubuntu and Mint that I've tried, a file called /etc/lsb-release, which defines DISTRIB_CODENAME. For Mint, it's the Mint codename, but there's also /etc/upstream-release/lsb-release, which is the Ubuntu file.

So...

Currently, we're using the following:

UBUNTU_CODENAME=$( \
   (grep DISTRIB_CODENAME /etc/upstream-release/lsb-release || \
    grep DISTRIB_CODENAME /etc/lsb-release) 2>/dev/null | \
   cut -d'=' -f2 )
Roger Lipscombe
  • 407
  • 5
  • 16
1

You could try running lsb_release -csu, checking if it gave output or returned an error (hiding the error message), and fall back to lsb_release -cs in that case:

lsb_release -csu 2> /dev/null || lsb_release -cs
Byte Commander
  • 105,631
  • 46
  • 284
  • 425
0

Ubuntu's "upstream" is Debian and so

$ cat /etc/debian_version
stretch/sid
$ 
DK Bose
  • 41,240
  • 22
  • 121
  • 214