#!/bin/bash

echo "<<=========== jdk部署[开始] ==========>>"
date '+时间 : %Y-%m-%d %H:%M:%S' >> /home/start.log
echo "<<=========== jdk部署[开始] ==========>>" >> /home/start.log
echo "##########" >> /home/start.log

IUSER=$1
jdkPath="/usr/lib/jvm"
mkdir -p ${jdkPath}
if [  -d ${jdkPath}/java ] ;then
	echo "Existing java path" >>/home/stop.log
	exit 1;
else
	echo "Please Wait unzip" 
	7z x ./sh/rar/jdk.7z -o${jdkPath} > /tmp/jdklog.log
	echo "unzip OK" >> /home/start.log
fi
BAPATH="/home/$IUSER/.bashrc"
if [ -f ${BAPATH} -a ! -f  ${BAPATH}.bak ];then
	cp ${BAPATH} ${BAPATH}.bak
	cp ./sh/doc/javahome /tmp/javahome
	echo "##################" >> ${BAPATH}
	echo "# oracle jdk wangjie" >> ${BAPATH}
	cat /tmp/javahome >> ${BAPATH}
	export JAVA_HOME=/usr/lib/jvm/java
	export JRE_HOME=${JAVA_HOME}/jre
	export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
	export PATH=${JAVA_HOME}/bin:$PATH
	echo "jdk install ok" 
	echo "jdk install ok" >> /home/start.log
else
	echo UserJdkPathExisting
	exit 1;
fi
chown $IUSER:$IUSER ${BAPATH}
