Created
November 2, 2017 12:51
-
-
Save yogeek/7f0ea49f747047544d261347e824d28c to your computer and use it in GitHub Desktop.
Automatic Set / Unset PROXY on centOS
This file contains hidden or 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
# /etc/sysconfig/docker | |
HTTP_PROXY=http://10.31.255.65:8080 | |
NO_PROXY=localhost,127.0.0.1 | |
http_proxy=http://10.31.255.65:8080 | |
no_proxy=localhost,127.0.0.1 | |
This file contains hidden or 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
# /etc/yum.conf.withproxy | |
[...] | |
proxy=http://10.31.255.65:8080 | |
proxy_username= | |
proxy_password= |
This file contains hidden or 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
# /etc/systemd/system/docker.service.d/http-proxy.conf.proxy | |
[Service] | |
EnvironmentFile=/etc/sysconfig/docker |
This file contains hidden or 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/bash | |
#---------------------------------------------------------------------------------- | |
# setProxy.sh | |
# Script to activate HTTP proxy for the system, docker and yum. | |
#---------------------------------------------------------------------------------- | |
echo "Enabling proxy env..." | |
export http_proxy=http://XXX.XXX.XXX.XXX | |
export https_proxy=$http_proxy | |
export HTTP_PROXY=$http_proxy | |
export HTTPS_PROXY=$HTTP_PROXY | |
isDockerProxy="$(sudo systemctl show docker.service | grep EnvironmentFile)" | |
# if variable empty, docker proxy is not configured : add it ! | |
if [[ -z $isDockerProxy ]] | |
then | |
echo "Enabling proxy for Docker service..." | |
sudo cp /etc/systemd/system/docker.service.d/http-proxy.conf.proxy /etc/systemd/system/docker.service.d/http-proxy.conf | |
echo "Reloading Docker service..." | |
sudo systemctl daemon-reload | |
sudo systemctl stop docker.service | |
sudo systemctl start docker.service | |
fi | |
isYumProxy="$(diff /etc/yum.conf /etc/yum.conf.withoutproxy)" | |
# if variable empty, yum proxy is not configured : add it ! | |
if [[ -z $isYumProxy ]] | |
then | |
echo "Enabling proxy for YUM..." | |
sudo cp /etc/yum.conf.withproxy /etc/yum.conf | |
fi | |
echo "Proxy set !" |
This file contains hidden or 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/bash | |
#---------------------------------------------------------------------------------- | |
# unsetProxy.sh | |
# Script to desactivate Thales proxy for the system, docker and yum. | |
#---------------------------------------------------------------------------------- | |
echo "Disabling proxy env..." | |
unset http_proxy | |
unset https_proxy | |
unset HTTP_PROXY | |
unset HTTPS_PROXY | |
isDockerProxy="$(sudo systemctl show docker.service | grep EnvironmentFile)" | |
# if variable not empty, docker proxy is configured : supress it ! | |
if [[ ! -z $isDockerProxy ]] | |
then | |
echo "Disabling proxy for Docker service..." | |
sudo rm -f /etc/systemd/system/docker.service.d/http-proxy.conf | |
echo "Reloading Docker service..." | |
sudo systemctl daemon-reload | |
sudo systemctl stop docker.service | |
sudo systemctl start docker.service | |
fi | |
isYumProxy="$(diff /etc/yum.conf /etc/yum.conf.withoutproxy)" | |
# if variable not empty, yum proxy is configured : suppress it ! | |
if [[ ! -z $isYumProxy ]] | |
then | |
echo "Disabling proxy for YUM..." | |
sudo cp /etc/yum.conf.withoutproxy /etc/yum.conf | |
fi | |
echo "Proxy unset !" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment