3

I use a proxy server settings at work but when i get home, my network connection uses no proxy settings.

every time i get home and use the proxy settings under settings->networks->Network Proxy to set to "none", the file /etc/apt/apt.conf gets cleared and the following day in the morning i have to edit the file and type in the command again, or at least copy paste from a backup file.

How can i avoid this situation, its tiring, how can i make the proxy settings gui write to this file for apt-get and software center to work when i set proxy under network settings?

2 Answers 2

1

In Ubuntu 12.04 LTS:

When you come home, try not applying no-proxy system-wide. This doesn't edit the apt.conf file, yet software center uses no proxy. Works for me, dunno how.

1

You could put the proxy configuration in /etc/apt/apt.conf.d/70proxy.conf, create this file and put your proxy config in there.

Acquire::http::Proxy "http://whatever:port";

Then when you get home, you can just rename that file. Note that only files ending in .conf (or files with no extension) will be considered by apt, so you can potentially just rename it to /etc/apt/apt.conf.d/70proxy.disabled and it will not be considered.

You can then automate it with stuff like this, you can create a .bash_aliases file in your home directory and put this in it:

export APT_PROXY_BASE=/etc/apt/apt.conf.d/70proxy
alias enable-proxy="[ -f ${APT_PROXY_BASE}.disabled ] && sudo mv ${APT_PROXY_BASE}.disabled ${APT_PROXY_BASE}.conf"
alias disable-proxy="[ -f ${APT_PROXY_BASE}.conf ] && sudo mv ${APT_PROXY_BASE}.conf ${APT_PROXY_BASE}.disabled"

To enable the proxy, just issue

enable-proxy

and to disable:

disable-proxy

Beware, I didn't test it :) it's just meant to get you on the right track.

8
  • thanks for pointing me on the right track. i thought Aliases are used to rename commands, and sometimes to include options, and the general format is alias mycommand='UNIXcommand' if so then i have problems understanding the ones you gave for enable-proxy and disable-proxy, i dont see an "=" sign, instead it's a whitespace and the commands aren't in quotation. i also dont quite understand what -f option is used for here. If you could please elaborate a little more, i'd appreciate a lot. Apr 19, 2012 at 13:35
  • Like I said, I didn't test it :) yes, I'm missing the '=' sign. I fixed it now.
    – roadmr
    Apr 19, 2012 at 13:52
  • the [ -f $filename ] construct returns a "true" or success value if the named file exists. I'm using this to avoid errors if you try to move a non-existing file; this could happen if you issued 'disable-proxy' twice in a row. So if the file does not exist, the alias will not even attempt to move it.
    – roadmr
    Apr 19, 2012 at 13:55
  • yeah, thats much better, didnt work though, logged out, logged back in and in terminal, disable-proxy or enable-proxy are not found. I ma thinking setting this up for at environment level would make sure wen i open a new terminal, its available. dont know how to do that though. FYI, it works if i do the commands in a terminal session. Apr 19, 2012 at 14:44
  • Apologies again, I updated with the correct location to put the aliases (.bash_aliases).
    – roadmr
    Apr 19, 2012 at 15:18

You must log in to answer this question.

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