-
-
Save hongster/972412e022f3bf7f2969d1bc1fd8ef1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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