1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| #!/bin/sh BASEDIR=$(cd `dirname $0`; pwd)
read -p "Please select java tar package full path path[/tmp/jdk.tar.gz] " INSTALL_FILE if [ ! -f "$INSTALL_FILE" ]; then trueINSTALL_FILE="/tmp/jdk.tar.gz" fi
read -p "Please select java install path path[/usr/local/java]: " INSTALL_PATH if [ "$INSTALL_PATH" = "" ]; then trueINSTALL_PATH="/usr/local/java" fi if [ ! -d $INSTALL_PATH ]; then echo "mkdir $INSTALL_PATH" mkdir -p $INSTALL_PATH fi
echo "uncompress $INSTALL_FILE to $INSTALL_PATH" if [ -w $INSTALL_PATH ]; then tar -zxvf $INSTALL_FILE -C $INSTALL_PATH --strip-components=1 else sudo tar -zxvf $INSTALL_FILE -C $INSTALL_PATH --strip-components=1 fi
echo "Setting java environment..." echo "export JAVA_HOME=$INSTALL_PATH" | sudo tee -a /etc/profile
JAVA_HOME=$INSTALL_PATH
echo "export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar" | sudo tee -a /etc/profile echo 'export PATH=$JAVA_HOME/bin:$PATH' | sudo tee -a /etc/profile
echo "refresh java environment..."
. /etc/profile source /etc/profile
java -version if [ "$?" = "0" ]; then echo -e "\033[32m Installed, please source /etc/profile or relogin. \033[0m" else echo -e "\033[31m Install failed. \033[0m" fi
unset BASEDIR unset INSTALL_PATH unset INSTALL_FILE
exit 0
|