forked from SpereShelde/BoxHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjava.sh
76 lines (69 loc) · 1.75 KB
/
java.sh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
#author SpereShelde
base_dir=$(cd "$(dirname "$0")";pwd)
JDK_FILE=$(ls | grep jdk-*-linux-*.tar.gz)
#下载JDK
download(){
os_version=`uname -a`
echo $os_version
architecture="64"
echo "$os_version" | grep -q "$architecture"
if [ $? -eq 0 ]
then
if [ ! -f "$JDK_FILE" ]; then
echo "您正在使用64位操作系统,为您选择64位JDK"
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
fi
else
if [ ! -f "$JDK_FILE" ]; then
echo "您正在使用32位操作系统,为您选择32位JDK"
wget -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-i586.tar.gz
fi
fi
JDK_FILE=$(ls | grep jdk-*-linux-*.tar.gz)
}
#安装JDK
install_jdk(){
JAVA_DIR=/usr/local/java
JDK_DIR="jdk1.8.0_131"
JDK_PATH="$JAVA_DIR"/"$JDK_DIR"
tar xzf $JDK_FILE
mkdir -p $JAVA_DIR
mv $JDK_DIR $JAVA_DIR
#配置环境变量
cp ~/.bashrc ~/.bashrc.backup.java
if [ ! -n "$JAVA_HOME" ]; then
echo "export JAVA_HOME=\"$JDK_PATH\"" >> ~/.bashrc
fi
if [ ! -n "$JRE_HOME" ]; then
echo "export JRE_HOME=\"\$JAVA_HOME/jre\"" >> ~/.bashrc
fi
if [ ! -n "$CLASSPATH" ]; then
echo "export CLASSPATH=.:\$JDK_PATH/lib/dt.jar:\$JDK_PATH/lib/tools.jar" >> ~/.bashrc
fi
echo "export PATH=\$JAVA_HOME/bin:\$JRE_HOME/bin:\$PATH" >> ~/.bashrc
source ~/.bashrc
echo "JDK install success!"
}
copy_wget(){
echo "Copy wget to /bin ..."
cp /usr/bin/wget /bin/wget
}
main(){
download
if [ $? != 0 ]; then
echo "JDK download failed"
exit 1
fi
install_jdk
if [ $? != 0 ]; then
echo "JDK install failed"
exit 1
fi
copy_wget
if [ $? != 0 ]; then
echo "Copy wget failed"
exit 1
fi
}
main