Skip to content

Instantly share code, notes, and snippets.

@burnsra
Last active June 16, 2016 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burnsra/4285b72fdf1e3eb5c65eb9ac78409af3 to your computer and use it in GitHub Desktop.
Save burnsra/4285b72fdf1e3eb5c65eb9ac78409af3 to your computer and use it in GitHub Desktop.
Proxy definition script
#!/bin/sh
proxyDomain="127.0.0.1"
proxyPort="3128"
proxyAuthenticated="off"
proxyEnabled="yes"
if [ "$1" != "" ]; then
proxyDomain=$1
fi
if [ "$2" != "" ]; then
proxyPort=$2
fi
# Detects all network hardware & creates services for all installed network hardware
sudo /usr/sbin/networksetup -detectnewhardware
IFS=$'\n'
#Loops through the list of network services
for i in $(/usr/sbin/networksetup -listallnetworkservices | tail +2 );
do
# Get a list of all services containing 'Ethernet' or 'Wi-Fi'
# If your service names are different to the below, you'll need to change the criteria
if [[ "$i" =~ 'Ethernet' ]] || [[ "$i" =~ 'Wi-Fi' ]] ; then
if [ "$1" == "disable" ]; then
sudo /usr/sbin/networksetup -setwebproxystate "$i" off
sudo /usr/sbin/networksetup -setsecurewebproxystate "$i" off
echo "Web proxy disabled for $i"
break
fi
proxyDomainLocal=`/usr/sbin/networksetup -getwebproxy "$i" | tail -n +2 | head -n 1 | cut -d':' -f2 | xargs`
proxyPortLocal=`/usr/sbin/networksetup -getwebproxy "$i" | tail -n +3 | head -n 1 | cut -d':' -f2 | xargs`
proxyAuthenticatedLocal=`/usr/sbin/networksetup -getwebproxy "$i" | tail -n +4 | head -n 1 | cut -d':' -f2 | xargs`
echo "$i previous proxy set to $proxyDomainLocal:$proxyPortLocal"
sudo /usr/sbin/networksetup -setwebproxy "$i" $proxyDomain $proxyPort $proxyAuthenticated
sudo /usr/sbin/networksetup -setsecurewebproxy "$i" $proxyDomain $proxyPort $proxyAuthenticated
proxyDomainLocal=`/usr/sbin/networksetup -getwebproxy "$i" | tail -n +2 | head -n 1 | cut -d':' -f2 | xargs`
proxyPortLocal=`/usr/sbin/networksetup -getwebproxy "$i" | tail -n +3 | head -n 1 | cut -d':' -f2 | xargs`
proxyAuthenticatedLocal=`/usr/sbin/networksetup -getwebproxy "$i" | tail -n +4 | head -n 1 | cut -d':' -f2 | xargs`
echo "$i current proxy set to $proxyDomainLocal:$proxyPortLocal"
sudo /usr/sbin/networksetup -setwebproxystate "$i" on
sudo /usr/sbin/networksetup -setsecurewebproxystate "$i" on
echo "Web proxy enabled for $i"
fi
done
export http_proxy=http://$proxyDomain:$proxyPort
export https_proxy=http://$proxyDomain:$proxyPort
export no_proxy=localhost,127.0.0.1,$proxyDomain,
export HTTP_PROXY=http://$proxyDomain:$proxyPort
export HTTPS_PROXY=http://$proxyDomain:$proxyPort
export NO_PROXY=localhost,127.0.0.1,$proxyDomain,
if [ "$1" == "disable" ]; then
if [ -f ~/.apmrc ]; then
rm ~/.apmrc
fi
if [ -f ~/.curlrc ]; then
rm ~/.curlrc
fi
if [ -f ~/.gemrc ]; then
rm ~/.gemrc
fi
if [ -f ~/.gradle/gradle.properties ]; then
rm ~/.gradle/gradle.properties
fi
if [ -f ~/.m2/settings.xml ]; then
rm ~/.m2/settings.xml
fi
if [ -f ~/.wgetrc ]; then
rm ~/.wgetrc
fi
if [ -f ~/.zprofile ]; then
rm ~/.zprofile
fi
git config --global http.proxy ""
git config --global https.proxy ""
unset http_proxy
unset https_proxy
unset no_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset NO_PROXY
exit
fi
echo "http-proxy=http://$proxyDomain:$proxyPort" > ~/.apmrc
echo "https-proxy=http://$proxyDomain:$proxyPort" >> ~/.apmrc
echo "strict-ssl=false" >> ~/.apmrc
echo "proxy=http://$proxyDomain:$proxyPort" > ~/.curlrc
echo "---" > ~/.gemrc
echo "gem: --bin=/usr/local/bin --no-ri --no-rdoc --http-proxy=http://$proxyDomain:$proxyPort --https-proxy=http://$proxyDomain:$proxyPort" >> ~/.gemrc
if [ ! -d ~/.gradle ]; then
mkdir ~/.gradle
fi
echo "org.gradle.daemon=true" > ~/.gradle/gradle.properties
echo "systemProp.http.proxyHost=$proxyDomain" >> ~/.gradle/gradle.properties
echo "systemProp.http.proxyPort=$proxyPort" >> ~/.gradle/gradle.properties
echo "systemProp.https.proxyHost=$proxyDomain" >> ~/.gradle/gradle.properties
echo "systemProp.https.proxyPort=$proxyPort" >> ~/.gradle/gradle.properties
if [ ! -d ~/.m2 ]; then
mkdir ~/.m2
fi
echo "<settings>" > ~/.m2/settings.xml
echo "<proxies>" >> ~/.m2/settings.xml
echo "<proxy>" >> ~/.m2/settings.xml
echo "<id>local-proxy</id>" >> ~/.m2/settings.xml
echo "<active>true</active>" >> ~/.m2/settings.xml
echo "<protocol>http</protocol>" >> ~/.m2/settings.xml
echo "<host>$proxyDomain</host>" >> ~/.m2/settings.xml
echo "<port>$proxyPort</port>" >> ~/.m2/settings.xml
echo "</proxy>" >> ~/.m2/settings.xml
echo "</proxies>" >> ~/.m2/settings.xml
echo "</settings>" >> ~/.m2/settings.xml
echo "use_proxy=yes" > ~/.wgetrc
echo "http_proxy=http://$proxyDomain:$proxyPort" >> ~/.wgetrc
echo "https_proxy=http://$proxyDomain:$proxyPort" >> ~/.wgetrc
echo "export http_proxy=http://$proxyDomain:$proxyPort" > ~/.zprofile
echo "export https_proxy=http://$proxyDomain:$proxyPort" >> ~/.zprofile
echo "export no_proxy=localhost,127.0.0.1,$proxyDomain," >> ~/.zprofile
echo "export HTTP_PROXY=http://$proxyDomain:$proxyPort" >> ~/.zprofile
echo "export HTTPS_PROXY=http://$proxyDomain:$proxyPort" >> ~/.zprofile
echo "export NO_PROXY=localhost,127.0.0.1,$proxyDomain," >> ~/.zprofile
git config --global http.proxy "http://$proxyDomain:$proxyPort"
git config --global https.proxy "http://$proxyDomain:$proxyPort"
echo "Web proxy enabled for various tools (atom, curl, git, gradle, maven, ruby, wget, zsh)"
unset IFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment