summaryrefslogtreecommitdiff
path: root/manifests/upgrade_package.pp
blob: 3ba2077a8b2e979dee4308914cbf24c6011644dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Install a package either to a certain version, or while making sure that it's
# always the latest version that's installed.

define apt::upgrade_package (
  $version = '',
) {

  $version_suffix = $version ? {
    ''       => '',
    'latest' => '',
    default  => "=${version}",
  }

  if !defined(Package['apt-show-versions']) {
    package { 'apt-show-versions':
      ensure  => present,
    }
  }

  if !defined(Package['dctrl-tools']) {
    package { 'dctrl-tools':
      ensure  => present,
    }
  }

  exec { "apt-get -q -y -o 'DPkg::Options::=--force-confold' install ${name}${version_suffix}":
    onlyif  => [ "grep-status -F Status installed -a -P ${name} -q", "apt-show-versions -u ${name} | grep -q upgradeable" ],
    require => Package['apt-show-versions', 'dctrl-tools'],
    before  => Exec['update_apt'];
  }
}