Permalink
Browse files

add pacman_aur LWRP

  • Loading branch information...
1 parent 836c448 commit c48813e3037fb5f6e404ddaa1a8ddb769ef0a9e1 @jtimberman jtimberman committed Oct 27, 2010
Showing with 190 additions and 7 deletions.
  1. +31 −2 pacman/README.md
  2. +1 −1 pacman/metadata.json
  3. +1 −4 pacman/metadata.rb
  4. +129 −0 pacman/providers/aur.rb
  5. +28 −0 pacman/resources/aur.rb
View
@@ -1,19 +1,48 @@
DESCRIPTION
===========
-Refreshes the pacman package cache from the FTP servers and provides an LWRP for managing package groups.
+Refreshes the pacman package cache from the FTP servers and provides LWRPs related to pacman
REQUIREMENTS
============
Platform: ArchLinux. Pacman is not relevant on other platforms.
+RESOURCES
+=========
+
+`pacman_group`
+--------------
+
+Use the `pacman_group` resource to install or remove pacman package groups. Note that at this time the LWRP will check if the group is installed but doesn't do a lot of error checking or handling. File a ticket on the COOK project at tickets.opscode.com for improvements and feature requests.
+
+The `options` parameter can be used to pass arbitrary options to the pacman command.
+
+`pacman_aur`
+------------
+
+Use the `pacman_aur` resource to install packages from ArchLinux's AUR repository.
+
+### Actions:
+
+* :build - Builds the package.
+* :install - Installs the built package.
+
+### Parameters:
+
+* version - hardcode a version
+* builddir - specify an alternate build directory, defaults to `Chef::Config[:file_cache_path]/builds`.
+* options - pass arbitrary options to the pacman command.
+* `pkgbuild_src` - whether to use an included PKGBUILD file, put the PKGBUILD file in in the `files/default` directory.
+* patches - array of patch names, as files in `files/default` that should be applied for the package.
+
+http://aur.archlinux.org/
+
USAGE
=====
Include `recipe[pacman]` early in the run list, preferably first, to ensure that the package caches are updated before trying to install new packages.
-Use the `pacman_group` resource to install or remove pacman package groups. Note that at this time the LWRP will check if the group is installed but doesn't do a lot of error checking or handling. File a ticket on the COOK project at tickets.opscode.com for improvements and feature requests.
LICENSE AND AUTHOR
==================
@@ -1,6 +1,6 @@
{
"name": "pacman",
- "description": "Updates package list for pacman",
+ "description": "Updates package list for pacman and has LWRP for pacman groups",
"long_description": "DESCRIPTION\n===========\n\nPrimarily refreshes the pacman package cache from the FTP servers.\n\nREQUIREMENTS\n============\n\nArchLinux.\n\nLICENSE AND AUTHOR\n==================\n\nAuthor:: Joshua Timberman (<joshua@opscode.com>)\n\nCopyright:: Opscode, Inc. (<legal@opscode.com>)\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n",
"maintainer": "Opscode, Inc.",
"maintainer_email": "cookbooks@opscode.com",
View
@@ -3,7 +3,4 @@
license "Apache 2.0"
description "Updates package list for pacman and has LWRP for pacman groups"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
-version "0.9.0"
-supports "arch"
-
-recipe "pacman", "Refreshes the pacman package cache"
+version "1.0.0"
@@ -0,0 +1,129 @@
+#
+# Cookbook Name:: pacman
+# Provider:: aur
+#
+# Copyright:: 2010, Opscode, Inc <legal@opscode.com>
+#
+# 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.
+#
+
+require 'chef/mixin/shell_out'
+require 'chef/mixin/language'
+include Chef::Mixin::ShellOut
+
+action :build do
+ get_pkg_version
+ aurfile = "#{new_resource.builddir}/#{new_resource.name}/#{new_resource.name}-#{new_resource.version}.pkg.tar.xz"
+
+ Chef::Log.debug("Checking for #{aurfile}")
+ unless ::File.exists?("#{aurfile}")
+ Chef::Log.debug("Creating build directory")
+ d = directory "#{new_resource.builddir}" do
+ owner "root"
+ group "root"
+ mode 0755
+ action :nothing
+ end
+ d.run_action(:create)
+
+ Chef::Log.debug("Retrieving source for #{new_resource.name}")
+ r = remote_file "#{new_resource.builddir}/#{new_resource.name}.tar.gz" do
+ source "http://aur.archlinux.org/packages/#{new_resource.name}/#{new_resource.name}.tar.gz"
+ owner "root"
+ group "root"
+ mode 0644
+ action :nothing
+ end
+ r.run_action(:create_if_missing)
+
+ Chef::Log.debug("Untarring source package for #{new_resource.name}")
+ e = execute "tar -xf #{new_resource.name}.tar.gz" do
+ cwd new_resource.builddir
+ action :nothing
+ end
+ e.run_action(:run)
+
+ if new_resource.pkgbuild_src
+ Chef::Log.debug("Replacing PKGBUILD with custom version")
+ pkgb = cookbook_file "#{new_resource.builddir}/#{new_resource.name}/PKGBUILD" do
+ source "PKGBUILD"
+ owner "root"
+ group "root"
+ mode 0644
+ action :nothing
+ end
+ pkgb.run_action(:create)
+ end
+
+ if new_resource.patches.length > 0
+ Chef::Log.debug("Adding new patches")
+ new_resource.patches.each do |patch|
+ pfile = cookbook_file "#{new_resource.builddir}/#{new_resource.name}/#{patch}" do
+ source "#{patch}"
+ mode 0644
+ action :nothing
+ end
+ pfile.run_action(:create)
+ end
+ end
+
+ if new_resource.options
+ Chef::Log.debug("Appending #{new_resource.options} to configure command")
+ opt = Chef::Util::FileEdit.new("#{new_resource.builddir}/#{new_resource.name}/PKGBUILD")
+ opt.search_file_replace(/(.\/configure.+$)/, "\\1 #{new_resource.options}")
+ opt.write_file
+ end
+
+ Chef::Log.debug("Building package #{new_resource.name}")
+ em = execute "makepkg -s --asroot" do
+ cwd "#{new_resource.builddir}/#{new_resource.name}"
+ creates "#{aurfile}"
+ action :nothing
+ end
+ em.run_action(:run)
+ @updated = true
+ end
+end
+
+action :install do
+ unless @aurpkg.exists
+ get_pkg_version
+ execute "install AUR package #{new_resource.name}" do
+ command "pacman -U --noconfirm --noprogressbar #{new_resource.builddir}/#{new_resource.name}/#{new_resource.name}-#{new_resource.version}.pkg.tar.xz"
+ end
+ @updated = true
+ end
+end
+
+def get_pkg_version
+ v = ''
+ r = ''
+ if ::File.exists?("#{new_resource.builddir}/#{new_resource.name}/PKGBUILD")
+ ::File.open("#{new_resource.builddir}/#{new_resource.name}/PKGBUILD").each do |line|
+ v = line.split("=")[1].chomp if line =~ /^pkgver/
+ r = line.split("=")[1].chomp if line =~ /^pkgrel/
+ end
+ Chef::Log.debug("Setting version of #{new_resource.name} to #{v}-#{r}")
+ new_resource.version("#{v}-#{r}-#{node.kernel.machine}")
+ end
+end
+
+def load_current_resource
+ @aurpkg = Chef::Resource::PacmanAur.new(new_resource.name)
+ @aurpkg.package_name(new_resource.package_name)
+
+ Chef::Log.debug("Checking pacman for #{new_resource.package_name}")
+ p = shell_out("pacman -Qi #{new_resource.package_name}")
+ exists = p.stdout.include?(new_resource.package_name)
+ @aurpkg.exists(exists)
+end
@@ -0,0 +1,28 @@
+#
+# Cookbook Name:: pacman
+# Resource:: group
+#
+# Copyright:: 2010, Opscode, Inc <legal@opscode.com>
+#
+# 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 :build, :install
+
+attribute :package_name, :name_attribute => true
+attribute :version, :default => nil
+attribute :builddir, :default => "#{Chef::Config[:file_cache_path]}/builds"
+attribute :options, :kind_of => String
+attribute :pkgbuild_src, :default => false
+attribute :patches, :kind_of => Array, :default => []
+attribute :exists, :default => false

0 comments on commit c48813e

Please sign in to comment.