8

I have a set of functions in bash script which I want to run only on particular flavors of Ubuntu. For example, I want to run the following if I am running Unity:

gsettings set com.canonical.indicator.datetime show-week-numbers true

but the following if I am running Ubuntu GNOME:

gsettings set org.gnome.shell.calendar show-weekdate true

and similarly, different commands for different flavors of Ubuntu.

I have tried to see the contents of /etc/os-release, but it doesn't give any information about the flavor of Ubuntu. The following is when run on Ubuntu GNOME:

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="14.04, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

Is it possible to know which recognized flavor I am running using terminal? I would prefer a solution which works out of the box, without installing any other packages for both live and installed environments. Looking for what packages are installed is a possibility, but I would prefer not to go that route, although you are welcome to give an answer in that direction.

6
  • 1
    Do you want to know the Ubuntu flavor installed or the desktop environment you are currently running? – terdon Apr 23 '14 at 1:28
  • @terdon I am looking for the flavor I've installed/running in a Live Environment.. – Aditya Apr 23 '14 at 9:04
  • 1
    I understand, I just can't imagine why that would ever be useful. The flavor is just the set of packages installed by default, it does not say anything about what you actually have installed. I can install KDE on Xubuntu for example, so why would it be useful to know that I'm running Xubuntu and not Kubuntu? – terdon Apr 23 '14 at 11:07
  • @terdon I just wanted to script it that way, but yes looking at what desktop environment I am running would be more useful. – Aditya Apr 23 '14 at 12:54
  • 1
    @Aditya: Maybe not the flavor... but you can read the XDG_CURRENT_DESKTOP variable to know what the current desktop enviroment is running eg: Unity,GNOME,XFCE,KDE – Roman Raguet May 12 '14 at 13:10
12

This is the command that I use. It works for me all the time:

cat /var/log/installer/media-info 

Output (my system) Correctly tells that I am running Kubuntu

Kubuntu 14.04 LTS "Trusty Tahr" - Beta amd64 (20140326.2)
5
  • It says This to me. – Aditya May 12 '14 at 12:51
  • OP asked for Ubuntu flavours(unity,gnome) – Avinash Raj May 12 '14 at 13:09
  • @AvinashRaj Something like that would have been fine as well :) – Aditya May 12 '14 at 13:19
  • 1
    This is a good way to tell about the installation media used, not the currently running release. If you've been applying all your updates you are no longer running the Beta release – Elder Geek May 14 '14 at 21:01
  • I am currently using Ubuntu 16.04, but this command is giving me following output: Ubuntu 15.10 "Wily Werewolf" - Release amd64 (20151021) – RD017 May 28 '17 at 11:38
8

Maybe not a flavor like Kubuntu, Xubuntu, Lubuntu etc. Because as Oli & terdon comments you can install Kubuntu but running XFCE as Desktop.

So, you can get the value of the enviroment variable XDG_CURRENT_DESKTOP to know what the current desktop is running.

eg:

  • echo $XDG_CURRENT_DESKTOP

Note:
The values of the variable could be Unity,GNOME,XFCE,KDE,LXDE,Pantheon (Elementary os).

Hope this helps.

3
  • Although the question was about recognized flavors and this won't let me know if I am running Edubuntu, UbuntuKylin, Mythbuntu, UbuntuStudio or other recognized flavors; but this would help me solve the problem I was trying to solve. So, +1 for the answer, but I am not really sure if I want to accept it or not. – Aditya May 12 '14 at 13:48
  • @Aditya: I understand. Perhaps the title of your question could be "Is it possible to know which Desktop enviroment I am running using terminal?". according to the content of you question you want to set with gsetting if I'm running Unity or Gnome etc (Desktops) not Flavors. maybe you can combine with the cshubhamrao's answer cat /var/log/installer/media-info. worked for me in virtual machines Kubuntu, Ubuntu Gnome, Ubuntu, Xubuntu. (installed not live) – Roman Raguet May 12 '14 at 14:15
  • Simple and elegant. I like it. – Elder Geek May 14 '14 at 20:49
2

Set both. Set everything. Fire and forget.

The settings are exclusive enough not to affect other things so it should be safe... And it's a lot, lot easier to do than needing to work out what's being run... Working out what's installed is possible but that isn't an indication of what the user actually uses.

2
  • Yes, the commands don't seem to have any side-effects when run on the environment where they are not intended to be run, but isn't there any file from which I can extract the information of the flavor I am running? – Aditya Apr 21 '14 at 15:49
  • 2
    Even if there was a way (and there almost certainly is) that doesn't guarantee the user is in that environment. You can install gnome and KDE on Ubuntu and it still be Ubuntu. – Oli Apr 21 '14 at 16:00
0

The following if will show you if you are running Unity or not:

if [[ "$(ps -ef | grep unity | grep $USER | grep -v grep)" =~ "unity" ]]; then 
    echo "I'm running Unity"; 
fi

In the same way you can check if you are running GNOME or other flavors. The important thing is what (part) name of the process you use for first grep. You must distinguish a specific process which run all the time only in the flavor about which you are interested.

1
  • I like the use of ps and grep here. However, distinguishing a specific process to apply to a specific flavor will probably be a bit difficult for the average user. – Elder Geek May 14 '14 at 20:57
0

If your aim is to make some desktop settings defaults for all users, it's much easier to let the OS do it for you, using Gsettings schema overrides. For example, create /usr/share/glib-2.0/schemas/99_my-settings.gschema.override containing your settings like this:

[com.canonical.indicator.datetime]
show-week-numbers=true

[org.gnome.desktop.calendar]
show-weekdate=true

Use Dconf Editor or CLI tools to check the correct schema (in square brackets) for each setting. You can group several settings under each schema. Finally run this to make them defaults for all users:

sudo glib-compile-schemas /usr/share/glib-2.0/schemas

This way you won't even have to run any scripts, as each desktop environment finds its new default settings when starting. Also, users will be able to personalize them without a sneaky startup script changing them back again.

Here's some more info: https://developer.gnome.org/gio/stable/glib-compile-schemas.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.