Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Import the apt_repository resource from opscode.

  • Loading branch information...
commit a9b412e80ab9c5c6f5972a0b3fad03c6b94568f0 1 parent b6dc1aa
@till authored
Showing with 102 additions and 0 deletions.
  1. +72 −0 apt/providers/repository.rb
  2. +30 −0 apt/resources/repository.rb
View
72 apt/providers/repository.rb
@@ -0,0 +1,72 @@
+#
+# Cookbook Name:: apt
+# Provider:: repository
+#
+# Copyright 2010-2011, Opscode, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+action :add do
+ unless ::File.exists?("/etc/apt/sources.list.d/#{new_resource.repo_name}-source.list")
+ Chef::Log.info "Adding #{new_resource.repo_name} repository to /etc/apt/sources.list.d/#{new_resource.repo_name}-source.list"
+ # add key
+ if new_resource.keyserver && new_resource.key
+ execute "install-key #{new_resource.key}" do
+ command "apt-key adv --keyserver #{new_resource.keyserver} --recv #{new_resource.key}"
+ action :nothing
+ end.run_action(:run)
+ elsif new_resource.key && (new_resource.key =~ /http/)
+ key_name = new_resource.key.split(/\//).last
+ remote_file "#{Chef::Config[:file_cache_path]}/#{key_name}" do
+ source new_resource.key
+ mode "0644"
+ action :nothing
+ end.run_action(:create_if_missing)
+ execute "install-key #{key_name}" do
+ command "apt-key add #{Chef::Config[:file_cache_path]}/#{key_name}"
+ action :nothing
+ end.run_action(:run)
+ end
+ # build our listing
+ repository = "deb"
+ repository = "deb-src" if new_resource.deb_src
+ repository = "# Created by the Chef apt_repository LWRP\n" + repository
+ repository += " #{new_resource.uri}"
+ repository += " #{new_resource.distribution}"
+ new_resource.components.each {|component| repository += " #{component}"}
+ # write out the file, replace it if it already exists
+ file "/etc/apt/sources.list.d/#{new_resource.repo_name}-source.list" do
+ owner "root"
+ group "root"
+ mode 0644
+ content repository + "\n"
+ action :nothing
+ end.run_action(:create)
+ execute "update package index" do
+ command "apt-get update"
+ action :nothing
+ end.run_action(:run)
+ new_resource.updated_by_last_action(true)
+ end
+end
+
+action :remove do
+ if ::File.exists?("/etc/apt/sources.list.d/#{new_resource.repo_name}-source.list")
+ Chef::Log.info "Removing #{new_resource.repo_name} repository from /etc/apt/sources.list.d/"
+ file "/etc/apt/sources.list.d/#{new_resource.repo_name}-source.list" do
+ action :delete
+ end
+ new_resource.updated_by_last_action(true)
+ end
+end
View
30 apt/resources/repository.rb
@@ -0,0 +1,30 @@
+#
+# Cookbook Name:: apt
+# Resource:: repository
+#
+# Copyright 2010-2011, Opscode, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+actions :add, :remove
+
+#name of the repo, used for source.list filename
+attribute :repo_name, :kind_of => String, :name_attribute => true
+attribute :uri, :kind_of => String
+attribute :distribution, :kind_of => String
+attribute :components, :kind_of => Array, :default => []
+#whether or not to add the repository as a source repo as well
+attribute :deb_src, :default => false
+attribute :keyserver, :kind_of => String, :default => nil
+attribute :key, :kind_of => String, :default => nil
Please sign in to comment.
Something went wrong with that request. Please try again.