Last active
March 26, 2018 08:19
-
-
Save erikw/905a2659e719243fd41c6b2ad4195cc3 to your computer and use it in GitHub Desktop.
brew_upgrade.sh: interactively upgrade all local brew & cask packages for macOS
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
#!/usr/bin/env bash | |
# Interactively upgrade my homebrew system. | |
# Usage: brew_upgrade.sh | |
# Requirements: | |
# - Install cask upgrade command with: $ brew tap buo/cask-upgrade | |
# Exit script on SIGINT. | |
set -e | |
CLI_PREFIX="📦$(tput setaf 1) ======>$(tput sgr0)" | |
last_step= | |
_log_start_step() { | |
last_step="$@" | |
echo "${CLI_PREFIX} ${last_step} -- START" | |
} | |
_log_stop_step() { | |
printf "\n" | |
echo "${CLI_PREFIX} ${last_step} -- DONE" | |
} | |
_exec() { | |
local msg="$1" | |
shift | |
local cmd="$@" | |
_log_start_step "$msg" | |
eval "$cmd" | |
_log_stop_step | |
} | |
_print() { | |
msg="$@" | |
echo "${CLI_PREFIX} $msg" | |
} | |
_exec "Updating brew formulas" brew update | |
outdated=$(brew outdated -v) | |
if [ -n "$outdated" ]; then | |
_print "These packages are outdated: " | |
echo "$outdated" | |
upgrade="" | |
while :; do | |
echo -n "${CLI_PREFIX} Upgrade these? [Yn]: " | |
read upgrade | |
([ -z "$upgrade" ] || [ "$upgrade" = y ] || [ "$upgrade" = Y ] || [ "$upgrade" = n ]) && break | |
done | |
if [ "$upgrade" != n ]; then | |
_exec "Upgrading brew" brew upgrade | |
_exec "The brew doctor says" brew doctor || : # Sneak around $(set -e) as the doctor command return error code. | |
fi | |
fi | |
_exec "Upgrade cask apps" brew cu --all | |
_exec "The brew cask doctor says" brew cask doctor || : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment