2012-05-04 22:35:13 +02:00
|
|
|
class apt::update {
|
|
|
|
include apt::params
|
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
|
|
|
|
2014-08-18 22:12:55 +02:00
|
|
|
if $::apt::always_apt_update == false {
|
|
|
|
#if always_apt_update is true there's no point in parsing this logic.
|
|
|
|
|
|
|
|
case $apt::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 {
|
|
|
|
$_kick_apt = true
|
2014-10-04 01:30:33 +02:00
|
|
|
} else {
|
|
|
|
$_kick_apt = false
|
2014-08-18 22:12:55 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#if apt-get update has not successfully run, we should kick apt_update
|
|
|
|
$_kick_apt = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'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 ) {
|
|
|
|
$_kick_apt = true
|
2014-10-04 01:30:33 +02:00
|
|
|
} else {
|
|
|
|
$_kick_apt = false
|
2014-08-18 22:12:55 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#if apt-get update has not successfully run, we should kick apt_update
|
|
|
|
$_kick_apt = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
#catches 'recluctantly', and any other value (which should not occur).
|
|
|
|
#do nothing.
|
2014-10-04 01:30:33 +02:00
|
|
|
$_kick_apt = false
|
2014-08-18 22:12:55 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-06 22:41:14 +02:00
|
|
|
} else {
|
|
|
|
$_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':
|
2012-05-04 22:35:13 +02:00
|
|
|
command => "${apt::params::provider} update",
|
2012-06-07 23:53:41 +02:00
|
|
|
logoutput => 'on_failure',
|
2014-08-18 22:12:55 +02:00
|
|
|
refreshonly => $_refresh,
|
2013-10-02 14:24:30 +02:00
|
|
|
timeout => $apt::update_timeout,
|
2014-03-05 22:59:21 +01:00
|
|
|
tries => $apt::update_tries,
|
|
|
|
try_sleep => 1
|
2012-05-04 22:35:13 +02:00
|
|
|
}
|
|
|
|
}
|