2

Is there a way to set a dconf key by command line, without logging into X?
I'd like to use this from Puppet.

If I try (from SSH, as the normal user) a simple

dconf write /desktop/gnome/remote-access/enabled true

I get

error: Command line `dbus-launch --autolaunch=e4d2b270bd8471627460e57c000007f1 --binary-syntax --close-stderr' exited with non-zero exit status 1:
Autolaunch error: X11 initialization failed.\n

While if I try

DISPLAY=:0 dconf write /desktop/gnome/remote-access/enabled true

I get

error: Command line `dbus-launch --autolaunch=e4d2b270bd8471627460e57c000007f1 --binary-syntax --close-stderr' exited with non-zero exit status 1:
Invalid MIT-MAGIC-COOKIE-1 keyInvalid MIT-MAGIC-COOKIE-1 keyAutolaunch error: X11 initialization failed.\n

If I remove $HOME/.Xauthority

error: Command line `dbus-launch --autolaunch=e4d2b270bd8471627460e57c000007f1 --binary-syntax --close-stderr' exited with non-zero exit status 1:
No protocol specified\nNo protocol specified\nAutolaunch error: X11 initialization failed.\n

I'm testing on Xubuntu 12.04

(My question is similar to this one but in that case the user is logged in)

2
  • keep in mind that puppet runs as root
    – jrg
    Oct 4, 2012 at 10:12
  • Well I can tell Puppet to force the user but I have to get it working from SSH first, I think
    – Joril
    Oct 4, 2012 at 10:13

5 Answers 5

3

Joril, thanks for providing your solution! I would like to add one comment in case people have the problem that I just did: when you use this type definition to set string values, you need to pass in some extra quotes and escape characters. For instance, I wanted to set my color scheme in gedit, so I tried this:

dconf::key {'/org/gnome/gedit/preferences/editor/scheme':
    value => 'solarized_dark',
}

but it didn't work. What I needed to do was this:

dconf::key {'/org/gnome/gedit/preferences/editor/scheme':
    value => "\\\"solarized_dark\\\"",
}

Maybe someone could do that in a simpler way, or build it into the function you provided? Anyway, it works for me now so I'm leaving it alone.

Note that passing in booleans works fine without that extra nonsense, e.g.:

dconf::key {'/org/gnome/gedit/preferences/editor/auto-indent': 
    value => 'true',  
}

works correctly, and I'm assuming that numerical values can probably be set without extra escape characters as well.

2

I managed to solve the problem:

define dconf::key($value) {
    exec { "Setting dconf $title":
        path => "/bin:/usr/bin",
        command => "/bin/sh -c 'eval `dbus-launch --auto-syntax` && dconf write $title $value'",
        user => "user_name",
        group => "user_name",
        unless => "dconf read $title | grep $value",
        require => Package["dconf-tools"]
    }
}
1

I have created a puppet module for that, based on Joril's answer:

https://github.com/sitaktif/puppet-dconf

As user153385 mentions, it needs escaping because of the use of sh. Examples with bool, string and array are given in the README.md of the repository.

1

I use the similar, but slightly simplified defined type to solve this problem:

define dconf ($key = $title, $value) {
    exec { "dbus-run-session -- dconf write \"${key}\" \"${value}\"":
        onlyif  => "test \"${value}\" != \"`dbus-run-session -- dconf read \"${key}\"`\"",
    }
}

The above doesn't include the ability to be run by a particular user (although that could easily be added). However, it does use a different invocation of dbus-run-session that doesn't leave extra dbus daemons running after the command completes and it removes the need for a separate sh -c layer (although this benefit could also be achieved with dbus-launch <command>). This eliminates the painful multiple-layers of escaping mentioned by some of the other answers.

Some examples that use the above:

# swap capslock and escape
dconf { '/org/gnome/desktop/input-sources/xkb-options':
    value   => '[\'caps:swapescape\']',
}

# stop ibus from swallowing ctrl+space
dconf { '/desktop/ibus/general/hotkey/triggers':
    value   => '@as []',
}
1
  • 1
    Thanks, very much! This works, dbus-launch does not.
    – Alek_A
    May 6, 2021 at 15:20
0

I found a temporary solution:

  1. Login into the remote system, then connect via ssh terminal to the remote system and export display via: export DISPLAY=:0.

  2. Now you can use "dconf" as usual via ssh terminal. But the gconftool-2 doesn't work now.

Do you have a better solution working for dconf without exporting display ?

1
  • 1
    Is something wrong with the accepted answer?
    – Joril
    Feb 20, 2014 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .