10

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.

Aditya
  • 13,616

5 Answers5

14

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)
cshubhamrao
  • 4,285
  • 2
  • 21
  • 30
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.

Roman Raguet
  • 9,613
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.

Oli
  • 299,380
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

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.

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407