jcampanaaxa
11/26/2015 - 8:30 AM

Setear/Chequear proxies OSX

Setear/Chequear proxies OSX

unsetProxyFunction(){
	unset http_proxy
	unset https_proxy
	unset HTTP_PROXY
	unset HTTPS_PROXY
	unset no_proxy
}
setSystemProxyFunction(){
	sudo networksetup -setwebproxy ethernet $1 $2
	sudo networksetup -setsecurewebproxy ethernet $1 $2
}

setProxyFunction() {
	export http_proxy=$1:$2 
	export https_proxy=$http_proxy
	export HTTP_PROXY=$http_proxy
	export HTTPS_PROXY=$http_proxy
	export no_proxy='127.0.0.1, localhost, 0.0.0.0'

	git config --global http.proxy http://$http_proxy
	git config --global https.proxy http://$http_proxy
	npm config set proxy http://$http_proxy
	npm config set https-proxy http://$http_proxy	
}

setAllProxyFunction(){
	echo Setting up proxies to $1:$2 ...

	setProxyFunction $1 $2
	setSystemProxyFunction $1 $2

	echo Done! 
	echo You can check them by executing checkproxy 
}

checkProxyFunction() {
	echo HTTP System proxy:
	echo ==================
	sudo networksetup -getwebproxy ethernet
	echo
	echo HTTPS System proxy:
	echo ===================
	sudo networksetup -getsecurewebproxy ethernet
	echo
	echo ENV:
	echo ====
	env | grep proxy -i
	echo
	echo NPM:
	echo ====
	npm config list | grep proxy
	echo
	echo GIT:
	echo ====
	git config --list | grep proxy
}

alias checkproxy=checkProxyFunction
alias setallproxy=setAllProxyFunction
alias setproxy=setProxyFunction
alias removeproxy=unsetProxyFunction