Skip navigation.

Sign up | Lost password? | Help

Open Life

Opendocuments, Web Office, Office suites

Disabling the Proxy on my Opera from BASH

, , , ,

Usually I dont blog other than OpenOffice.org but having this blog on an Opera community and this been a Opera hack, I think it deserved the attention.

So I don't know much of bash script and I am learning so doing a simple script that will allow me to get rid of some of Opera annoyances --- or GUI annoyances really.

The Problem
My damn employer network force us to use a Proxy everytime we want to access he interweb. So every morning I come in the office I need to run Opera and quickly get the Alt-P keystroke go to Advanced > Network > Proxy Servers and check the HTTP/FTP/HTTPS checkbox to enable the proxy in all. This is quite irritating.

The Research
Asking on the forum I remember that most of this preferences are ASCII parameters in .ini files. So I asked on the forum looking for the right .ini until I found it under ~/.opera/opera6.ini

Did a less opera6.ini |grep Proxy gave me what I was looking for:
[Proxy]
Use WAIS=0
Use Automatic Proxy Configuration=0
HTTP server=internet.ps.net:80
HTTPS server=internet.ps.net:80
Gopher server
WAIS server
Automatic Proxy Configuration URL=
No Proxy Servers=
No Proxy Servers Check=0
FTP server=internet.ps.net:80
Use GOPHER=0
Enable HTTP 1.1 for proxy=0
Use HTTP=1
Use HTTPS=1
Use FTP=1


The last 3 is what I was looking for, so it seems the script should not need any complex XML parser/Regular expression script to a complish this. So instead I used vim command line interface with bash. I end up with vim + bash and some advanced flags will let me be able to perform:
  • Open the file
  • Position on the exact line
  • do a search and replace from 1 to 0 and viceversa
  • Save and Quit


VIM is a very popular editor so a friend suggest me this external flags, specifically the -c flag that stand for command.


The Solution
I finally got something like this:
 vim -c "601" -c "s/1/0/" ~/.opera/opera6.ini


This enabled me to do a search and replace the 0 by 1, but now I need the opposite but instead of having another 1 liner I tried to just use an if... else and have it run.

The code end up like this:
if [ "$1" = "-e" ]; then
        vi -c "610" -c "s/1/0/" 
           -c "611" -c "s/1/0/" 
           -c "612" -c "s/1/0/" 
           -c "wq" ~/.opera/opera6.ini;
   else
        vi -c "610" -c "s/0/1/" 
           -c "611" -c "s/0/1/" 
           -c "612" -c "s/0/1/" 
           -c "wq" ~/.opera/opera6.ini;
   fi


I finally got this script stored on a command I called unproxy stored at /usr/local/bin with everything hardcoding and no 'intelligence on the script'. Ths mean that it doesnt validate that there is indeed a proxy, it's just a dumb command.

using the iff I can switch it on or off depending on the flag I show it:
unproxy -e (-e for enable) 

unproxy 

In the end the configuration profiles changed to just 0:
Use HTTP=0
Use HTTPS=0
Use FTP=0

Got Interviewed at TLLTSMissing a fallen soldier

Comments

netstrider 10. May 2007, 19:57

This might actually come in handy for my brother...at work

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.

November 2009
S M T W T F S
October 2009December 2009
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30