Monday, January 27, 2014

Java download without authentication and java chef recipe by bash

1. Downloading oracle java
root@knife2:/home/young/chef-repo# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com" http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.tar.gz


# Very simple recipe that needs local web server. I used apache2
#default.rb

#

#
# Cookbook Name:: java
# Recipe:: default
# Author:: ohyoungjooung@gmail.com
# Copyright 2014, My Future Company
#
# All rights reserved - Do Not Redistribute
#
bash "install_java" do
     user "root"
     cwd "/tmp"
     code <<-EOH
      rm -rf /tmp/jdk*
      echo $?
      apt-get -y autoremove
      rm -f /usr/bin/java
      apt-get -y install wget
      # From local network apache webserver
      wget http://192.168.56.105/jdk-7u51-linux-x64.tar.gz
      if [[ $? != "0" ]]
      then
         echo "wget java file failed"
         exit 1
      fi
      tar xvzf jdk-7u51-linux-x64.tar.gz
      #backup old java
      if [[ -d /usr/local/java ]]
      then
        /bin/rm -rf /usr/local/java
      fi
 
      mv jdk1.7.0_51 /usr/local/java
      `grep /usr/local/java/bin /etc/profile`
      if [[ $? != "0" ]]
      then
      echo 'export PATH=/usr/local/java/bin:$PATH' >> /etc/profile
      echo 'export JAVA_HOME=/usr/local/java' >> /etc/profile
      fi
      /bin/rm -f jdk*
     EOH
end
~                                                                                                                                  
~                                        


root@chef-client2:~# chef-client -o java
Starting Chef Client, version 11.8.2
[2014-01-27T03:58:45+09:00] WARN: Run List override has been provided.
[2014-01-27T03:58:45+09:00] WARN: Original Run List: [recipe[mysql::server]]
[2014-01-27T03:58:45+09:00] WARN: Overridden Run List: [recipe[java]]
resolving cookbooks for run list: ["java"]
Synchronizing Cookbooks:
  - java
Compiling Cookbooks...
Converging 1 resources
Recipe: java::default
  * bash[install_java] action run
    - execute "bash"  "/tmp/chef-script20140127-11663-1am5mk9"

Chef Client finished, 1 resources updated
root@chef-client2:~# ls /tmp/
hsperfdata_chef_server  hsperfdata_root  opt  stderr
root@chef-client2:~# echo $PATH
/usr/local/java/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@chef-client2:~# java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
root@chef-client2:~# 
~                               

No comments:

Post a Comment