Skip to content

Instantly share code, notes, and snippets.

@JoeyBurzynski
Last active May 22, 2020 08:49
Show Gist options
  • Save JoeyBurzynski/383122ca0d2834e7d6204dc5ef7ab043 to your computer and use it in GitHub Desktop.
Save JoeyBurzynski/383122ca0d2834e7d6204dc5ef7ab043 to your computer and use it in GitHub Desktop.
Ensure Homebrew is installed and up to date.
#!/usr/bin/env bash
# * Ensure Homebrew is installed and up to date.
# ? Reference URL: https://brew.sh/
function ensure_homebrew_exists() {
echo "Ensuring Homebrew is installed and up to date."
# * $() is for command substitution, commands don't _return_ values, they _capture_ them
# ? Reference URL: https://stackoverflow.com/a/12137501/890814
# * [[ ]] is the newer _test command_ for evaluations, is more literal
# ? Reference URL: http://mywiki.wooledge.org/BashFAQ/031
# * the double [[ ]], and $() is important
# = `command -v brew` will output nothing if Homebrew is not installed
# * Install Homebrew, if required.
if [[ $(command -v brew) == "" ]]; then
echo " => Installing Homebrew.. "
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# * Update Homebrew, if it exists.
else
echo " ✓ Homebrew is installed. Updating.."
brew update
fi
}
ensure_homebrew_exists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment