Skip to content

Instantly share code, notes, and snippets.

@leemcd56
Created June 18, 2018 16:22
Show Gist options
  • Save leemcd56/dfbe7d35ed218df36c8bd7be606df098 to your computer and use it in GitHub Desktop.
Save leemcd56/dfbe7d35ed218df36c8bd7be606df098 to your computer and use it in GitHub Desktop.
Packages Updater
#!/bin/sh
# up - script to keep your Mac up-to-date (both OS and Homebrew updates) via the command line
# run thus to to install: cd /usr/local/bin && curl -s -O https://gist.githubusercontent.com/mayel/e681a6175bf17366a16e03006d7feac2/raw/bb4ddb0c4842f5633fa1f29df61c433760c4affe/up && chmod 755 /usr/local/bin/up
# and then run it anytime by simply entering the command: up
# By https://github.com/mayel based on a script by https://github.com/imwally
# Homebrew
echo "Checking Homebrew packages..."
brew update > /dev/null;
new_packages=$(brew outdated --quiet)
num_packages=$(echo $new_packages | wc -w)
if [ $num_packages -gt 0 ]; then
echo "\n$num_packages New Brew updates available:"
for package in $new_packages; do
echo " * $package";
done
echo "\nInstall Brew updates? (y/n)"
read answer
if echo "$answer" | grep -iq "^y" ; then
brew upgrade && echo "\nBrew updates done!"
fi
echo "\nClean up old versions of brew packages? (y/n)"
read answer
if echo "$answer" | grep -iq "^y" ; then
brew cleanup && echo "\nBrew cleanup done!"
fi
else
echo "\nNo Brew updates available."
fi
# Composer
echo "\nUpdating Composer..."
composer self-update --quiet > /dev/null;
new_packages=$(composer global show --name-only --outdated --quiet)
num_packages=$(echo $new_packages | sed '/^\s*$/d' | wc -l)
if [ $num_packages -gt 0 ]; then
echo "\n$num_packages New Composer updates available:"
for package in $new_packages; do
echo " * $package";
done
echo "\nInstall Composer updates? (y/n)"
read answer
if echo "$answer" | grep -iq "^y" ; then
composer global update && echo "\nComposer updates done!"
fi
else
echo "\nNo Composer updates available."
fi
# macOS
echo "\nChecking macOS updates..."
softwareupdate -l | tail +5
echo "\nInstall macOS updates? (y/n)"
read answer
if echo "$answer" | grep -iq "^y" ; then
sudo softwareupdate -i -a && echo "\nmacOS updates done! You may need to reboot..."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment