Permalink
Browse files

initial and very simple JRE/JDK download recipie

  • Loading branch information...
1 parent 95e69c0 commit ce05083fd807a5219e8d32b200bf501354d74752 @ktoso ktoso committed Jul 10, 2011
Showing with 32 additions and 1 deletion.
  1. +1 −0 cookbooks/java/metadata.rb
  2. +30 −0 cookbooks/java/recipes/default.rb
  3. +1 −1 roles/javadev.rb
@@ -0,0 +1 @@
+description "Installs Sun (Oracle) JVM and JDK (1.6)"
@@ -0,0 +1,30 @@
+bash "Install Oracle JDK 6" do
+ user "root"
+ cwd "/usr/lib"
+ code <<-EOH
+ mkdir -p jvm
+ cd jvm
+ wget -O jdk.bin -c http://download.oracle.com/otn-pub/java/jdk/6u26-b03/jdk-6u26-linux-x64.bin
+ chmod +x jdk.bin
+ ./jdk.bin
+ rm jdk.bin
+ EOH
+end
+
+bash "Install Oracle JRE 6" do
+ user "root"
+ cwd "/usr/lib"
+ code <<-EOH
+ mkdir -p jvm
+ cd jvm
+ wget -O jre.bin -c http://download.oracle.com/otn-pub/java/jdk/6u26-b03/jre-6u26-linux-x64.bin
+ chmod +x jre.bin
+ ./jre.bin
+ rm jre.bin
+ EOH
+end
+
+# todo somehow get the user which started this process (his $HOME) and do:
@ktoso

ktoso Jul 10, 2011

Contributor

Any ideas how to resolve this issue?
I can't use bash/script because they require declaring the user etc. Didn't spend too much time on looking into this matter though, comments are welcome.

@sickill

sickill Jul 10, 2011

Contributor

Maybe sth like this?

bash "export JAVA_HOME in .bash_profile" do
  code %(su -l -c 'echo "export JAVA_HOME=\'/usr/lib/jvm/jdk1.6.0_26\'" >>~/.bash_profile' #{ENV['SUDO_USER']})
  not_if %(su -l -c 'grep JAVA_HOME ~/.bash_profile' #{ENV['SUDO_USER']})
end
@sickill

sickill Jul 10, 2011

Contributor

Theoretically you could use following:

bash "..." do
  user ENV['SUDO_USER']
  code %(echo "export JAVA_HOME='/usr/lib/jvm/jdk1.6.0_26'" >>~/.bash_profile)
  not_if "..."
end

but it does "su" without --login option so user profile is not loaded and HOME stays "/root", which we don't want.

@sickill

sickill Jul 10, 2011

Contributor

Above problem is related to this chef improvement request: http://tickets.opscode.com/browse/CHEF-2288

@ktoso

ktoso Jul 11, 2011

Contributor

I think i have a clean and nice sollution, will commit it soon:

require 'etc'

login = Etc.getlogin
home = Etc.getpwnam(login).dir
open(home + '/.bash_profile', 'a') do |f|
  f << "JAVA_HOME = ..."
end

:-)

BUT! I've found that maybe it'll be better to set this in /etc/profile and I'll probably do so in the end.

@sickill

sickill Jul 11, 2011

Contributor

Cool, didn't know about this 'etc' gem. Is it in ruby standard library?

Btw, when writing chef recipes for lunar-station have in mind it should also work on OSX ;) Not a requirement here for "javadev" role but would be nice for all common cookbooks.

@ktoso

ktoso Jul 11, 2011

Contributor

Yup, I'll ask ags how one usually installs JVM on a mac and add it.
Etc is in fact a standard lib: http://www.ruby-doc.org/stdlib/libdoc/etc/rdoc/index.html

@sickill

sickill Jul 11, 2011

Contributor

Btw, don't put this ruby code straight in cookbook file as it will be evaluated when cookbooks are loaded, not when they're invoked - we don't want that.
You should do it this way:

ruby_block "export JVM_PATH" do
  block do
    <above ruby code>
  end
end
@ktoso

ktoso Jul 12, 2011

Contributor

Ok ok, will do this soon - got some free time now.

+#open("#{HOME}/.bash_profile", "a") do |f|
+# f.puts "export JAVA_HOME='/usr/lib/jvm/jdk1.6.0_26'"
+#end
View
@@ -1,3 +1,3 @@
description 'LLP Java developer workstation'
-run_list 'role[base]', 'recipe[mysql]'
+run_list 'role[base]', 'recipe[mysql]', 'recipe[java]'

0 comments on commit ce05083

Please sign in to comment.