«CentOS 开关代理的脚本»
by pluvet on Jan 16, 2020
PROXY_SERVER="192.168.0.104"
PROXY_PORT="1080"
# 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)

   # 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_SERVER:$PROXY_PORT"
   export https_proxy=$http_proxy
   export FTP_PROXY=$HTTP_PROXY
   export SOCKS_PROXY=$HTTP_PROXY

   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 --global https.proxy $HTTP_PROXY
   # 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" "FTP_PROXY" "SOCKS_PROXY" \
      "NO_PROXY" "GIT_CURL_VERBOSE" "GIT_SSL_NO_VERIFY" \
      "http_proxy" "https_proxy"
   )

   for i in "${variables[@]}"
   do
      unset $i
   done

   env | grep -e _PROXY -e GIT_ | sort
   echo -e "\nProxy-related environment variables removed."
}

添加新评论