System-wide proxies in ChaletOS, Ubuntu Studio, Xubuntu and XFCE must be set via environment variables

View previous topic View next topic Go down

System-wide proxies in ChaletOS, Ubuntu Studio, Xubuntu and XFCE must be set via environment variables

Post by xyis1 on Tue May 26, 2015 12:24 pm

System-wide proxies in ChaletOS, Ubuntu Studio, Xubuntu and XFCE must be set via environment variables

Scripts for turning Proxy server on/off:

Disclaimer:: Before proceeding, note that I have tried this on Lubuntu 14.04 and it is IMPORTANT that before you run the mentioned scripts, the file /etc/environment should have only one line in it i.e. '$PATH...' and there should be nothing else in the file, else you might need to modify the script's code. These scripts set and unset the proxy as described above, but they rely upon file truncation and file appending to change /etc/environment and /etc/apt/apt.conf.d/95proxies files. So make sure that:

1) /etc/environment contains only one line i.e. '$PATH:...'. And nothing else.

2) The file /etc/apt/apt.conf.d/95proxies does not exist or does not have anything important in it.

So! If you want to automate the process of turning proxy on and off without having to type allot. you can make two executable shell scripts proxyon.sh and proxyoff.sh as:

proxyon.sh:

if [ $(id -u) -ne 0 ]; then
echo "This script must be run as root";
exit 1;
fi

if [ $# -eq 2 ]
then

gsettings set org.gnome.system.proxy mode 'manual' ;
gsettings set org.gnome.system.proxy.http host '$1';
gsettings set org.gnome.system.proxy.http port $2;


grep PATH /etc/environment > lol.t;
printf \
"http_proxy=http://$1:$2/\n\
https_proxy=http://$1:$2/\n\
ftp_proxy=http://$1:$2/\n\
no_proxy=\"localhost,127.0.0.1,localaddress,.localdomain.com\"\n\
HTTP_PROXY=http://$1:$2/\n\
HTTPS_PROXY=http://$1:$2/\n\
FTP_PROXY=http://$1:$2/\n\
NO_PROXY=\"localhost,127.0.0.1,localaddress,.localdomain.com\"\n" >> lol.t;

cat lol.t > /etc/environment;


printf \
"Acquire::http::proxy \"http://$1:$2/\";\n\
Acquire::ftp::proxy \"ftp://$1:$2/\";\n\
Acquire::https::proxy \"https://$1:$2/\";\n" > /etc/apt/apt.conf.d/95proxies;

rm -rf lol.t;

else

printf "Usage $0 \n";

fi

proxyoff.sh:

if [ $(id -u) -ne 0 ]; then
   echo "This script must be run as root";
   exit 1;
fi

gsettings set org.gnome.system.proxy mode 'none' ;

grep PATH /etc/environment > lol.t;
cat lol.t > /etc/environment;

printf "" > /etc/apt/apt.conf.d/95proxies;

rm -rf lol.t;

How to use: Once you have made these scripts, make them executable, you may keep them anywhere you like. To turn on proxy all you have to do is go to the directory containing the 'proxyon.sh' script and then you need to type sudo ./proxyon.sh {host} {port}. As an example consider this:

$: sudo ./proxyon.sh 10.2.20.17 8080
OR
$: sudo ./proxyon.sh myproxy.server.com 8080
Where '10.2.20.17' is the proxy server's IP - you can also type something like myproxy.server.com - and '8080' is the port. After that just log out and login to your account, to make sure that everything is set. You can start using the internet or whatever then. And when you want to turn the proxy off, go to the directory containing 'proxyoff.sh' and type:

$: sudo ./proxyoff.sh
This will unset all of your proxies. Now logout and login again to switch to normal mode.

___________________________________________________________________________________________________________________________________
Stay in touch with reality. All quotes are nothing but frame of mind.
I found the truth. The problem is health. The solution is health.
avatar
xyis1

Posts : 56
Join date : 2015-05-04
Location : India

http://xyis1.blogspot.in/

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum