-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathphp_meal.rb
236 lines (201 loc) · 6.09 KB
/
php_meal.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# encoding: utf-8
require_relative 'php_common_recipes'
require_relative 'php_recipe'
class PhpMeal
attr_reader :name, :version
def initialize(name, version, options)
@name = name
@version = version
version_parts = version.split('.')
@major_version = version_parts[0]
@minor_version = version_parts[1]
@options = options
@native_modules = []
@extensions = []
create_native_module_recipes
create_extension_recipes
(@native_modules + @extensions).each do |recipe|
recipe.instance_variable_set('@php_path', php_recipe.path)
recipe.instance_variable_set('@php_source', "#{php_recipe.send(:tmp_path)}/php-#{@version}")
if recipe.is_a? FakePeclRecipe
recipe.instance_variable_set('@version', @version)
recipe.instance_variable_set('@files', [{url: recipe.url, md5: nil}])
end
end
end
def cook
system <<-eof
DIFF=$(expr $(date +'%s') - $(date -r /tmp/apt-last-updated +'%s'))
if [ -z $DIFF ] || [ $DIFF -gt 86400 ]; then
apt-get update
apt-get -y upgrade
apt-get -y install #{apt_packages}
touch /tmp/apt-last-updated
fi
#{install_libuv}
#{symlink_commands}
eof
if OraclePeclRecipe.oracle_sdk?
Dir.chdir('/oracle') do
system "ln -s libclntsh.so.* libclntsh.so"
end
end
php_recipe.cook
php_recipe.activate
# native libraries
@native_modules.each do |recipe|
recipe.cook
end
# php extensions
@extensions.each do |recipe|
recipe.cook if should_cook?(recipe)
end
end
def url
php_recipe.url
end
def archive_files
php_recipe.archive_files
end
def archive_path_name
php_recipe.archive_path_name
end
def archive_filename
php_recipe.archive_filename
end
def setup_tar
php_recipe.setup_tar
if OraclePeclRecipe.oracle_sdk?
@extensions.detect{|r| r.name=='oci8'}.setup_tar
@extensions.detect{|r| r.name=='pdo_oci'}.setup_tar
end
@extensions.detect{|r| r.name=='odbc'}&.setup_tar
@extensions.detect{|r| r.name=='pdo_odbc'}&.setup_tar
@extensions.detect{|r| r.name=='sodium'}&.setup_tar
end
private
def create_native_module_recipes
return unless @options[:php_extensions_file]
php_extensions_hash = YAML.load_file(@options[:php_extensions_file])
php_extensions_hash['native_modules'].each do |hash|
klass = Kernel.const_get(hash['klass'])
@native_modules << klass.new(
hash['name'],
hash['version'],
md5: hash['md5']
)
end
end
def create_extension_recipes
return unless @options[:php_extensions_file]
php_extensions_hash = YAML.load_file(@options[:php_extensions_file])
php_extensions_hash['extensions'].each do |hash|
klass = Kernel.const_get(hash['klass'])
@extensions << klass.new(
hash['name'],
hash['version'],
md5: hash['md5']
)
end
@extensions.each do |recipe|
case recipe.name
when 'amqp'
recipe.instance_variable_set('@rabbitmq_path', @native_modules.detect{|r| r.name=='rabbitmq'}.work_path)
when 'lua'
recipe.instance_variable_set('@lua_path', @native_modules.detect{|r| r.name=='lua'}.path)
when 'phpiredis'
recipe.instance_variable_set('@hiredis_path', @native_modules.detect{|r| r.name=='hiredis'}.path)
when 'sodium'
recipe.instance_variable_set('@libsodium_path', @native_modules.detect{|r| r.name=='libsodium'}.path)
end
end
end
def apt_packages
%w(automake
firebird-dev
libaspell-dev
libc-client2007e-dev
libcurl4-openssl-dev
libedit-dev
libenchant-dev
libexpat1-dev
libgd-dev
libgdbm-dev
libgeoip-dev
libgmp-dev
libgpgme11-dev
libjpeg-dev
libkrb5-dev
libldap2-dev
libmaxminddb-dev
libmcrypt-dev
libmemcached-dev
libonig-dev
libpng-dev
libpspell-dev
librecode-dev
libsasl2-dev
libsnmp-dev
libsqlite3-dev
libssh2-1-dev
libssl-dev
libtidy-dev
libtool
libwebp-dev
libxml2-dev
libzip-dev
libzookeeper-mt-dev
snmp-mibs-downloader
unixodbc-dev).join(" ")
end
def install_libuv
%q((
if [ "$(pkg-config libuv --print-provides | awk '{print $3}')" != "1.12.0" ]; then
cd /tmp
wget http://dist.libuv.org/dist/v1.12.0/libuv-v1.12.0.tar.gz
tar zxf libuv-v1.12.0.tar.gz
cd libuv-v1.12.0
sh autogen.sh
./configure
make install
fi
)
)
end
def symlink_commands
[ "sudo ln -s /usr/include/x86_64-linux-gnu/curl /usr/local/include/curl",
"sudo ln -fs /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h",
"sudo ln -fs /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so",
"sudo ln -fs /usr/lib/x86_64-linux-gnu/libldap_r.so /usr/lib/libldap_r.so"].join("\n")
end
def should_cook?(recipe)
case recipe.name
when 'ioncube'
IonCubeRecipe.build_ioncube?(version)
when 'oci8', 'pdo_oci'
OraclePeclRecipe.oracle_sdk?
else
true
end
end
def files_hashs
native_module_hashes = @native_modules.map do |recipe|
recipe.send(:files_hashs)
end.flatten
extension_hashes = @extensions.map do |recipe|
recipe.send(:files_hashs) if should_cook?(recipe)
end.flatten.compact
extension_hashes + native_module_hashes
end
def php_recipe
php_recipe_options = {}
hiredis_recipe = @native_modules.detect{|r| r.name=='hiredis'}
libmemcached_recipe = @native_modules.detect{|r| r.name=='libmemcached'}
ioncube_recipe = @extensions.detect{|r| r.name=='ioncube'}
php_recipe_options[:hiredis_path] = hiredis_recipe.path unless hiredis_recipe.nil?
php_recipe_options[:libmemcached_path] = libmemcached_recipe.path unless libmemcached_recipe.nil?
php_recipe_options[:ioncube_path] = ioncube_recipe.path unless ioncube_recipe.nil?
php_recipe_options.merge(DetermineChecksum.new(@options).to_h)
@php_recipe ||= PhpRecipe.new(@name, @version, php_recipe_options)
end
end