Skip to content

Instantly share code, notes, and snippets.

@hongster

hongster/update_homebrew.zsh Secret

Created Nov 5, 2020
Embed
What would you like to do?
#!/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