Skip to content

Instantly share code, notes, and snippets.

@hongster
Created November 5, 2020 01:53
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 hongster/972412e022f3bf7f2969d1bc1fd8ef1e to your computer and use it in GitHub Desktop.
Save hongster/972412e022f3bf7f2969d1bc1fd8ef1e to your computer and use it in GitHub Desktop.
#!/usr/bin/env zsh
# Automate updateing of brew, to be executed by cronjob.
# It keeps a timestamp of last update. If last update is more than 1 day ago, update will be preformed.
# If last update was within 24 hours, skip this update.
# If `-f` switch is used, it will preform update iregardless of timestamp.
timestampFile="/tmp/brew_update.timestamp"
function updateBrew {
/usr/local/bin/brew upgrade
/usr/local/bin/brew cleanup
touch ${timestampFile}
}
if [ "$1" = "-f" ]; then
echo "Forced update"
updateBrew
elif [ ! -f ${timestampFile} ]; then
echo "First update"
updateBrew
elif [ $(find -L ${timestampFile} -mtime +1) ]; then
echo "Last update more than 1 day"
updateBrew
else
echo "Skipping this update, as it was updated recently."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment