Created
February 24, 2016 08:07
-
-
Save platypython/4712468b19cf5a4f4664 to your computer and use it in GitHub Desktop.
Fix Homebrew on El Capitan
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 | |
| # Fix brew in El Capitan! | |
| # Check if sudo/root | |
| if [ $USER == "root" ]; then | |
| echo "NOOOOOO!!!! Running this script as root would ruin everything! Please run with" | |
| echo "your normal user. It will prompt for sudo later for just a few commands." | |
| exit 1 | |
| fi | |
| # Don't say I didn't warn ya | |
| clear | |
| echo "******************************************************************************" | |
| echo "* WARNING- This will nuke all your global packages in brewed NPM, python2, *" | |
| echo "* python3, golang, and (insert brewed language here) *" | |
| echo "* You might want to 'npm -g shrinkrwap','pip2 freeze','pip3 freeze', etc to *" | |
| echo "* get a list to reinstall later, although starting from scratch might make *" | |
| echo "* for a cleaner environment overall :) *" | |
| echo "******************************************************************************" | |
| echo "" | |
| echo "" | |
| # Ask politely | |
| while true; do | |
| read -p "Do you want to remove brew and start over?" -n 1 yn | |
| case $yn in | |
| [Yy]* ) echo ""; echo "LETS BURN THIS CANDLE!"; break;; | |
| [Nn]* ) echo ""; echo "No changes made!"; exit;; | |
| * ) echo "Please answer yes or no.";; | |
| esac | |
| done | |
| # Install coreutils and gnutils | |
| echo "" | |
| echo "As part of the reinstall would you like to install the gnu command line tools" | |
| echo "(sed, tar, grep, etc) without a 'g' prefix, so you don't have to use OSX's " | |
| echo "BSDified version of them?" | |
| # Ask politely | |
| while true; do | |
| read -p "Y to use the same tools you'll find server side, N to keep defaults" -n 1 yn | |
| case $yn in | |
| [Yy]* ) echo ""; echo "You have chosen wisely."; GNU="1"; break;; | |
| [Nn]* ) echo ""; echo "Coreutils will not be installed"; break;; | |
| * ) echo "Please answer yes or no.";; | |
| esac | |
| done | |
| # Burn the candle!; check xcode cli | |
| echo "" | |
| xcode-select -p | |
| if [ $? -ne 0 ]; then | |
| xcode-select --install | |
| read -p "Press [Enter] when xcode is finished installing..." | |
| fi | |
| # Cache sudo creds for as long as we need em. | |
| echo "" | |
| echo "We're gonna have sudo refresh its timestamp because a few commands need it" | |
| echo "and if you don't have NOPASSWD enabled this way you'll only need to type it" | |
| echo "once." | |
| sudo -v | |
| # Grab what brews ya got | |
| echo "Getting taps" | |
| brew tap > ~/brewed_taps | |
| echo "Getting package list" | |
| brew list > ~/brewed_pkgs | |
| echo "Getting casks" | |
| brew cask list > ~/brewed_casks | |
| # OSX screws up perms on el capitan upgrade | |
| echo "Fixing OSX's derpy ownership of YOUR home folder" | |
| sudo chown -R $USER /Users/$USER | |
| # Its just cleaner to start from scratch, /usr/local does NOT exist on a clean OSX install | |
| echo "Removing old brew folders" | |
| sudo rm -rf /usr/local/ | |
| sudo rm -rf /Library/Caches/Homebrew/ | |
| # Install brew | |
| echo "Installing brew..." | |
| /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
| # Install cask (in case you're using it, cus ya should be) | |
| brew install cask | |
| brew cask > /dev/null 2>&1 # does pre init | |
| # Install gnutils/coreutils | |
| if [ $GNU == "1" ]; then | |
| echo "Installing gnutils/coreutils" | |
| brew tap homebrew/dupes | |
| GNUTILS="binutils\ndiffutils\ned --with-default-names\nfindutils --with-default-names\ngawk\ngnu-indent --with-default-names\ngnu-sed --with-default-names\ngnu-tar --with-default-names\ngnu-which --with-default-names\ngnutls\ngrep --with-default-names\ngzip\nscreen\nwatch\nwdiff --with-gettext\nwget\ncoreutils" | |
| echo -e $GNUTILS | /usr/bin/xargs -L 1 -J % brew install % 2> /tmp/brew_errors | |
| fi | |
| # Go grab dinner | |
| cat ~/brewed_taps | /usr/bin/xargs -L 1 -J % brew tap % 2>> /tmp/brew_errors | |
| cat ~/brewed_pkgs | /usr/bin/xargs -J % brew install % 2>> /tmp/brew_errors | |
| cat ~/brewed_casks | /usr/bin/xargs -J % brew cask install % 2>> /tmp/brew_errors | |
| echo "All Set!" | |
| echo "" | |
| echo "" | |
| echo "Here's the error log, mostly junk probably." | |
| cat /tmp/brew_errors | |
| echo "" | |
| echo "" | |
| echo "For coreutils, if you haven't already, you'll need to add some pathing so you don't" | |
| echo "have to prefix with 'g' " | |
| echo "" | |
| echo "If you really need to use these commands with their normal names, you" | |
| echo "can add a "gnubin" directory to your PATH from your bashrc like:" | |
| echo "" | |
| echo ' PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment