Skip to content

Instantly share code, notes, and snippets.

@kojiromike
Last active April 29, 2022 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kojiromike/383191a7c5b7287132e43d90239b2b76 to your computer and use it in GitHub Desktop.
Save kojiromike/383191a7c5b7287132e43d90239b2b76 to your computer and use it in GitHub Desktop.
Comprehensive macOS homebrew updates
burp() (
##
# Comprehensively update everything locally installed that I can manage.
local kubectl
softwareupdate -ia # Check for macOS updates
brew up # Update the list of applications in brew
brew upgrade # Update any outdated brew applications
brew list --cask | xargs -n1 brew upgrade --cask # Update any brew casks that were missed
##
# Repair if Docker Cask stomped on kubectl install
kubectl="$(readlink /usr/local/bin/kubectl)"
case "$kubectl" in
''|/Applications/Docker.app/Contents/Resources/bin/kubectl)
echo 'Docker Cask overwrote our files. Repairing kubernetes-cli.'
brew unlink kubernetes-cli || true
brew link --overwrite kubernetes-cli
;;
esac
brew doctor # Check health of brew install
vimup
pyup
)
vimup() {
# Update vim bundles installed with pathogen (separate function)
find "$HOME/.vim" -type d -iname '.git' -print -execdir git pull --recurse-submodules --rebase \;
}
pyup() {
# Update all the pyenv python versions and make sure core packages are installed
# (Don't install 3.6 because it doesn't build on macos.
local -a current have newest outdated want
# The versions we have now.
mapfile -t current < <(pyenv versions --bare | sort -rV)
# The newest versions pyenv is aware of
mapfile -t newest < <(
pyenv install --list |
sort -rV |
awk '$1~/^3\.(10|[789])\.(10|[0-9])/{split($1, a, "."); if (!s[a[2]]++) print $1}')
# The versions we have that are already newest
mapfile -t have < <(comm -12 <(printf '%s\n' "${current[@]}") <(printf '%s\n' "${newest[@]}"))
# The versions we don't have that are newest
mapfile -t want < <(comm -13 <(printf '%s\n' "${current[@]}") <(printf '%s\n' "${newest[@]}"))
# The versions we have that are not newest
mapfile -t outdated < <(comm -23 <(printf '%s\n' "${current[@]}") <(printf '%s\n' "${newest[@]}"))
echo
if (( ${#have[@]} )); then
echo " * Python versions ${have[*]} are up-to-date."
else
echo ' * No Python versions are up-to-date.'
fi
echo
if (( ${#outdated[@]} )); then
echo " * Python versions ${outdated[*]} are out-of-date."
else
echo ' * No Python versions are out-of-date.'
fi
echo
if (( ${#want[@]} )); then
echo " * Installing Python versions ${want[*]}".
else
echo ' * No new Python versions to install.'
fi
echo
if (( ${#want[@]} )); then
for v in "${want[@]}"; do
pyenv install "$v"
done
comm -23 <(printf '%s\n' "${current[@]}") <(printf '%s\n' "${newest[@]}") |
xargs -n1 pyenv uninstall -f
fi
# Activate the newly installed pythons
pyenv versions --bare | sort -rn | xargs pyenv global
# Make sure pip, setuptools, tox-wheel and wheel are installed in each global pyenv
pyenv versions --bare | sort -rn | while read -r ver; do
"python${ver%.*}" -m pip install --upgrade build pip setuptools tox-wheel wheel
done
}
burp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment