Configuration and deconfiguration of proxy in system environment
#!/bin/bash
SET_PROXY=1
# method to set proxy in the system environment
function configure_proxy {
if [[ SET_PROXY != 0 ]]; then
PROXY_HOSTNAME=""
PROXY_PORT=""
PROXY_PROTOCOL="http"
PROXY_CONNECTION_URL="${PROXY_PROTOCOL}://${PROXY_HOSTNAME}:${PROXY_PORT}"
# bash proxy configuration
export http_proxy="${PROXY_CONNECTION_URL}"
export https_proxy="${PROXY_CONNECTION_URL}"
export ftp_proxy="${PROXY_CONNECTION_URL}"
# npm proxy configuration
if [[ ! -z $(which npm) ]]; then
npm config set proxy "${PROXY_CONNECTION_URL}"
npm config set https-proxy "${PROXY_CONNECTION_URL}"
fi
# git proxy configuration
if [[ ! -z $(which git) ]]; then
git config --global http.proxy "${PROXY_CONNECTION_URL}"
fi
fi
}
# method to deconfigure proxy in system environment
function deconfigure_proxy {
SET_PROXY=0
unset http_proxy
unset https_proxy
unset ftp_proxy
if [[ ! -z $(which npm) ]]; then
npm config delete proxy
npm config delete https-proxy
fi
if [[ ! -z $(which git) ]]; then
git config --global --unset http.proxy
fi
}
# deconfigure_proxy
configure_proxy