| [1c22429] | 1 | # ppa.pp
|
|---|
| 2 | define apt::ppa(
|
|---|
| 3 | $ensure = 'present',
|
|---|
| 4 | $options = $::apt::ppa_options,
|
|---|
| 5 | $release = $::apt::xfacts['lsbdistcodename'],
|
|---|
| 6 | $package_name = $::apt::ppa_package,
|
|---|
| 7 | $package_manage = false,
|
|---|
| 8 | ) {
|
|---|
| 9 | unless $release {
|
|---|
| 10 | fail('lsbdistcodename fact not available: release parameter required')
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | if $::apt::xfacts['lsbdistid'] == 'Debian' {
|
|---|
| 14 | fail('apt::ppa is not currently supported on Debian.')
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | $ubuntu_release_year = regsubst($::apt::xfacts['lsbdistrelease'], '\.\d+$', '', 'G') + 0
|
|---|
| 18 | $ubuntu_release_month = regsubst($::apt::xfacts['lsbdistrelease'], '^\d+\.', '', 'G') + 0
|
|---|
| 19 |
|
|---|
| 20 | if $ubuntu_release_year >= 15 and $ubuntu_release_month >= 10 {
|
|---|
| 21 | $distid = downcase($::apt::xfacts['lsbdistid'])
|
|---|
| 22 | $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2-${release}")
|
|---|
| 23 | } else {
|
|---|
| 24 | $filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2-${release}")
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | $filename_no_slashes = regsubst($filename, '/', '-', 'G')
|
|---|
| 28 | $filename_no_specialchars = regsubst($filename_no_slashes, '[\.\+]', '_', 'G')
|
|---|
| 29 | $sources_list_d_filename = "${filename_no_specialchars}.list"
|
|---|
| 30 |
|
|---|
| 31 | if $ensure == 'present' {
|
|---|
| 32 | if $package_manage {
|
|---|
| 33 | ensure_packages($package_name)
|
|---|
| 34 |
|
|---|
| 35 | $_require = [File['sources.list.d'], Package[$package_name]]
|
|---|
| 36 | } else {
|
|---|
| 37 | $_require = File['sources.list.d']
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | $_proxy = $::apt::_proxy
|
|---|
| 41 | if $_proxy['host'] {
|
|---|
| 42 | if $_proxy['https'] {
|
|---|
| 43 | $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}", "https_proxy=https://${$_proxy['host']}:${$_proxy['port']}"]
|
|---|
| 44 | } else {
|
|---|
| 45 | $_proxy_env = ["http_proxy=http://${$_proxy['host']}:${$_proxy['port']}"]
|
|---|
| 46 | }
|
|---|
| 47 | } else {
|
|---|
| 48 | $_proxy_env = []
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | exec { "add-apt-repository-${name}":
|
|---|
| 52 | environment => $_proxy_env,
|
|---|
| 53 | command => "/usr/bin/add-apt-repository ${options} ${name}",
|
|---|
| 54 | unless => "/usr/bin/test -s ${::apt::sources_list_d}/${sources_list_d_filename}",
|
|---|
| 55 | user => 'root',
|
|---|
| 56 | logoutput => 'on_failure',
|
|---|
| 57 | notify => Class['apt::update'],
|
|---|
| 58 | require => $_require,
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | file { "${::apt::sources_list_d}/${sources_list_d_filename}":
|
|---|
| 62 | ensure => file,
|
|---|
| 63 | require => Exec["add-apt-repository-${name}"],
|
|---|
| 64 | }
|
|---|
| 65 | }
|
|---|
| 66 | else {
|
|---|
| 67 | file { "${::apt::sources_list_d}/${sources_list_d_filename}":
|
|---|
| 68 | ensure => 'absent',
|
|---|
| 69 | notify => Class['apt::update'],
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|