Hello I would like to parse a js file in bash containing settings in this way :
user_pref("network.proxy.socks", "127.0.0.1");
user_pref("network.proxy.socks_port", 9150);
user_pref("network.proxy.type", 1);
- if the lines do not exist, it should be created (>>append).
- if the lines are already set with those values : do nothing.
- If the lines are already set with different values, change it for values "127.0.0.1", 9150, 1
So far I can perform point 1 and 2, but I struggle on point 3. I believe it can be achieved by using bash conditionals, and 'sed' with a regex pattern. Can anyone (regex guru) help me please ?
Quick introduction to my problem :
I am writing a bash script on OS X and have socks5 listening on 127.0.0.1:9150. I want then to set those settings for Firefox by editing the prefs.js file (equivalent of url about:config). The GUI for this is Preferences/Advanced/Network/Connection Settings/Manual Proxy/Socks5.
FYI, here's my script, the missing part is ###MISSING PART### :
function sshD
{
pkill firefox #Kill existing instance(s) of Firefox
#Create HTTP Proxy via SSH Tunnel
ssh -Cc blowfish -D9150 -Nf myuser@mydomain
fxpref="$HOME/Library/Application Support/Firefox/Profiles/"; fxpref="$fxpref`ls "$fxpref" | awk 'NR==1'`/prefs.js"
test ! -f "$fxpref".backup && cp "$fxpref" "$fxpref".backup
proxypref=`cat "$fxpref" | grep proxy`
###MISSING PART###
/Applications/Firefox.app/Contents/MacOS/firefox-bin -private > /dev/null 2>&1 &
}