Created
July 15, 2016 19:45
-
-
Save joncardasis/90dd80d67a1c329e464e76b19cdcdee9 to your computer and use it in GitHub Desktop.
Setup script for cloning git submodules through an enterprise proxy
This file contains 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 | |
# Sets up and configured Git to work with an enterprise proxy for | |
# cloning submodules through the git/https protocol. Tunnels all git | |
# traffic through the proxy to allow for these commands. | |
#Set proxies: | |
http_proxy="proxy.example.com:83" | |
http_proxy_port="83" #specifically specify the port only | |
https_proxy="proxy.example.com:83" | |
#################### | |
function printInRed { | |
printf '\e[0;31m%s\e[0m\n' "$1" | |
} | |
function printInGreen { | |
printf '\e[0;32m%s\e[0m\n' "$1" | |
} | |
function printInCyan { | |
printf '\e[0;36m%s\e[0m\n' "$1" | |
} | |
printInCyan "Setting up GitHub access for Enterprise Network..." | |
#Set proxies for current terminal session (Allow to connect for brew) | |
export HTTPS_PROXY=$http_proxy | |
export HTTP_PROXY=$https_proxy | |
#Check if homebrew is installed | |
command -v brew >/dev/null 2>&1 || { printInRed 'Homebrew is not installed. Please install Homebrew before continuing.'; exit 1; } | |
#Open permissions for /usr/local & /Library/Caches/Homebrew for read and write access | |
sudo chmod +a "everyone allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity" /usr/local | |
if [ -d /Library/Caches/Homebrew ]; then | |
sudo chmod +a "everyone allow list,add_file,search,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity" /Library/Caches/Homebrew | |
fi | |
#Install socat through Homebrew | |
brew install socat | |
if [ ! -d /usr/local/git ]; then | |
printInRed 'A proper version of Git is not installed.' | |
printInRed 'Download the latest from https://git-scm.com' | |
exit 1; | |
fi | |
#Create the gitproxy file | |
echo "Creating git-proxy..." | |
if [ ! -f /usr/local/bin/gitproxy ]; then | |
#create if it doesn't yet exist | |
echo '_proxy=$http_proxy' >> /usr/local/bin/gitproxy | |
echo '_proxyport=$http_proxy_port' >> /usr/local/bin/gitproxy | |
echo 'exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport' >> /usr/local/bin/gitproxy | |
#Enable execute access for gitproxy | |
chmod +x /usr/local/bin/gitproxy | |
else | |
echo "The git-proxy already exists." | |
fi | |
#Set up the system-wide git config for proxy | |
echo "Configuring git to use proxy..." | |
sudo git config --system url."https://github.com/".insteadOf git@github.com: | |
sudo git config --system core.gitproxy gitproxy | |
#Done | |
printInGreen "GitHub Access Configured for All System Users." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment