From 0af235e9c0187667e4a27000bdaaa6028ad327e9 Mon Sep 17 00:00:00 2001 From: David Kinzer Date: Sat, 8 Nov 2014 15:05:43 -0500 Subject: [PATCH 1/7] Add Recompile PHP recipe. Sometimes the user wants to be able to simply recompile PHP for whatever reason. This recipe provides the user an out of the box way to do this task. --- recipes/recompile.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 recipes/recompile.rb diff --git a/recipes/recompile.rb b/recipes/recompile.rb new file mode 100644 index 000000000..7d9e313a0 --- /dev/null +++ b/recipes/recompile.rb @@ -0,0 +1,31 @@ +# +# Author:: David Kinzer () +# Cookbook Name:: php +# Recipe:: recompile +# +# Copyright 2014, David Kinzer +# +# 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. +# + +version = node['php']['version'] +configure_options = node['php']['configure_options'].join(' ') + +bash 're-build php' do + cwd Chef::Config[:file_cache_path] + code <<-EOF + (cd php-#{version} && make clean) + (cd php-#{version} && #{ext_dir_prefix} ./configure #{configure_options}) + (cd php-#{version} && make && make install) + EOF +end From 2473ca545dc14c3edac7568551ab33616e023de6 Mon Sep 17 00:00:00 2001 From: David Kinzer Date: Thu, 13 Nov 2014 15:56:48 -0500 Subject: [PATCH 2/7] Add extension directory. --- recipes/recompile.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes/recompile.rb b/recipes/recompile.rb index 7d9e313a0..c24d638bc 100644 --- a/recipes/recompile.rb +++ b/recipes/recompile.rb @@ -20,6 +20,7 @@ version = node['php']['version'] configure_options = node['php']['configure_options'].join(' ') +ext_dir_prefix = node['php']['ext_dir'] ? "EXTENSION_DIR=#{node['php']['ext_dir']}" : '' bash 're-build php' do cwd Chef::Config[:file_cache_path] From dae969ba6cef9b12f986f77d6ae74b3bd0e02e1e Mon Sep 17 00:00:00 2001 From: David Kinzer Date: Fri, 14 Nov 2014 09:55:47 -0500 Subject: [PATCH 3/7] Download source if necessary. Sometimes the reason we are recompiling is because we have a new version of PHP. --- recipes/recompile.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/recipes/recompile.rb b/recipes/recompile.rb index c24d638bc..bee60271e 100644 --- a/recipes/recompile.rb +++ b/recipes/recompile.rb @@ -22,6 +22,19 @@ configure_options = node['php']['configure_options'].join(' ') ext_dir_prefix = node['php']['ext_dir'] ? "EXTENSION_DIR=#{node['php']['ext_dir']}" : '' +node['php']['src_deps'].each do |pkg| + package pkg do + action :install + end +end + +remote_file "#{Chef::Config[:file_cache_path]}/php-#{version}.tar.gz" do + source "#{node['php']['url']}/php-#{version}.tar.gz/from/this/mirror" + checksum node['php']['checksum'] + mode '0644' + creates "#{Chef::Config[:file_cache_path]}/php-#{version}" +end + bash 're-build php' do cwd Chef::Config[:file_cache_path] code <<-EOF From 717f361c65ef034b0d126fef52e76915bff59207 Mon Sep 17 00:00:00 2001 From: David Kinzer Date: Fri, 14 Nov 2014 10:19:19 -0500 Subject: [PATCH 4/7] Fix guard. --- recipes/recompile.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/recompile.rb b/recipes/recompile.rb index bee60271e..5ac6683ad 100644 --- a/recipes/recompile.rb +++ b/recipes/recompile.rb @@ -32,7 +32,7 @@ source "#{node['php']['url']}/php-#{version}.tar.gz/from/this/mirror" checksum node['php']['checksum'] mode '0644' - creates "#{Chef::Config[:file_cache_path]}/php-#{version}" + not_if { ::File.directory?("#{Chef::Config[:file_cache_path]}/php-#{version}") } end bash 're-build php' do From 8e2ac6ddf3d9bb5e494b326818f9059eb3499593 Mon Sep 17 00:00:00 2001 From: David Kinzer Date: Fri, 14 Nov 2014 11:45:26 -0500 Subject: [PATCH 5/7] Add guard. --- recipes/recompile.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes/recompile.rb b/recipes/recompile.rb index 5ac6683ad..e98435752 100644 --- a/recipes/recompile.rb +++ b/recipes/recompile.rb @@ -42,4 +42,5 @@ (cd php-#{version} && #{ext_dir_prefix} ./configure #{configure_options}) (cd php-#{version} && make && make install) EOF + only_if { ::File.directory?("#{Chef::Config[:file_cache_path]}/php-#{version}") } end From d7500bc8289dcccf9c26c8390a112d890c281b59 Mon Sep 17 00:00:00 2001 From: David Kinzer Date: Fri, 14 Nov 2014 12:04:20 -0500 Subject: [PATCH 6/7] Remove guard and extract source. --- recipes/recompile.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/recipes/recompile.rb b/recipes/recompile.rb index e98435752..bf3201979 100644 --- a/recipes/recompile.rb +++ b/recipes/recompile.rb @@ -24,7 +24,7 @@ node['php']['src_deps'].each do |pkg| package pkg do - action :install + action 'install' end end @@ -32,15 +32,15 @@ source "#{node['php']['url']}/php-#{version}.tar.gz/from/this/mirror" checksum node['php']['checksum'] mode '0644' - not_if { ::File.directory?("#{Chef::Config[:file_cache_path]}/php-#{version}") } + action 'create_if_missing' end bash 're-build php' do cwd Chef::Config[:file_cache_path] code <<-EOF + tar -zxf php-#{version}.tar.gz (cd php-#{version} && make clean) (cd php-#{version} && #{ext_dir_prefix} ./configure #{configure_options}) (cd php-#{version} && make && make install) EOF - only_if { ::File.directory?("#{Chef::Config[:file_cache_path]}/php-#{version}") } end From 0b639535ab88cc02e851d4036cf24d789c944c2a Mon Sep 17 00:00:00 2001 From: David Kinzer Date: Fri, 14 Nov 2014 15:42:24 -0500 Subject: [PATCH 7/7] Separate unpacking and building. In case PHP source has already been unpacked in a previous instance there is no need to unpack it again. --- recipes/recompile.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/recipes/recompile.rb b/recipes/recompile.rb index bf3201979..1a090cd91 100644 --- a/recipes/recompile.rb +++ b/recipes/recompile.rb @@ -35,12 +35,17 @@ action 'create_if_missing' end -bash 're-build php' do +bash 'un-pack php' do cwd Chef::Config[:file_cache_path] + code "tar -zxf php-#{version}.tar.gz" + creates "#{node['php']['url']}/php-#{version}" +end + +bash 're-build php' do + cwd "#{Chef::Config[:file_cache_path]}/php-#{version}" code <<-EOF - tar -zxf php-#{version}.tar.gz - (cd php-#{version} && make clean) - (cd php-#{version} && #{ext_dir_prefix} ./configure #{configure_options}) - (cd php-#{version} && make && make install) + (make clean) + (#{ext_dir_prefix} ./configure #{configure_options}) + (make && make install) EOF end