Skip to content

Instantly share code, notes, and snippets.

@washcycle
Last active April 8, 2018 02:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save washcycle/85a2ac501f7ddb102f7dce876f879693 to your computer and use it in GitHub Desktop.
Save washcycle/85a2ac501f7ddb102f7dce876f879693 to your computer and use it in GitHub Desktop.
Corporate Proxy Bash Script
# configure proxy for git while on corporate network
# From https://gist.github.com/garystafford/8196920
function proxy_on(){
# assumes $USERDOMAIN, $USERDNSDOMAIN, $CA_PATH
# are existing Windows system-level environment variables
# assumes $PROXY_SERVER, $PROXY_PORT
# are existing Windows current user-level environment variables (your user)
# environment variables are UPPERCASE even in git bash
export HTTP_PROXY="http://$PROXY_SERVER:$PROXY_PORT"
export HTTPS_PROXY=$HTTP_PROXY
export http_proxy=$HTTP_PROXY
export https_proxy=$HTTP_PROXY
export FTP_PROXY=$HTTP_PROXY
export SOCKS_PROXY=$HTTP_PROXY
export CA_BUNDLE=$CA_PATH
export AWS_CA_BUNDLE=$CA_PATH
export CURL_CA_BUNDLE=$CA_PATH
export NO_PROXY="localhost,127.0.0.1,$USERDNSDOMAIN"
# Update git and npm to use the proxy
git config --global http.proxy $HTTP_PROXY
#git config --system http.sslcainfo $CA_PATH need root to do this....
git config --global http.sslcainfo $CA_PATH
# npm config set proxy $HTTP_PROXY
# npm config set https-proxy $HTTP_PROXY
# npm config set strict-ssl false
# npm config set registry "http://registry.npmjs.org/"
# optional for debugging
export GIT_CURL_VERBOSE=1
# optional Self Signed SSL certs and
# internal CA certificate in an corporate environment
export GIT_SSL_NO_VERIFY=1
env | grep -e _PROXY -e GIT_ | sort
# echo -e "\nProxy-related environment variables set."
# clear
}
# Enable proxy settings immediately
proxy_on
# Disable proxy settings
function proxy_off(){
variables=( \
"HTTP_PROXY" "HTTPS_PROXY" "http_proxy" "https_proxy" "FTP_PROXY" "SOCKS_PROXY" \
"NO_PROXY" "GIT_CURL_VERBOSE" "GIT_SSL_NO_VERIFY" \
"CA_BUNDLE" "AWS_CA_BUNDLE" "CURL_CA_BUNDLE" \
)
for i in "${variables[@]}"
do
unset $i
done
env | grep -e _PROXY -e GIT_ | sort
echo -e "\nProxy-related environment variables removed."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment