jdk安装脚本

#!/bin/bash  
      
    chmod u+x jdk-6u29-linux-i586.bin  
    installPath=/usr/java  
    if [ ! -d /usr/java ];  
    then  
        mkdir /usr/java  
    fi  
    ./jdk-6u29-linux-i586.bin -D  /usr/java  
    cp  -R jdk1.6.0_29/ /usr/java/jdk1.6.0_29/  
      
    touch environment  
    echo "PATH=\"$PATH:/usr/java/jdk1.6.0_29/bin\"" >> environment  
    echo "JAVA_HOME=/usr/java/jdk1.6.0_29" >> environment  
    echo "CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar" >> environment  
    rm -rf /etc/environment  
    cp environment /etc  
    source /etc/environment  
    update-alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_29/bin/java 300  
    update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.6.0_29/bin/javac 300  
    update-alternatives --config java
#!/bin/bash
#
echo "You want to which kinds of means to install jdk:"
select jdk in `ls *gz *bin`
do
 echo "Your choice is $jdk"
 break
done

echo "According to your chosen bag suffixes to choice,eg:bin"
echo "Usage:Please input bin or gz:"
read -p "You jdk type is App>" type
case $type in 
bin)
   chmod +x $jdk
   sh $jdk
   ;;
gz)
  tar -zxvf $jdk
   ;;
esac 

ls jdk* -d|while read jdkfile;do
appjdk=(`echo $jdkfile`)
size=${#jdkfile[@]}
for ((i=0;i<$size;i++))
 do
  if [ -d ${appjdk[$i]} ];then
     mv ${appjdk[$i]} /opt/oracle/

  echo -e  "JAVA_HOME=/opt/oracle/"${appjdk[$i]}"" >> /etc/profile
  echo -e  "JAVA_BIN=/opt/oracle/"${appjdk[$i]}"/bin" >> /etc/profile
  echo -e  "PATH=$PATH:$JAVA_BIN" >> /etc/profile
  echo -e  "CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" >> /etc/profile
  export JAVA_HOME JAVA_BIN PATH CLASSPATH
source /etc/profile
echo "Now we'll test about whether it's ok!"
java -version
echo "                                    "
     if [ $? == 0 ];then
       echo "You see,jdk is installed successfully!"
     else
       echo "Please check where did jdk go wrong!!!"
     fi
  fi 
 done
done

相关推荐