#!/bin/bash ################################################# # # INSTALL JDK AUTOMATICALLY # # author: jeffzhao # date: 2013.6.20 # ################################################# cmd_path=`pwd` jdk_package_path="./" jdk_install_path="/opt/jdk" jdk_package_name="jdk-7u25-linux-i586.tar.gz" jdk_unzip_dir="" ################################################# # # check jdk package # unzip jdk # ################################################ function check_package() { jdk_package_name=`ls | grep jdk | grep tar.gz` ### jdk_unzip_dir=`ls -l | grep '^d' |grep jdk |awk '{print$8}'` if [ -d ${jdk_unzip_dir} ] then rm -rf ${jdk_unzip_dir} fi ### if [ ! -f ${jdk_package_name} ] then echo "you need jdk package!" exit 0 fi ### tar -xzvf ${jdk_package_name} rm -rf ${jdk_install_path}/* cp -r `ls -l | grep '^d' |grep jdk |awk '{print$8}'` ${jdk_install_path} } ################################################ # # install jdk # ################################################# function install_jdk() { grep "JAVA_HOME" /etc/profile if [ $? == 0 ] then sed '/JAVA_HOME/' /etc/profile fi echo "export JAVA_HOME=${jdk_install_path}/${jdk_unzip_dir}" >>/etc/profile } function main() { check_package install_jdk } main