Created
November 12, 2014 09:50
-
-
Save ssh0/ea7ab9fa37d91a7b1971 to your computer and use it in GitHub Desktop.
proxy_toggle.sh: toggle setting for proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
HTTP_PROXY_HOST=www-proxy.waseda.jp | |
HTTP_PROXY_PORT=8080 | |
HTTPS_PROXY_HOST=www-proxy.waseda.jp | |
HTTPS_PROXY_PORT=8080 | |
shellrc=$HOME/.zshrc # .bashrc | |
if [ $# = 0 ]; then | |
echo "Error: no args" | |
exit 1 | |
else | |
if [ $1 = "on" ]; then | |
sudo sed -i.bak '/http[s]::proxy/Id' /etc/apt/apt.conf | |
sudo tee -a /etc/apt/apt.conf <<EOF | |
Acquire::http::proxy "http://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT/"; | |
Acquire::https::proxy "https://$HTTPS_PROXY_HOST:$HTTPS_PROXY_PORT/"; | |
EOF | |
sudo sed -i.bak '/http[s]_proxy/Id' /etc/environment | |
sudo tee -a /etc/environment <<EOF | |
http_proxy="http://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT/" | |
https_proxy="https://$HTTPS_PROXY_HOST:$HTTPS_PROXY_PORT/" | |
EOF | |
sed -i.bak '/http_proxy/Id' $shellrc | |
sed -i.bak '/https_proxy/Id' $shellrc | |
tee -a $shellrc <<EOF | |
export http_proxy="http://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT/" | |
export https_proxy="https://$HTTPS_PROXY_HOST:$HTTPS_PROXY_PORT/" | |
EOF | |
else | |
if [ $1 = "off" ]; then | |
sudo sed -i.bak "/http::proxy/Id" /etc/apt/apt.conf | |
sudo sed -i.bak "/https::proxy/Id" /etc/apt/apt.conf | |
sudo sed -i.bak "/http_proxy/Id" /etc/environment | |
sudo sed -i.bak "/https_proxy/Id" /etc/environment | |
sed -i.bak '/http_proxy/Id' $shellrc | |
sed -i.bak '/https_proxy/Id' $shellrc | |
tee -a $shellrc <<EOF | |
export http_proxy= | |
export https_proxy= | |
EOF | |
else | |
echo "arg: 'on' or 'off'" | |
exit 1 | |
fi | |
fi | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment