Thursday, September 27, 2012

Easily Enable/Disable SVN Proxy

To configure SVN proxy settings you need to edit the servers file in svn. In Linux, this can be found at ~/.subversion/servers.

Open this file in a text editor and change the settings as following by including the proxy host and port under the [global] section. Uncomment those two lines and remove any leading spaces.

[global]
# http-proxy-exceptions = *.exception.com, www.internal-site.org
http-proxy-host = proxy.host.com
http-proxy-port = 1234

# http-proxy-username = defaultusername
# http-proxy-password = defaultpassword
# http-compression = no
# http-auth-types = basic;digest;negotiate
# No http-timeout, so just use the builtin default.
# No neon-debug-mask, so neon debugging is disabled.
# ssl-authority-files = /path/to/CAcert.pem;/path/to/CAcert2.pem


If you get any errors, make sure that there are no spaces at the start of those lines.

For most of us, proxy is used only at school/university/work. Everywhere else you don't use proxy. So Most of the time you need configure the settings once. But you will have to enable/disable proxy every time. That means opening this file in an editor and commenting/uncommenting manually every single time.

After getting fed up with doing this every time I move to and from university, I came up with a better way to do this.


#!/bin/bash
#
# ------------------------------------------------------
#  SVN proxy toggle script
#  nufailm.blogspot.com
# ------------------------------------------------------
#
L1='144'
L2='145'
sed -i "$L1,$L2 { /^#/ {
   s/^#//
   w /dev/stdout
   b end
   }
   s/^/#/
   w /dev/stdout
}
:end " ~/.subversion/servers 

You can download the above file from here. Each time above script is run, it comments or uncomments the two lines given by L1 and L2 depending on whether they are already uncommented or commented.

  • First download and save the above script.
  • Then edit the two variables L1 and L2 to contain the correct line numbers of the servers file that needs to be changed.
  • Edit your servers file as mentioned in the beginning of the post using your proxy settings. Uncomment the two lines and make sure there are no leading spaces.
  • Open your .bashrc file located at ~/.bashrc and add the following to the end of the file to create an alias to run this script. Edit the location of the script file as necessary.

# svn proxy toggle script alias
alias svnproxy='sh ~/Documents/toggleSvnProxy'


  • Now open a terminal and run the command svnproxy. It will display the two changed lines so you can see the settings used and whether it's commented or not.


As shown in the screen shot, running the command has disabled proxy. If you run the command again, it will uncomment the lines and enable proxy. So each time you need to enable/disable svn proxy, you only have to run the command svnproxy.

2 comments:

Julia David said...
This comment has been removed by a blog administrator.
Sylvester Stallone said...
This comment has been removed by a blog administrator.

Post a Comment