Sometimes (yes it does happen), you need to install the JDK from SUN automatically (without having to answer yes/no to the license). Why? For example in a Kick Start script to auto-install the JDK.
And so to do this, here a bash & perl script for this exact purpose. This script works only with the .bin install package that you download from SUN’s website.
#!/bin/bash jdkBinFile=$1 echo $1 # just spew out the agreement perl -p -i -e 's/^more/cat/g' $1 # set the 'agreed' value for jdk 1.5 perl -p -i -e 's/\s+agreed=$/agreed=1/g' $1 # set the agree value for jdk 1.6 perl -p -i -e 's/`agree`/yes/g' $1 # do not call the register_jdk method perl -p -i -e 's/\s+register_JDK/#register_JDK/g' $1 # and now run the installation bash $1
How to
Create a new script file called autoinstall.sh containing the above script. and run it as follows:
$ cd /install/to/directory $ autoinstall.sh /my/downloads/jdk-6u16-linux-x64.bin
#1 by magnet on November 26th, 2009
Quote
thanks for that usefull tips !
I tried to do the same thing, but I had to modify the checksum or it didn’t wanted to install. any idea why you don’t need to do it ?
#2 by srasul on December 10th, 2009
Quote
I would need details on how you did “your way” to find out why the checksum didnt work.
#3 by meteor on August 20th, 2010
Quote
thanks a lot
#4 by Scot Rhodes on March 26th, 2012
Quote
Just tried this with a kickstart script on CentOS 6.2, and it worked like a charm! This was very helpful and saved me a lot of time. Just in case someone else wants to give it a shot, I’ll share my chunk of %post kickstart script that I used.
# Create Java auto installer.
########################################################################
cat > /tmp/autoinstaller.sh << EOF
#!/bin/bash
jdkBinFile=\$1
echo \$1
# just spew out the agreement
perl -p -i -e 's/^more/cat/g' \$1
# set the 'agreed' value for jdk 1.5
perl -p -i -e 's/\s+agreed=$/agreed=1/g' \$1
# set the agree value for jdk 1.6
perl -p -i -e 's/\`agree\`/yes/g' \$1
# do not call the register_jdk method
perl -p -i -e 's/\s+register_JDK/#register_JDK/g' \$1
# and now run the installation
bash \$1
EOF
chmod 755 /tmp/autoinstaller.sh
# Download and install Java JDK 1.6 (This must be moved to a primary server).
########################################################################
wget http:///jdk-6u24-linux-x64.bin
mkdir /usr/java
mv jdk-6u24-linux-x64.bin /usr/java
cd /usr/java
chmod 755 jdk-6u24-linux-x64.bin
/tmp/autoinstaller.sh jdk-6u24-linux-x64.bin
echo ”
export JAVA_HOME=/usr/java/jdk1.6.0_24
export PATH=\$JAVA_HOME/bin:\$PATH
” >> /etc/profile
source /etc/profile
rm -rf jdk-6u24-linux-x64.bin;
alternatives –install /usr/bin/java java $JAVA_HOME/bin/java 2
alternatives –set java $JAVA_HOME/bin/java
#5 by Scot Rhodes on March 26th, 2012
Quote
The angle bracketed comment was wiped, make sure you point the wget command to a location you can access via HTTP.
Trackback: JavaPins