Skip to content

Instantly share code, notes, and snippets.

@mikesprague
Created May 25, 2023 16:28
Show Gist options
  • Save mikesprague/a9600842f43691bf4d608cb419733df7 to your computer and use it in GitHub Desktop.
Save mikesprague/a9600842f43691bf4d608cb419733df7 to your computer and use it in GitHub Desktop.
Bash script to run some common updates/commands I use
#!/bin/bash
# PREREQUISITES:
# - Homebrew
# - Zsh
# - oh-my-zsh
# - Node.js with the following global packages installed:
# - npm-check-updates
# - n
# - Docker
# homebrew housekeeping
brew cleanup && brew doctor
# update/upgrade homebrew packages
brew update && brew upgrade
# update oh-my-zsh
"$ZSH/tools/upgrade.sh"
# make sure LTS version of Node.js is installed (and npm is up to date)
n lts && npm i --location=global npm corepack
# make sure latest version of Node.js is installed (and npm is up to date)
n latest && npm i --location=global npm corepack
# run npm-check-updates on global npm packages
command=$(ncu -g | tail -n 2)
# if there are any updates, upgrade those global packages
update_string='npm -g install'
if [[ "$command" == *"$update_string"* ]]; then
# echo "$command"
eval "$command"
fi
# update all docker images
for image in $(docker images --format "{{.Repository}}:{{.Tag}}"); do docker pull "$image"; done
# remove any stale docker images
docker rmi -f "$(docker images -f dangling=true -q)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment