OSDN Git Service

add source build installation recipe of the Protocol Buffers.
authorwhitestar <whitestar@gaea.test>
Sat, 31 Aug 2013 06:07:10 +0000 (15:07 +0900)
committerwhitestar <whitestar@gaea.test>
Sat, 31 Aug 2013 06:07:10 +0000 (15:07 +0900)
cookbooks/protobuf-compiler/attributes/default.rb
cookbooks/protobuf-compiler/recipes/default.rb
roles/hadoop-build.rb
roles/protobuf-compiler.rb

index 697c5b1..580d9bf 100644 (file)
@@ -20,4 +20,5 @@
 default['protobuf-compiler']['install_flavor'] = 'google'  # 'google'|'package'
 default['protobuf-compiler']['version'] = '2.5.0'
 default['protobuf-compiler']['archive_url'] = 'https://protobuf.googlecode.com/files'
+default['protobuf-compiler']['src_path'] = '/usr/local/src'
 
index 2cbc287..9223080 100644 (file)
 # limitations under the License.
 #
 
+require 'digest/sha1'
+
+tarball_sha1s = {
+  '2.5.0' => '7f6ea7bc1382202fb1ce8c6933f1ef8fea0c0148',
+  '2.4.1' => 'efc84249525007b1e3105084ea27e3273f7cbfb0',
+  '2.3.0' => 'd0e7472552e5c352ed0afbb07b30dcb343c96aaf',
+}
+
+packages = nil
+
+deb_packages = [
+  'tar',
+  'build-essential',
+  'autoconf',
+  'libtool'
+]
+
+rpm_packages = [
+  'tar',
+  'autoconf',
+  'automake',
+  'libtool'
+]
+
+case node[:platform_family]
+when 'debian'
+  packages = deb_packages
+when 'rhel'
+  packages = rpm_packages
+end
+
 flavor = node['protobuf-compiler']['install_flavor']
 case flavor
 when 'package'
@@ -24,7 +55,51 @@ when 'package'
     action :install
   end
 when 'google'
-  # TODO:
+  src_path = node['protobuf-compiler']['src_path']
+  version = node['protobuf-compiler']['version']
+  tarball = "protobuf-#{version}.tar.gz"
+  downloaded_tarball = "#{src_path}/#{tarball}"
+  
+  archive_url = node['protobuf-compiler']['archive_url']
+  if ! FileTest.directory? "#{src_path}/protobuf-#{version}" then
+    remote_file downloaded_tarball do
+      source "#{archive_url}/#{tarball}"
+      action :create_if_missing
+    end
+  
+    ruby_block "sha1 checksum #{downloaded_tarball}" do
+      block do
+        checksum = tarball_sha1s[version]
+        Chef::Log.info "#{tarball}: SHA1 = #{checksum}"
+        actual_checksum = Digest::SHA1.file(downloaded_tarball).to_s
+        Chef::Log.info "#{tarball}: actual SHA1 = #{actual_checksum}"
+        if ! checksum.casecmp(actual_checksum) then
+          Chef::Application.fatal!("Invalid SHA1 checksum of #{downloaded_tarball}, expected: #{checksum}")
+        end
+      end
+      action :create
+    end
+  
+    packages.each {|pkg|
+      resources(:package => pkg) rescue package pkg do
+        action :install
+      end
+    }
+  
+    bash "install_protobuf-#{version}" do
+      cwd src_path
+      code <<-EOC
+        tar xvzf #{downloaded_tarball}
+        cd protobuf-#{version}
+        ./configure
+        make install
+        ldconfig
+      EOC
+      creates "#{src_path}/protobuf-#{version}"
+    end
+  else
+    log "#{src_path}: protobuf-#{version} already installed. "
+  end
 else
   Chef::Application.fatal!("Non supported flavor: #{flavor}")
 end
index c6655c1..08cbba9 100644 (file)
@@ -4,9 +4,9 @@ description 'Hadoop Build Environment.'
 run_list(
   'role[apt]',
   'recipe[hadoop::build]',
-  'role[java]',
+  'role[java]',  # default: Oracle JDK installation.
   'role[maven]',
-  #'role[protobuf-compiler]',  # default: package installation
+  #'role[protobuf-compiler]',  # default: package installation.
   'recipe[protobuf-compiler]',
 )
 
@@ -20,11 +20,11 @@ default_attributes(
     'jdk_version' => '6'
   },
   'maven' => {
-    'install_flavor' => 'apache',
+    'install_flavor' => 'apache',  # tarball installation.
     'version' => '3.0.5'
   },
   'protobuf-compiler' => {
-    'install_flavor' => 'google',
+    'install_flavor' => 'google',  # source build installation.
     'version' => '2.5.0'
   },
 )
index 9b580b1..5fa6ae5 100644 (file)
@@ -11,6 +11,8 @@ run_list(
 default_attributes(
   'protobuf-compiler' => {
     'install_flavor' => 'package'
+    #'install_flavor' => 'google',  # source build installation.
+    #'version' => '2.5.0'
   }
 )