From b0177154179dce49be9f91f3e203b490514a3573 Mon Sep 17 00:00:00 2001 From: fh Date: Fri, 7 Mar 2014 07:47:53 +0100 Subject: [PATCH] Optional reenabling of pear --- easybib/attributes/default.rb | 1 + easybib/metadata.rb | 1 + easybib/recipes/role-phpapp.rb | 4 ++ php-pear/README.md | 0 php-pear/attributes/default.rb | 11 ++++ php-pear/metadata.rb | 11 ++++ php-pear/providers/pear.rb | 104 +++++++++++++++++++++++++++++++++ php-pear/recipes/default.rb | 49 ++++++++++++++++ php-pear/recipes/packages.rb | 49 ++++++++++++++++ php-pear/resources/pear.rb | 8 +++ 10 files changed, 238 insertions(+) create mode 100644 php-pear/README.md create mode 100644 php-pear/attributes/default.rb create mode 100644 php-pear/metadata.rb create mode 100644 php-pear/providers/pear.rb create mode 100644 php-pear/recipes/default.rb create mode 100644 php-pear/recipes/packages.rb create mode 100644 php-pear/resources/pear.rb diff --git a/easybib/attributes/default.rb b/easybib/attributes/default.rb index 2f04af2dc..5b7d46d01 100644 --- a/easybib/attributes/default.rb +++ b/easybib/attributes/default.rb @@ -1,3 +1,4 @@ default["easybib_deploy"] = {} default["easybib_deploy"]["gearman_file"] = "pecl_manager_env" default["easybib_deploy"]["env_source"] = nil +default["easybib_deploy"]["provide_pear"] = false diff --git a/easybib/metadata.rb b/easybib/metadata.rb index a2fadb5b9..48f4981d3 100644 --- a/easybib/metadata.rb +++ b/easybib/metadata.rb @@ -31,6 +31,7 @@ depends "php-gearman" depends "php-intl" depends "php-mysqli" +depends "php-pear" depends "php-phar" depends "php-opcache" depends "php-poppler-pdf" diff --git a/easybib/recipes/role-phpapp.rb b/easybib/recipes/role-phpapp.rb index 05535a3b2..d98985e2d 100644 --- a/easybib/recipes/role-phpapp.rb +++ b/easybib/recipes/role-phpapp.rb @@ -4,6 +4,10 @@ include_recipe "php-suhosin" include_recipe "composer::configure" +if node['easybib_deploy']['provide_pear'] + include_recipe "php-pear" +end + if is_aws include_recipe "php-opcache::configure" include_recipe "newrelic" diff --git a/php-pear/README.md b/php-pear/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/php-pear/attributes/default.rb b/php-pear/attributes/default.rb new file mode 100644 index 000000000..161d6ef11 --- /dev/null +++ b/php-pear/attributes/default.rb @@ -0,0 +1,11 @@ +default["php-pear"] = {} +default["php-pear"]["packages"] = { + "Crypt_HMAC2-beta" => "pear.php.net", + "Net_Gearman-alpha" => "pear.php.net", + "Services_Amazon_S3-0.4.0" => "pear.php.net", + "Net_CheckIP2-1.0.0RC3" => "pear.php.net", + "Easybib_Form_Decorator-0.3.2" => "easybib.github.com/pear", + "StatsD-alpha" => "easybib.github.com/pear", + "Lagged_Session_SaveHandler_Memcache-0.8.0b2" => "easybib.github.com/pear", + "Rediska-0.5.6" => "easybib.github.com/pear" +} diff --git a/php-pear/metadata.rb b/php-pear/metadata.rb new file mode 100644 index 000000000..e76062d28 --- /dev/null +++ b/php-pear/metadata.rb @@ -0,0 +1,11 @@ +name "php-pear" +maintainer "Till Klampaeckel" +maintainer_email "till@php.net" +license "BSD License" +description "Installs various PEAR packages" +version "0.1" + +depends "php" +depends "php-fpm" + +supports 'ubuntu' diff --git a/php-pear/providers/pear.rb b/php-pear/providers/pear.rb new file mode 100644 index 000000000..e8eb41163 --- /dev/null +++ b/php-pear/providers/pear.rb @@ -0,0 +1,104 @@ +def initialize(*args) + super(*args) + + pear = pear_run("which pear").strip + + if pear.empty? + fail Chef::Exceptions::ShellCommandFailed, "PEAR is not installed, or not in the path." + end + + @pear_cmd = pear + + Chef::Log.debug("Looks like we found a PEAR installer: #{@pear_cmd}") + pear_run("#{@pear_cmd} config-set auto_discover 1") + Chef::Log.debug("Enabled auto_discover") +end + +def pear_run(cmd) + cmd = Mixlib::ShellOut.new(cmd) + out = cmd.run_command.stdout.strip + # Chef::Log.debug("Command '#{cmd.command}' ran with exit status: #{cmd.exitstatus}") + # Chef::Log.debug("StdOut: #{cmd.stdout}") + # Chef::Log.debug("StdErr: #{cmd.stderr}") + + if cmd.exitstatus > 0 + fail "Failed: #{cmd.command}, StdOut: #{cmd.stdout}, StdErr: #{cmd.stderr}" + end + + out +end + +def discovered?(pear, channel) + command = "#{pear} channel-info #{channel}" + cmd = Mixlib::ShellOut.new(command) + + cmd.run_command + + if cmd.exitstatus > 0 + return false + else + return true + end +end + +def pear_cmd(pear, action, package, force, channel, version) + if !discovered?(pear, channel) + discover = Mixlib::ShellOut.new("#{pear} channel-discover #{channel}") + discover.run_command + end + + # get the alias - BUT Y U NEED ALIAS?! - because when the channel is 'foo.example.org/pear' it screws up pear install + command_alias = "#{pear} channel-info #{channel}|grep -a Alias|awk '{print $2}'" + channel_alias = pear_run(command_alias) + if channel_alias.empty? + fail "Could not find alias for #{channel}" + end + Chef::Log.debug("Channel: #{channel}, Alias: #{channel_alias}") + + # avoid roundtrip to channel if it's installed + if action == 'install_if_missing' + p_count = pear_run("#{pear} list -c #{channel_alias}|grep -a #{package}|wc -l") + if p_count.to_i > 0 + Chef::Log.debug("PEAR package #{package} is already installed.") + return + end + action = "install" + end + + # force whatever comes next (probably a good idea) + f_param = "" + if force == true + f_param = " -f" + end + + # version string + version_str = "" + if version && !version.empty? + version_str = "-#{version}" + end + + complete_command = "#{pear} #{action}#{f_param} #{channel_alias}/#{package}#{version_str}" + execute "PEAR: run #{action}: #{complete_command}" do + command complete_command + end +end + +action :install do + pear_cmd(@pear_cmd, "install", new_resource.name, new_resource.force, new_resource.channel, new_resource.version) + new_resource.updated_by_last_action(true) +end + +action :uninstall do + pear_cmd(@pear_cmd, "uninstall", new_resource.name, new_resource.force, new_resource.channel, new_resource.version) + new_resource.updated_by_last_action(true) +end + +action :upgrade do + pear_cmd(@pear_cmd, "upgrade", new_resource.name, new_resource.force, new_resource.channel, new_resource.version) + new_resource.updated_by_last_action(true) +end + +action :install_if_missing do + pear_cmd(@pear_cmd, "install_if_missing", new_resource.name, new_resource.force, new_resource.channel, new_resource.version) + new_resource.updated_by_last_action(true) +end diff --git a/php-pear/recipes/default.rb b/php-pear/recipes/default.rb new file mode 100644 index 000000000..67e6b79b0 --- /dev/null +++ b/php-pear/recipes/default.rb @@ -0,0 +1,49 @@ +# +# Cookbook Name:: php-fpm +# Recipe:: default +# +# Copyright 2010-2012, Till Klampaeckel +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list +# of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this +# list of conditions and the following disclaimer in the documentation and/or other +# materials provided with the distribution. +# * The names of its contributors may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +pears = ["/usr/local/bin/pear", "/usr/bin/pear"] + +pears.each do |pear| + link pear do + to "#{node["php-fpm"]["prefix"]}/bin/pear" + end +end + +# fucking hack. remove when pear is newer than 1.9.4 +# see https://github.com/pear/pear-core/commit/8d569263eac91ad9484b45acb3a6381759138f3c#diff-b0dfa4abcb5cde685dae6b352ae38a17 +remote_file "/opt/easybib/pear/PEAR/REST.php" do + source "https://raw2.github.com/pear/pear-core/8d569263eac91ad9484b45acb3a6381759138f3c/PEAR/REST.php" + mode 0644 +end + +if !node["php-pear"]["packages"].empty? + include_recipe "php-pear::packages" +end diff --git a/php-pear/recipes/packages.rb b/php-pear/recipes/packages.rb new file mode 100644 index 000000000..6ffbea35b --- /dev/null +++ b/php-pear/recipes/packages.rb @@ -0,0 +1,49 @@ +# +# Cookbook Name:: php-pear +# Recipe:: packages +# +# Copyright 2010-2012, Till Klampaeckel +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, this list +# of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright notice, this +# list of conditions and the following disclaimer in the documentation and/or other +# materials provided with the distribution. +# * The names of its contributors may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# install packages +node["php-pear"]["packages"].each do |pear_package, pear_channel| + + version = "" + if !pear_package.index('-').nil? + attrs = pear_package.split('-') + pear_package, pear_version = attrs + end + + # Chef::Log.info("PACKAGE: #{package}, Version: #{version}, Channel: #{channel}") + + php_pear pear_package do + action :install_if_missing + channel pear_channel + force true + version pear_version + end +end diff --git a/php-pear/resources/pear.rb b/php-pear/resources/pear.rb new file mode 100644 index 000000000..6ecbdd9b7 --- /dev/null +++ b/php-pear/resources/pear.rb @@ -0,0 +1,8 @@ +actions :install, :uninstall, :upgrade, :install_if_missing + +default_action :install + +attribute :package, :kind_of => String, :name_attribute => true +attribute :channel, :kind_of => String, :default => 'pear.php.net' +attribute :version, :kind_of => String, :default => nil +attribute :force, :equal_to => [true, false], :default => false