Skip to content

Instantly share code, notes, and snippets.

@nemtsov
Created March 15, 2013 23:45
Show Gist options
  • Save nemtsov/5174097 to your computer and use it in GitHub Desktop.
Save nemtsov/5174097 to your computer and use it in GitHub Desktop.
function setProxy {
local proxy=$1
echo "Setting proxy: $proxy"
#TODO: set proxy here
}
function maybeSetProxy {
local proxy=$1
echo "Detecting whether a proxy is needed..."
env -i bash -c "curl -sm2 example.com"
if [ $? -ne 0 ]
then
echo "Looks like a proxy is needed. Trying with a proxy..."
env -i bash -c "export http_proxy=$proxy; curl -sm2 example.com"
if [ $? -ne 0 ]
then
echo "Setting a proxy won't help. Exiting." 1>&2
exit 1
else
setProxy $proxy
fi
else
echo "No proxy is necessary"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment