diff --git a/README.md b/README.md index 1a99f24..f54293a 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ Attributes * `node['wordpress']['server_name']` - Hostname used for setting up the Virtual Host configuration for your WordPress site * `node['wordpress']['php_options']` - Additional PHP settings for the installation. +* `node['wordpress']['plugins']` - Hash of plugin names and URLs to be installed. Usage ===== diff --git a/attributes/default.rb b/attributes/default.rb index 873753d..9feacb9 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -101,3 +101,6 @@ end default['wordpress']['php_options'] = { 'php_admin_value[upload_max_filesize]' => '50M', 'php_admin_value[post_max_size]' => '55M' } + +default['wordpress']['plugins'] = {} + diff --git a/providers/plugin.rb b/providers/plugin.rb new file mode 100644 index 0000000..d53b8ee --- /dev/null +++ b/providers/plugin.rb @@ -0,0 +1,51 @@ + +def whyrun_supported? + true +end + +action :install do + + if @current_resource.exists + Chef::Log.info "Plugin #{@new_resource} already exists - nothing to do." + else + converge_by("Add plugin #{@new_resource}") do + add_plugin + end + end +end + +def add_plugin + # Retrieve the file + remote_file "#{Chef::Config[:file_cache_path]}/#{new_resource.plugin_name}.zip" do + source new_resource.url + end + + # TODO: update/freshen the files in the plugins directory + bash "install-plugin" do + cwd "#{node['wordpress']['dir']}/wp-content/plugins" + code "temp=(mktemp -d) && unzip -d $temp #{Chef::Config[:file_cache_path]}/#{new_resource.plugin_name}.zip && mkdir #{new_resource.plugin_name} && mv $temp/*/* #{new_resource.plugin_name} && rmdir $temp/* $temp" + end +end + +def load_current_resource + @current_resource = Chef::Resource::WordpressPlugin.new(@new_resource.name) + @current_resource.name(@new_resource.name) + @current_resource.plugin_name(@new_resource.plugin_name) + @current_resource.url(@new_resource.url) + + if plugin_exists?(@current_resource.plugin_name) + @current_resource.exists = true + end + + @current_resource +end + +def plugin_exists?(name) + + if Dir.exist?("#{node['wordpress']['dir']}/wp-content/plugins/#{name}") + return true + end + + return false +end + diff --git a/recipes/app.rb b/recipes/app.rb index b3d9f41..35a15bb 100644 --- a/recipes/app.rb +++ b/recipes/app.rb @@ -88,3 +88,6 @@ group node['wordpress']['install']['group'] action :create end + +include_recipe "wordpress::plugins" + diff --git a/recipes/plugins.rb b/recipes/plugins.rb new file mode 100644 index 0000000..82f0edd --- /dev/null +++ b/recipes/plugins.rb @@ -0,0 +1,29 @@ +# +# Cookbook Name:: wordpress +# Recipe:: plugins +# +# Copyright 2009-2010, 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. +# + +package "unzip" + +node['wordpress']['plugins'].each do |plugin, url| + + wordpress_plugin plugin do + url url + end + +end + diff --git a/resources/plugin.rb b/resources/plugin.rb new file mode 100644 index 0000000..509613c --- /dev/null +++ b/resources/plugin.rb @@ -0,0 +1,11 @@ + +actions :install +default_action :install + +attribute :plugin_name, :name_attribute => true, :kind_of => String, + :required => true + +attribute :url, :kind_of => String, :default => nil, :required => true + +attr_accessor :exists +