Skip to content

Instantly share code, notes, and snippets.

@sysarcher
Created July 26, 2016 22:32
Show Gist options
  • Save sysarcher/6c211913eeadf31a200a3bddd016d086 to your computer and use it in GitHub Desktop.
Save sysarcher/6c211913eeadf31a200a3bddd016d086 to your computer and use it in GitHub Desktop.
Skip `apt-get update` if you've recently updated cache
function getLastAptGetUpdate()
{
local -r aptDate="$(stat -c %Y '/var/cache/apt')"
local -r nowDate="$(date +'%s')"
echo $((nowDate - aptDate))
}
# Default To 24 hours
updateInterval="$((24 * 60 * 60))"
lastAptGetUpdate="$(getLastAptGetUpdate)"
if [[ "${lastAptGetUpdate}" -gt "${updateInterval}" ]]
then
sudo apt-get update
else
#lastUpdate="$(date -u -d @"${lastAptGetUpdate}" +'%-Hh %-Mm %-Ss')"
echo "Skip apt-get update because it was run within ${updateInterval}sec"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment