Skip to content

Commit

Permalink
current oracle java with proper alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
kosarko committed Jun 25, 2015
1 parent 1c15119 commit f813251
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 4 deletions.
3 changes: 3 additions & 0 deletions hieradata/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ my::packages_no_conf:
- mc
- screen
- sshfs
- tree
- htop
- iftop
Binary file modified manifests/.first.pp.swp
Binary file not shown.
22 changes: 21 additions & 1 deletion manifests/first.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Globals
Exec {path => ["/usr/local/sbin", "/usr/local/bin", "/usr/sbin", "/usr/bin", "/sbin", "/bin"]}

exec { 'apt-update':
command => '/usr/bin/apt-get update'
}
Expand Down Expand Up @@ -25,9 +28,26 @@
require => File['/opt/sources'],
}

##### SUN JAVA
class { 'jdk_oracle':
ensure => installed,
version => '8',
install_dir => '/installations/java',
version_update => '45',
version_build => '14',
install_dir => '/usr/lib/jvm',
default_java => false, #this seems broken and incomplete, use own script on ubuntu
require => File['/installations'],
}

$jdk_alias = "jdk1.8.0_45"
exec { 'generate-jinfo':
command => "sudo ${::settings::modulepath}/scripts/generate-jinfo.sh $jdk_alias",
require => Class['jdk_oracle'],
creates => "/usr/lib/jvm/.${jdk_alias}.jinfo",
}

exec { 'update-java-alternatives':
command => "update-java-alternatives -s $jdk_alias",
require => Exec["generate-jinfo"],
user => 'root',
}
4 changes: 2 additions & 2 deletions modules/jdk_oracle/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
$ensure = 'installed'
) {

$default_8_update = '11'
$default_8_build = '12'
$default_8_update = '45'
$default_8_build = '14'
$default_7_update = '67'
$default_7_build = '01'
$default_6_update = '45'
Expand Down
Binary file not shown.
110 changes: 110 additions & 0 deletions modules/scripts/generate-jinfo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env bash
# ----------------------------------------------------------------------
# http://hostcode.sourceforge.net/view/367
# Description
# Setup a Java JDK with the alternatives system.
#
# Usage
# To setup the alternatives system:
# $ sudo ./configure-java.sh <jdk alias>
#
# To set the configured JDK as the system default one, you can then run:
# $ sudo update-java-alternatives -s <jdk alias>
#
# Prerequisites
# /usr/lib/jvm/<jdk alias> must point to the JDK to setup.
#
# ----------------------------------------------------------------------


# ----------------------------------------------------------------------
# Constants
# ----------------------------------------------------------------------

JDK_ALIAS=$1 # Set it from command prompt
JDK_DIRECTORY=/usr/lib/jvm/$JDK_ALIAS
JDK_ALTERNATIVE_PRORITY=1
JINFO_FILE=/usr/lib/jvm/.$JDK_ALIAS.jinfo


# ----------------------------------------------------------------------
# Functions
# ----------------------------------------------------------------------

# Check the execution rights.
check_rights()
{
if [[ $USER != 'root' ]]; then
echo "Error: You must run this script as root."
exit 1
fi
}

# Check that $JDK_DIRECTORY contains a Java JDK
check_jdk()
{
if [[ ! -e $JDK_DIRECTORY ]] && [[ ! -e $JDK_DIRECTORY/jre/bin/java ]] && [[ ! -e $JDK_DIRECTORY/bin/java ]] ; then
echo "Error: '$JDK_DIRECTORY' must point to a valid Java JDK home."
exit 1
fi
}

# Register the JRE executable.
setup_jre_alternative()
{
update-alternatives --verbose --install /usr/bin/$1 $1 $JDK_DIRECTORY/jre/bin/$1 $JDK_ALTERNATIVE_PRORITY
echo "jre $1 $JDK_DIRECTORY/jre/bin/$1" >> $JINFO_FILE
}

# Register the JDK executable.
setup_jdk_alternative()
{
update-alternatives --verbose --install /usr/bin/$1 $1 $JDK_DIRECTORY/bin/$1 $JDK_ALTERNATIVE_PRORITY
echo "jdk $1 $JDK_DIRECTORY/bin/$1" >> $JINFO_FILE
}

# Start the .jinfo file.
generate_jinfo_header()
{
echo "name=$JDK_ALIAS" > $JINFO_FILE
echo "alias=$JDK_ALIAS" >> $JINFO_FILE
echo "priority=$JDK_ALTERNATIVE_PRORITY" >> $JINFO_FILE
echo "section=non-free" >> $JINFO_FILE
echo "" >> $JINFO_FILE
}

register_all_executables()
{
files=`ls -1 ${JDK_DIRECTORY}/bin`
for f in ${files}
do
setup_jdk_alternative ${f}
done
}


# ----------------------------------------------------------------------
# Main
# ----------------------------------------------------------------------

# Check execution rights.
check_rights

# Check that there is a JDK at the right place.
check_jdk

# Generate a .jinfo file for the update-java-alternatives command.
generate_jinfo_header

# Register the executables with the alternatives system.
register_all_executables

# Log a message about the jinfo file.
echo "The file '$JINFO_FILE' containing metadatas used by the 'update-java-alternatives' command has been generated."

# TODO: Run the cat command below
# http://www.nick-prosch.de/?p=4228
# nick@silentbox /usr/lib/jvm $ cat .jdk1.6.31.jinfo | grep -E '^(jre|jdk)' | awk '{print "/usr/bin/" $2 " " $2 " " $3 " 30 \n"}' | xargs -t -n4 sudo update-alternatives --verbose --install
# nick@silentbox /usr/lib/jvm $ sudo update-alternatives --verbose --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /opt/jdk1.6.31/jre/lib/amd64/libnpjp2.so 30
# nick@silentbox /usr/lib/jvm $ sudo update-alternatives --verbose --install /usr/lib/xulrunner-addons/plugins/libjavaplugin.so xulrunner-1.9-javaplugin.so /opt/jdk1.6.31/jre/lib/amd64/libnpjp2.so 30

1 change: 1 addition & 0 deletions puppet.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[main]
hiera_config=./hiera.yaml
modulepath=./modules
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
puppet apply manifests/first.pp --config $(dirname $0)/puppet.conf --modulepath ./modules "$@"
puppet apply manifests/first.pp --config $(dirname $0)/puppet.conf "$@"

0 comments on commit f813251

Please sign in to comment.