Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm running Ubuntu-Studio 12.10 using GNOME-3, and I'm trying to set up a bash script in /etc/network/if-up.d to auto-configure my proxy settings based on the SSID of the network I'm connected to. I cannot get gsettings to work automatically, using any of the following:

gsettings set org.gnome.system.proxy mode "manual"
sudo -u blaine gsettings set org.gnome.system.proxy mode "manual"
su blaine -c 'gsettings set org.gnome.system.proxy mode "manual"'

Furthermore, I'd like the script to change the environment variables http_proxy, https_proxy and so forth so that things like Wine would recognise them without having to log out and back in, and five days of googling tells me this is impossible.

Except - I know it can be done. The "Apply System-Wide" button in Unity does all this without having to re-log. Some further digging revealed this article that suggest the button accesses com.ubuntu.systemservice.setProxy, which is presumably part of the ubuntu-system-service package.

Is it possible to use ubuntu-system-service to set a system-wide proxy via bash, the terminal, or similar?

share|improve this question
add comment

1 Answer 1

In case anyone is still looking for a solution, here is what I've found. Ubuntu exposes a DBus service via the ubuntu-system-service package, but I'm not familiar with DBus.

However, inspecting the source code (ain't Open Source great?), the setProxy action does 2 things:

  1. Modify the system-wide environment
  2. Modify the proxy settings used by APT

For the first case, the file at /etc/environment is modified. The second case is a little more complicated - files in /etc/apt/apt.conf.d are scanned for lines matching Acquire::::Proxy , where the values are replaced. If there are no matching lines, then a proxy line (like the above) is added to each APT conf file.

The relevant files are found in UbuntuSystemService/backend.py (~line 209 @ version 0.2.5).

Answering your question, you can either make the same changes that ubuntu-system-service does, or attempt to figure it out using DBus:

dbus-send --system --print-reply --dest=com.ubuntu.SystemService --type=method_call / com.ubuntu.SystemService.set_proxy string:'http' string:'127.0.0.1:8080'

For some reason, I keep getting False as a reply on this one, but you may be able to figure this out.

share|improve this answer
    
The command works if you launch it from the terminal. It appears a prompt asking you your password to change the proxy. You must make sure that you are running in the same environment as your user, ie. with the DBUS_SESSION_BUS_ADDRESS file, etc. –  Braiam Nov 13 '13 at 21:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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