Skip to content

Instantly share code, notes, and snippets.

@Aqours
Created November 2, 2019 01:01
Show Gist options
  • Save Aqours/fcf560dd71bb0e22d433ebd96b27d165 to your computer and use it in GitHub Desktop.
Save Aqours/fcf560dd71bb0e22d433ebd96b27d165 to your computer and use it in GitHub Desktop.
bash_proxy_function.sh
# configure proxy for git while on corporate network
# From https://gist.github.com/garystafford/8196920
function proxy_on(){
# assumes $USERDOMAIN, $USERNAME, $USERDNSDOMAIN
# are existing Windows system-level environment variables
# assumes $PASSWORD, $PROXY_SERVER, $PROXY_PORT
# are existing Windows current user-level environment variables (your user)
local GENERAL_PROXY="socks5://127.0.0.1:1081"
# environment variables are UPPERCASE even in git bash
export http_proxy=$GENERAL_PROXY
export https_proxy=$GENERAL_PROXY
export ftp_proxy=$GENERAL_PROXY
export socks_proxy=$GENERAL_PROXY
export no_proxy="localhost,127.0.0.1,$USERDNSDOMAIN"
# Update git and npm to use the proxy
# git config --global http.proxy $GENERAL_PROXY
# git config --system http.sslcainfo /bin/curl-ca-bundle.crt
# git config --global http.sslcainfo /bin/curl-ca-bundle.crt
# npm config set proxy $GENERAL_PROXY
# npm config set https-proxy $GENERAL_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 _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" "FTP_PROXY" "SOCKS_PROXY" \
"NO_PROXY" "GIT_CURL_VERBOSE" "GIT_SSL_NO_VERIFY" \
"http_proxy" "https_proxy" "ftp_proxy" "socks_proxy" \
"no_proxy" \
)
for i in "${variables[@]}"
do
unset $i
done
env | grep -e _proxy -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