Last active
December 19, 2016 13:13
-
-
Save mcenirm/a055587699858a9b2980 to your computer and use it in GitHub Desktop.
Update various packages on macosx with homebrew
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 | |
# gist -r a055587699858a9b2980 | diff -u - update_various_packages | |
# gist -u a055587699858a9b2980 update_various_packages | |
set -e | |
_saved_path=$PATH | |
# brew doctor does not like pyenv: | |
# Warning: python is symlinked to python3 | |
# Warning: "config" scripts exist outside your system or Homebrew directories. | |
if [ -n "$PYENV_ROOT" ] ; then export PATH=$( python - "$PATH" "$PYENV_ROOT" <<EOF | |
import os, sys | |
path = sys.argv[1].split(os.pathsep) | |
good = [p for p in path if not p.startswith(sys.argv[2].rstrip('/')+'/')] | |
print(os.pathsep.join(good)) | |
EOF | |
) | |
fi | |
# brew doctor does not like unprefixed coreutils or findutils in PATH | |
export PATH=$( python - "$PATH" <<EOF | |
import os, sys | |
path = sys.argv[1].split(os.pathsep) | |
good = [p for p in path if not p.endswith('/gnubin')] | |
print(os.pathsep.join(good)) | |
EOF | |
) | |
set -x | |
brew update | |
brew upgrade | |
brew cleanup | |
brew cask cleanup | |
brew prune | |
brew doctor | |
set +x | |
PATH=${_saved_path} | |
good_xxenv_versions () { | |
sed -E -n -e 's#^[* ] ([0-9]+\.[0-9]+\.[0-9]+)( .*)?$#\1#p' | sort -u | |
} | |
if command -v rbenv > /dev/null ; then | |
for v in $( rbenv versions | good_xxenv_versions ) ; do | |
( | |
export RBENV_VERSION=${v} | |
rbenv version | |
set -x | |
rbenv exec gem update | |
rbenv exec gem cleanup -v | |
rbenv rehash | |
set +x | |
) | |
done | |
fi | |
if command -v npm ; then | |
set -x | |
npm -g update | |
set +x | |
fi | |
sort_with_first () { | |
local marker=\" | |
local name=pip | |
sed -e "s/^\(${name}\)$/${marker}\1/" | sort | sed -e "s/^${marker}//" | |
} | |
pip_upgrade () { | |
local pip=$1 | |
command -v "$pip" || return | |
local troublepkgs=() | |
local pkg | |
local listcmd=( $pip list --outdated ) | |
local pipmajorversion=$( | |
pip freeze --disable-pip-version-check --all \ | |
| sed -n -e 's,^pip==,,p' | egrep -o '^[0-9]+' | |
) | |
if [ "$pipmajorversion" -lt 9 ] ; then | |
$pip install -U pip | |
fi | |
for i in 1 2 ; do | |
for pkg in $( $pip list --outdated --format=freeze | cut -d= -f1 | sort_with_first ) ; do | |
if ! (set -x ; $pip install -U "$pkg" ) ; then | |
troublepkgs+=( "$pkg" ) | |
fi | |
done | |
if [ ${#troublepkgs[@]} -gt 0 ] ; then | |
echo Trouble packages for "$pip": "${troublepkgs[@]}" | |
fi | |
done | |
} | |
for v in $( pyenv versions | good_xxenv_versions ) ; do | |
PYENV_VERSION=${v} pyenv version | |
PYENV_VERSION=${v} pip_upgrade pip | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment