Created
January 20, 2013 05:11
-
-
Save bcap/4576775 to your computer and use it in GitHub Desktop.
Run apt get update in a more reasonable fashion
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
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