I have a makeself
script which I expect to be run as root; It's a desktop installer.
At the end of the script, the software which was recently installed to the filesystem tries to launch in user-space.
This works well using sudo -u $(logname) /path/to/application
(or alternately sudo -u $SUDO_USER ...
in Ubuntu 16.04) however a critical environmental variable from the user is missing:
GNOME_DESKTOP_SESSION_ID
I need GNOME_DESKTOP_SESSION_ID
because the child process belongs to Java and Java uses this environmental variable for detecting the GtkLookAndFeel.
However attempts to use sudo -i
have failed.
From some basic tests, the GNOME_DESKTOP_SESSION_ID
doesn't appear to be a natural environmental variable when this users logs in. For example, if I CTRL+ALT+F1
to a terminal, env |grep GNOME
yields nothing whereas XTerm
and gnome-terminal
both yield GNOME_DESKTOP_SESSION_ID
.
How can I get a hold of this GNOME_DESKTOP_SESSION_ID
variable from within the installer script without requiring users to pass something such as the -E
parameter to the sudo
command?
Note, although GtkLookAndFeel
is the primary look and feel for Linux, I prefer not to hard-code the export JAVA_OPTS
either, I prefer to continue to fallback onto Oracle's detection techniques for support, longevity and scalability reasons.
Update: In Ubuntu, GNOME_DESKTOP_SESSION_ID
lives in /usr/share/upstart/sessions/xsession-init.conf
initctl set-env --global GNOME_DESKTOP_SESSION_ID=this-is-deprecated
Which leads to using initctl get-env
to retrieve it. Unfortunately this does not help within a new sudo
shell, nor does any (optimistic) attempt at dbus-launch
.