forked from puppetlabs/puppetlabs-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.pp
More file actions
128 lines (117 loc) · 4.29 KB
/
Copy pathinit.pp
File metadata and controls
128 lines (117 loc) · 4.29 KB
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
# Class: java
#
# This module manages the Java runtime package
#
# Parameters:
#
# [*distribution*]
# The java distribution to install. Can be one of "jdk" or "jre",
# or other platform-specific options where there are multiple
# implementations available (eg: OpenJDK vs Oracle JDK).
#
#
# [*version*]
# The version of java to install. By default, this module simply ensures
# that java is present, and does not require a specific version.
#
# [*package*]
# The name of the java package. This is configurable in case a non-standard
# java package is desired.
#
# [*java_alternative*]
# The name of the java alternative to use on Debian systems.
# "update-java-alternatives -l" will show which choices are available.
# If you specify a particular package, you will almost always also
# want to specify which java_alternative to choose. If you set
# this, you also need to set the path below.
#
# [*java_alternative_path*]
# The path to the "java" command on Debian systems. Since the
# alternatives system makes it difficult to verify which
# alternative is actually enabled, this is required to ensure the
# correct JVM is enabled.
#
# Actions:
#
# Requires:
#
# Sample Usage:
#
class java(
$distribution = 'jdk',
$version = 'present',
$package = undef,
$java_alternative = undef,
$java_alternative_path = undef
) {
include java::params
case $::osfamily {
default: {
validate_re($version, 'present|installed|latest|^[._0-9a-zA-Z:-]+$')
if has_key($java::params::java, $distribution) {
$default_package_name = $java::params::java[$distribution]['package']
$default_alternative = $java::params::java[$distribution]['alternative']
$default_alternative_path = $java::params::java[$distribution]['alternative_path']
} else {
fail("Java distribution ${distribution} is not supported.")
}
$use_java_package_name = $package ? {
default => $package,
undef => $default_package_name,
}
## If $java_alternative is set, use that.
## Elsif the DEFAULT package is being used, then use $default_alternative.
## Else undef
$use_java_alternative = $java_alternative ? {
default => $java_alternative,
undef => $use_java_package_name ? {
$default_package_name => $default_alternative,
default => undef,
}
}
## Same logic as $java_alternative above.
$use_java_alternative_path = $java_alternative_path ? {
default => $java_alternative_path,
undef => $use_java_package_name ? {
$default_package_name => $default_alternative_path,
default => undef,
}
}
anchor { 'java::begin:': }
->
package { 'java':
ensure => $version,
name => $use_java_package_name,
}
->
class { 'java::config': }
-> anchor { 'java::end': }
}
'windows': {
if $distribution == "jdk" {
fail("The JDK is currently unsupported for Windows via Puppet")
}
$sysdrive = $java::params::sysdrive
$bundleId = $java::params::java[$distribution]['package']
$jre_file = ".\java_install.exe"
$bundle_url = "http://javadl.sun.com/webapps/download/AutoDL?BundleId=${bundleId}"
exec { 'download_java':
command => "powershell -NoProfile -ExecutionPolicy remotesigned -command \"(new-object net.webclient).DownloadFile('${bundle_url}', '${jre_file}')\"",
path => "${sysdrive}\\windows\\system32;${sysdrive}\\windows\\system32\\WindowsPowerShell\\v1.0",
unless => "cmd.exe /c If NOT EXIST ${jre_file} Exit 1",
}
#
# We should check if we are running on Hyper-V server. If yes, then
# do not install the Java Web components, other wise, we probably should...
#
$web_java = 'WEB_JAVA=0'
exec { 'install_jre':
command => "cmd /c \"${jre_file} /s ${web_java}\"",
path => "${sysdrive}\\windows\\system32;${sysdrive}\\windows\\system32\\WindowsPowerShell\\v1.0",
require => Exec[ 'download_java' ],
unless => "cmd.exe /c If NOT EXIST \"${java::params::java_root_dir}\" Exit 1",
}
Exec['download_java'] -> Exec['install_jre']]
}
}
}