Created
August 14, 2019 15:21
-
-
Save pablordoricaw/77244409f996bd4740b3c016824ef270 to your computer and use it in GitHub Desktop.
This bash script sets/unsets the http and https proxies for git
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### | |
# This bash script sets/unsets the http and https proxies for git | |
### | |
# get the scripts name for the usage message | |
_filename=$0 | |
# verbose mode deactivated | |
verbose=false | |
# Global variables | |
SET=1 # Default set proxies | |
# Display usage message function | |
usage(){ | |
echo "Usage:" | |
echo -e "\t$_filename -h Display usage message" | |
echo -e "\t$_filename [-v] Verbose mode" | |
echo -e "\t$_filename [-u] Set/Unset Git proxies" | |
} | |
# Verbose print function | |
verbose_print(){ | |
if $verbose | |
then | |
echo "$1" | |
fi | |
} | |
if [ ! 0 == $# ] # If options provided then | |
then | |
while getopts "hvu" opt; do # Go through the options | |
case $opt in | |
h ) # Help | |
usage | |
exit 0 # Exit correctly | |
;; | |
u ) # Unset Git proxies | |
SET=0 | |
;; | |
v ) # Verbose | |
echo "Verbose mode activated..." | |
verbose=true | |
;; | |
? ) # Invalid option | |
usage | |
exit 1 # Exit with erro | |
;; | |
esac | |
done | |
fi | |
if [ $SET = 1 ] | |
then | |
verbose_print "Setting HTTP Proxy.." | |
git config --global http.proxy "http://<username>:<password>@proxy.aholdusa.com:8080" | |
verbose_print "Setting HTTPS Proxy..." | |
git config --global https.proxy "https://<username>:<password>@proxy.aholdusa.com:8080" | |
echo "- Git Proxies set -" | |
else | |
verbose_print "Unsetting HTTP Proxy" | |
git config --global --unset http.proxy | |
verbose_print "Unsetting HTTPS Proxy" | |
git config --global --unset https.proxy | |
echo "- Git Proxies unset -" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment