Last active
January 24, 2023 21:59
-
-
Save JSONOrona/d21b178bab399d713b53a172b243a858 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version = node['openjdk']['version'] | |
major_version = version.split(".")[0] | |
default['openjdk']['path'] = { | |
'windows' => "C:\\Program Files\\OpenJDK\\jdk-#{major_version}", | |
'rhel' => "/usr/lib/jvm/java-#{major_version}-openjdk-#{major_version}", | |
'fedora' => "/usr/lib/jvm/java-#{major_version}-openjdk-#{major_version}", | |
'amazon' => "/usr/lib/jvm/java-#{major_version}-openjdk-#{major_version}", | |
'debian' => "/usr/lib/jvm/java-#{major_version}-openjdk-amd64" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook:: myapp | |
# Recipe:: install_openjdk | |
# | |
# Copyright:: 2020, The Authors, All Rights Reserved. | |
openjdk_version = node['openjdk']['version'] | |
openjdk_path = node['openjdk']['path'][node['platform_family']] | |
openjdk_source = node['openjdk']['source'][node['platform_family']] | |
case node['platform_family'] | |
when 'windows' | |
# Find the appropriate OpenJDK package for the current version of Windows | |
openjdk_package_name = if node['kernel']['machine'] == 'x86_64' | |
"OpenJDK #{openjdk_version} (LTS) x64" | |
else | |
"OpenJDK #{openjdk_version} (LTS) x86" | |
end | |
# Install OpenJDK using the windows_package resource | |
windows_package openjdk_package_name do | |
source openjdk_source | |
installer_type :msi | |
action :install | |
end | |
# Adjust JAVA_HOME environment variable | |
windows_path openjdk_path do | |
action :add | |
end | |
when 'rhel', 'fedora', 'amazon' | |
package 'java-11-openjdk-devel' | |
package 'java-11-openjdk' | |
# Adjust JAVA_HOME environment variable | |
link '/etc/profile.d/java.sh' do | |
to openjdk_path | |
link_type :symbolic | |
end | |
file '/etc/profile.d/java.sh' do | |
content "export JAVA_HOME=#{openjdk_path}" | |
end | |
when 'debian' | |
package 'openjdk-11-jdk' | |
# Adjust JAVA_HOME environment variable | |
link '/etc/profile.d/java.sh' do | |
to openjdk_path | |
link_type :symbolic | |
end | |
file '/etc/profile.d/java.sh' do | |
content "export JAVA_HOME=#{openjdk_path}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated