Created
December 2, 2019 11:15
-
-
Save Szpadel/5ed5073dd5e6948328025da1f960b6e1 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
sudo -v | |
trap 'echo "Something went wrong, restart script to retry"' ERR | |
set -ex | |
export PATH=/usr/bin:/bin:/usr/sbin:/sbin | |
downloadPkg() { | |
echo "Downloading $1..." | |
/usr/local/bin/brew fetch --retry "$1" > /dev/null | |
echo "Finished downloading $1" | |
} | |
if ! [ -f ~/.brew-upgrade ] && [ -n "$(which brew)" ];then | |
brew list -1 > ~/.brew-upgrade | |
fi | |
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)" | |
if [ -e ~/.gem ];then | |
mv ~/.gem ~/.gem-brew-upgrade | |
fi | |
sudo rm -rf /usr/local/Cellar /usr/local/Homebrew /usr/local/Caskroom | |
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
if [ -f ~/.brew-upgrade ];then | |
find -L /usr/local/bin -name . -o -type d -prune -o -type l -exec rm {} \; | |
find -L /usr/local/sbin -name . -o -type d -prune -o -type l -exec rm {} \; | |
for pkg in $(cat ~/.brew-upgrade);do | |
downloadPkg "$pkg" & | |
done | |
wait | |
for pkg in $(cat ~/.brew-upgrade);do | |
if ! /usr/local/bin/brew install -f "$pkg";then | |
echo "Brew reinstalation failed, press enter to continue or ctrl+c to abort, you will be able to rerun this script to try again" | |
read | |
fi | |
done | |
rm -f ~/.brew-upgrade | |
fi | |
if [ -e ~/.gem-brew-upgrade ];then | |
rm -rf ~/.gem | |
mv ~/.gem-brew-upgrade ~/.gem | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment