A: This script runs the machine, Linux
B: The machine that installs the JDK, Linux
First, on machine A on which the script runs, determine that you can log on to machine B on the JDK by SSH without a password, and then you can run this script on a:
Copy Code code as follows:
Or
Copy Code code as follows:
$./install-jdk.sh "B's IP" "JDK's uri"
You can install the JDK on machine B. The tar package used by JDK requires the user to set default_jdk_src=? To ensure that wget can be obtained. Here are the full script contents:
Copy Code code as follows:
#!/bin/bash
#
# @file
# install-jdk.sh
#
# @date
# 2013-12-19
#
# @author
# Cheungmine
#
# @version
# 0.0.1pre
#
# @usage:
#./install-jdk.sh 192.168.122.206
#
################################################################################
. common.sh
#***********************************************************
# INSTALL_JDK
# Install JDK on machine:/usr/local/lib
#
# Parameters:
# MACHINE-ROOT@IPADDR
# Jdkuri-uri for fetching Tarball
#
# Example:
#
# INSTALL_JDK root@192.168.122.206 ftp://vm-ftp/pub/tarball/jdk-7u67-linux-x64.tar.gz
#
#***********************************************************
. common.sh
# You might the change BELOW line to get YOUR JDK tarball:
Default_jdk_src= "Ftp://vm-ftp/pub/tarball/jdk-7u67-linux-x64.tar.gz"
# do don't change BELOW two LINES:
Install_dir= "/usr/local/lib/java"
Local_dir= "./.tmp"
function Install_jdk () {
Echo-e "<INFO> install JDK on machine: $"
Local dest_login=$1
Local jdk_uri=$2
Local tar=$ (basename $JDK _uri)
Echo-e "<INFO> jdk: ' $JDK _uri '"
Wget-c $JDK _uri-p $LOCAL _dir-o $LOCAL _dir/$TAR
$ (is_empty_dir "$LOCAL _dir/jdk_untar")
Local ret=$?
Case $ret in
$DIR _not_existed)
Mkdir-p $LOCAL _dir/jdk_untar
;;
$DIR _is_empty)
;;
$DIR _not_empty)
RM-RF $LOCAL _dir/jdk_untar/*
;;
*)
Exit $ERR _fatal_error
;;
Esac
# Untar to Jdk_untar
TAR-ZXF $LOCAL _dir/$TAR-C $LOCAL _dir/jdk_untar
$ (is_empty_dir "$LOCAL _dir/jdk_untar")
Local ret=$?
If ["$ret"-eq "$DIR _not_empty"]; Then
Local jdk_home= ' ls $LOCAL _dir/jdk_untar 2>/dev/null '
Echo $JDK _home
Else
Exit $ERR _fatal_error
Fi
Echo-e "<INFO> Create folder on: $DEST _login: $INSTALL _dir"
Local ret= ' ssh $DEST _login ' mkdir $INSTALL _dir '
Echo-e "<INFO> copy $jdk _home/to: $DEST _login: $INSTALL _dir/"
Local ret= ' scp-r $LOCAL _dir/jdk_untar/$jdk _home $DEST _login: $INSTALL _dir '
# Remove Local tar
RM-RF $LOCAL _dir/jdk_untar
Local dest_java_home= $INSTALL _dir/$jdk _home
Echo-e "<TODO> remove old settings for INSTALL_JDK in/etc/profile"
Echo-e "<INFO> set/etc/profile:java_home= $DEST _java_home"
Local ret= ' ssh $DEST _login ' echo ' >>/etc/profile '
Local ret= ' ssh $DEST _login ' echo ' #! {{install_jdk@hgdb.net==> ' >>/etc/profile '
Local ret= ' ssh $DEST _login ' echo ' Export java_home= $DEST _java_home ' >>/etc/profile '
Local ret= ' ssh $DEST _login ' echo ' Export classpath=.:\ \ $JAVA _home/lib/tools.jar:\\ $JAVA _home/lib/dt.jar ' >>/etc/profile '
Local ret= ' ssh $DEST _login ' echo ' export path=\\ $JAVA _home/bin:\\ $JAVA _home/jre/bin:\\ $PATH ' >>/etc/profile '
Local ret= ' ssh $DEST _login ' echo ' #!<==install_jdk@hgdb.net}} ' >>/etc/profile '
Local ret= ' ssh $DEST _login '. /etc/profile "'
}
function Uninstall_jdk () {
Echo-e "<TODO> uninstall JDK from: $"
}
#=======================================================================
#----Main ()----
If [-N $]; Then
Dest_ip=$1
jdk_src= $DEFAULT _JDK_SRC
if [$# = 2]; Then
Jdk_src=$2
Fi
Echo-e "<INFO> install JDK on ' $DEST _ip ', jdk: ' $JDK _src '"
Install_jdk "root@ $DEST _ip" "$JDK _src"
Fi