Skip to content

Commit

Permalink
Merge pull request #774 from wenzhengjiang/unless_gpg_key_exists
Browse files Browse the repository at this point in the history
Check existence of gpg key in apt:ppa
  • Loading branch information
david22swan authored Aug 23, 2018
2 parents 8b651b5 + 75f5da7 commit cc63cdf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$provider = '/usr/bin/apt-get'
$sources_list = "${root}/sources.list"
$sources_list_d = "${root}/sources.list.d"
$trusted_gpg_d = "${root}/trusted.gpg.d"
$conf_d = "${root}/apt.conf.d"
$preferences = "${root}/preferences"
$preferences_d = "${root}/preferences.d"
Expand Down
23 changes: 17 additions & 6 deletions manifests/ppa.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@

if versioncmp($facts['lsbdistrelease'], '15.10') >= 0 {
$distid = downcase($facts['lsbdistid'])
$filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2-${release}")
$dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-${distid}-\\2")
$underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_${distid}_\\2")
} else {
$filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2-${release}")
$dash_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1-\\2")
$underscore_filename = regsubst($name, '^ppa:([^/]+)/(.+)$', "\\1_\\2")
}

$filename_no_slashes = regsubst($filename, '/', '-', 'G')
$filename_no_specialchars = regsubst($filename_no_slashes, '[\.\+]', '_', 'G')
$sources_list_d_filename = "${filename_no_specialchars}.list"
$dash_filename_no_slashes = regsubst($dash_filename, '/', '-', 'G')
$dash_filename_no_specialchars = regsubst($dash_filename_no_slashes, '[\.\+]', '_', 'G')
$underscore_filename_no_slashes = regsubst($underscore_filename, '/', '-', 'G')
$underscore_filename_no_specialchars = regsubst($underscore_filename_no_slashes, '[\.\+]', '_', 'G')

$sources_list_d_filename = "${dash_filename_no_specialchars}-${release}.list"

if versioncmp($facts['lsbdistrelease'], '15.10') >= 0 {
$trusted_gpg_d_filename = "${underscore_filename_no_specialchars}.gpg"
} else {
$trusted_gpg_d_filename = "${dash_filename_no_specialchars}.gpg"
}

if $ensure == 'present' {
if $package_manage {
Expand All @@ -47,7 +58,7 @@
exec { "add-apt-repository-${name}":
environment => $_proxy_env,
command => "/usr/bin/add-apt-repository ${options} ${name}",
unless => "/usr/bin/test -f ${::apt::sources_list_d}/${sources_list_d_filename}",
unless => "/usr/bin/test -f ${::apt::sources_list_d}/${sources_list_d_filename} && /usr/bin/test -f ${::apt::trusted_gpg_d}/${trusted_gpg_d_filename}",
user => 'root',
logoutput => 'on_failure',
notify => Class['apt::update'],
Expand Down
16 changes: 8 additions & 8 deletions spec/defines/ppa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
it {
is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow+type').that_notifies('Class[Apt::Update]').with(environment: [],
command: '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow+type', # rubocop:disable Metrics/LineLength
unless: '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow_type-trusty.list', # rubocop:disable Metrics/LineLength
unless: '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow_type-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs-such_substitution-wow_type.gpg', # rubocop:disable Metrics/LineLength
user: 'root',
logoutput: 'on_failure')
}
Expand All @@ -47,7 +47,7 @@
it {
is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: [],
command: '/usr/bin/add-apt-repository -y ppa:user/foo',
unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list',
unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-ubuntu-foo-wily.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user_ubuntu_foo.gpg', # rubocop:disable Metrics/LineLength
user: 'root',
logoutput: 'on_failure')
}
Expand Down Expand Up @@ -81,7 +81,7 @@
it {
is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [],
'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', # rubocop:disable Metrics/LineLength
'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list', # rubocop:disable Metrics/LineLength
'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs-such_substitution-wow.gpg', # rubocop:disable Metrics/LineLength
'user' => 'root',
'logoutput' => 'on_failure')
}
Expand Down Expand Up @@ -118,7 +118,7 @@
it {
is_expected.to contain_exec('add-apt-repository-ppa:needs/such.substitution/wow').that_notifies('Class[Apt::Update]').with('environment' => [],
'command' => '/usr/bin/add-apt-repository -y ppa:needs/such.substitution/wow', # rubocop:disable Metrics/LineLength
'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list', # rubocop:disable Metrics/LineLength
'unless' => '/usr/bin/test -f /etc/apt/sources.list.d/needs-such_substitution-wow-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/needs-such_substitution-wow.gpg', # rubocop:disable Metrics/LineLength
'user' => 'root',
'logoutput' => 'on_failure')
}
Expand Down Expand Up @@ -159,7 +159,7 @@
it {
is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: [],
command: '/usr/bin/add-apt-repository ppa:user/foo',
unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', # rubocop:disable Metrics/LineLength
user: 'root',
logoutput: 'on_failure')
}
Expand Down Expand Up @@ -194,7 +194,7 @@
it {
is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8080'],
command: '/usr/bin/add-apt-repository ppa:user/foo',
unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', # rubocop:disable Metrics/LineLength
user: 'root',
logoutput: 'on_failure')
}
Expand Down Expand Up @@ -229,7 +229,7 @@
it {
is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8180'],
command: '/usr/bin/add-apt-repository ppa:user/foo',
unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', # rubocop:disable Metrics/LineLength
user: 'root',
logoutput: 'on_failure')
}
Expand Down Expand Up @@ -264,7 +264,7 @@
it {
is_expected.to contain_exec('add-apt-repository-ppa:user/foo').that_notifies('Class[Apt::Update]').with(environment: ['http_proxy=http://localhost:8180', 'https_proxy=https://localhost:8180'],
command: '/usr/bin/add-apt-repository ppa:user/foo',
unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list',
unless: '/usr/bin/test -f /etc/apt/sources.list.d/user-foo-trusty.list && /usr/bin/test -f /etc/apt/trusted.gpg.d/user-foo.gpg', # rubocop:disable Metrics/LineLength
user: 'root',
logoutput: 'on_failure')
}
Expand Down

0 comments on commit cc63cdf

Please sign in to comment.