|
| 1 | +# Cookbook Name:: java |
| 2 | +# Recipe:: ibm_tar |
| 3 | +# |
| 4 | +# Copyright 2013, Opscode, Inc. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +require 'uri' |
| 19 | + |
| 20 | +source_url = node['java']['ibm']['url'] |
| 21 | +jdk_uri = ::URI.parse(source_url) |
| 22 | +jdk_filename = ::File.basename(jdk_uri.path) |
| 23 | + |
| 24 | +unless valid_ibm_jdk_uri?(source_url) |
| 25 | + raise "You must set the attribute `node['java']['ibm']['url']` to a valid URI" |
| 26 | +end |
| 27 | + |
| 28 | +unless jdk_filename =~ /\.(tar.gz|tgz)$/ |
| 29 | + raise "The attribute `node['java']['ibm']['url']` must specify a .tar.gz file" |
| 30 | +end |
| 31 | + |
| 32 | +remote_file "#{Chef::Config[:file_cache_path]}/#{jdk_filename}" do |
| 33 | + source source_url |
| 34 | + mode 00755 |
| 35 | + if node['java']['ibm']['checksum'] |
| 36 | + checksum node['java']['ibm']['checksum'] |
| 37 | + action :create |
| 38 | + else |
| 39 | + action :create_if_missing |
| 40 | + end |
| 41 | + notifies :create, "directory[create-java-home]", :immediately |
| 42 | + notifies :run, "execute[untar-ibm-java]", :immediately |
| 43 | +end |
| 44 | + |
| 45 | +directory "create-java-home" do |
| 46 | + path node['java']['java_home'] |
| 47 | + mode 00755 |
| 48 | + recursive true |
| 49 | +end |
| 50 | + |
| 51 | +execute "untar-ibm-java" do |
| 52 | + cwd Chef::Config[:file_cache_path] |
| 53 | + command "tar xzf ./#{jdk_filename} -C #{node['java']['java_home']} --strip 1" |
| 54 | + creates "#{node['java']['java_home']}/jre/bin/java" |
| 55 | +end |
| 56 | + |
| 57 | +include_recipe "java::set_java_home" |
0 commit comments