Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Commit

Permalink
Optional reenabling of pear
Browse files Browse the repository at this point in the history
  • Loading branch information
fh committed Mar 7, 2014
1 parent de5480b commit b017715
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 0 deletions.
1 change: 1 addition & 0 deletions 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
1 change: 1 addition & 0 deletions easybib/metadata.rb
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions easybib/recipes/role-phpapp.rb
Expand Up @@ -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"
Expand Down
Empty file added php-pear/README.md
Empty file.
11 changes: 11 additions & 0 deletions 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"
}
11 changes: 11 additions & 0 deletions 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'
104 changes: 104 additions & 0 deletions 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
49 changes: 49 additions & 0 deletions 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
49 changes: 49 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions 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

0 comments on commit b017715

Please sign in to comment.