2012-05-04 22:35:13 +02:00
|
|
|
class apt::update {
|
2014-08-18 22:12:55 +02:00
|
|
|
#TODO: to catch if $::apt_update_last_success has the value of -1 here. If we
|
|
|
|
#opt to do this, a info/warn would likely be all you'd need likely to happen
|
|
|
|
#on the first run, but if it's not run in awhile something is likely borked
|
|
|
|
#with apt and we'd want to know about it.
|
2012-05-04 22:35:13 +02:00
|
|
|
|
2015-03-18 21:52:12 +01:00
|
|
|
case $::apt::_update['frequency'] {
|
|
|
|
'always': {
|
|
|
|
$_kick_apt = true
|
|
|
|
}
|
|
|
|
'daily': {
|
|
|
|
#compare current date with the apt_update_last_success fact to determine
|
|
|
|
#if we should kick apt_update.
|
|
|
|
$daily_threshold = (strftime('%s') - 86400)
|
|
|
|
if $::apt_update_last_success {
|
|
|
|
if $::apt_update_last_success < $daily_threshold {
|
2014-08-18 22:12:55 +02:00
|
|
|
$_kick_apt = true
|
2015-03-18 21:52:12 +01:00
|
|
|
} else {
|
|
|
|
$_kick_apt = false
|
2014-08-18 22:12:55 +02:00
|
|
|
}
|
2015-03-18 21:52:12 +01:00
|
|
|
} else {
|
|
|
|
#if apt-get update has not successfully run, we should kick apt_update
|
|
|
|
$_kick_apt = true
|
2014-08-18 22:12:55 +02:00
|
|
|
}
|
2015-03-18 21:52:12 +01:00
|
|
|
}
|
|
|
|
'weekly':{
|
|
|
|
#compare current date with the apt_update_last_success fact to determine
|
|
|
|
#if we should kick apt_update.
|
|
|
|
$weekly_threshold = (strftime('%s') - 604800)
|
|
|
|
if $::apt_update_last_success {
|
|
|
|
if ( $::apt_update_last_success < $weekly_threshold ) {
|
2014-08-18 22:12:55 +02:00
|
|
|
$_kick_apt = true
|
2015-03-18 21:52:12 +01:00
|
|
|
} else {
|
|
|
|
$_kick_apt = false
|
2014-08-18 22:12:55 +02:00
|
|
|
}
|
2015-03-18 21:52:12 +01:00
|
|
|
} else {
|
|
|
|
#if apt-get update has not successfully run, we should kick apt_update
|
|
|
|
$_kick_apt = true
|
2014-08-18 22:12:55 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-18 21:52:12 +01:00
|
|
|
default: {
|
2015-06-17 13:05:37 +02:00
|
|
|
#catches 'reluctantly', and any other value (which should not occur).
|
2015-03-18 21:52:12 +01:00
|
|
|
#do nothing.
|
|
|
|
$_kick_apt = false
|
|
|
|
}
|
2014-08-18 22:12:55 +02:00
|
|
|
}
|
2014-10-06 22:41:14 +02:00
|
|
|
|
2014-08-18 22:12:55 +02:00
|
|
|
if $_kick_apt {
|
|
|
|
$_refresh = false
|
|
|
|
} else {
|
|
|
|
$_refresh = true
|
|
|
|
}
|
2012-05-04 00:44:17 +02:00
|
|
|
exec { 'apt_update':
|
2015-02-20 20:15:23 +01:00
|
|
|
command => "${::apt::provider} update",
|
2012-06-07 23:53:41 +02:00
|
|
|
logoutput => 'on_failure',
|
2014-08-18 22:12:55 +02:00
|
|
|
refreshonly => $_refresh,
|
2015-02-28 16:48:48 +01:00
|
|
|
timeout => $::apt::_update['timeout'],
|
|
|
|
tries => $::apt::_update['tries'],
|
2014-03-05 22:59:21 +01:00
|
|
|
try_sleep => 1
|
2012-05-04 22:35:13 +02:00
|
|
|
}
|
|
|
|
}
|