Skip to content

Instantly share code, notes, and snippets.

@bcap
Created January 20, 2013 05:11
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 bcap/4576775 to your computer and use it in GitHub Desktop.
Save bcap/4576775 to your computer and use it in GitHub Desktop.
Run apt get update in a more reasonable fashion
class apt::update {
# execute apt-get update if any of the following conditions met:
# - there is no apt-get update cache data (eg. first run)
# - any file in the /etc/apt/** was changed after the last execution
# - it was executed more than 24h ago
$apt_update_min_age_in_seconds = "24 * 60 * 60" # you can edit this
$apt_update_condition_1 = "[[ ! -f /var/cache/apt/pkgcache.bin ]]"
$apt_update_condition_2 = "find /etc/apt -cnewer /var/cache/apt/pkgcache.bin | grep ."
$apt_update_condition_3 = "[[ $(( $(date +%s) - $(stat -c %Z /var/cache/apt/pkgcache.bin) )) -gt $(( ${apt_update_min_age_in_seconds} )) ]]"
$apt_update_run_check = "bash -c '${apt_update_condition_1} || ${apt_update_condition_2} || ${apt_update_condition_3}'"
exec { "apt-get update":
onlyif => $apt_update_run_check,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment