Skip to content

Instantly share code, notes, and snippets.

@Fifan31
Last active September 27, 2016 07:19
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 Fifan31/c7cf107470f5abf10b07e9bd28e1fb6e to your computer and use it in GitHub Desktop.
Save Fifan31/c7cf107470f5abf10b07e9bd28e1fb6e to your computer and use it in GitHub Desktop.
Shell functions intialisation. Put this script in /etc/profile.d/
setproxy()
{
proxyhostport="my.proxy.com:portnbr"
authok=0
while [ $authok -eq 0 ] ; do
echo "Setting proxy environment variables:"
echo -n " Username: "
read -e username
echo -n " Password: "
read -es password
ret=$(curl -s -D - -x http://${username}:${password}@${proxyhostport} \
-o /dev/null http://www.example.org | head -n 1 | tr -d '\n\r')
echo
if [ "$ret" == "HTTP/1.0 200 OK" ] ; then
authok=1
else
echo " *** ERROR: authentification failed ('$ret') ***"
fi
done
export http_proxy="http://${username}:${password}@${proxyhostport}"
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export no_proxy="$(hostname),*.my.domain.com,localhost,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16"
echo "Proxy environment variables set"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment