3

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?

4 Answers4

6

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
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 )
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
  • 110,243
0

Ubuntu's "upstream" is Debian and so

$ cat /etc/debian_version
stretch/sid
$ 
DK Bose
  • 44,553