3 # Resource:: apt_source
5 # Copyright 2015, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 default_action :create
22 property :source_name, String, :name_property => true
23 property :source_template, String, :default => "default.list.erb"
24 property :url, String, :required => true
26 property :key_url, String
27 property :update, [TrueClass, FalseClass], :default => false
29 def initialize(name, run_context = nil)
30 super(name, run_context)
32 @action = node[:apt][:sources].include?(name) ? :create : :delete
37 execute "apt-key-#{key}-clean" do
38 command "/usr/bin/apt-key adv --batch --delete-key --yes #key}"
39 only_if "/usr/bin/apt-key adv --list-keys #{key} | fgrep expired"
43 execute "apt-key-#{key}-install" do
44 command "/usr/bin/apt-key adv --fetch-keys #{key_url}"
45 not_if "/usr/bin/apt-key adv --list-keys #{key}"
46 notifies :run, "execute[apt-update-#{source_name}]"
49 execute "apt-key-#{key}-install" do
50 command "/usr/bin/apt-key adv --keyserver hkp://keys.gnupg.net --recv-keys #{key}"
51 not_if "/usr/bin/apt-key adv --list-keys #{key}"
52 notifies :run, "execute[apt-update-#{source_name}]"
57 template source_path do
58 source source_template
63 notifies :run, "execute[apt-update-#{source_name}]"
66 execute "apt-update-#{source_name}" do
67 action update ? :run : :nothing
68 command "/usr/bin/apt-get update --no-list-cleanup -o Dir::Etc::sourcelist='#{source_path}' -o Dir::Etc::sourceparts='-'"
79 "/etc/apt/sources.list.d/#{source_name}.list"