-
Notifications
You must be signed in to change notification settings - Fork 0
/
javains
executable file
·49 lines (37 loc) · 1.76 KB
/
javains
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
#!/bin/sh
J_INSTALL_DIR=/usr/lib/jvm/java-8-oracle
URL=$(curl -s http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html | \
awk "/downloads\['/ && ! /demos/ && /\['files'\]/ && /linux-x64/ && /\.tar\.gz/" | \
grep -o 'http.*\.tar\.gz')
AVAILABLE=$(echo $URL | grep -o -P 'jdk-8u.{0,2}' | cut -d "u" -f 2)
CURRENT=$("$J_INSTALL_DIR"/bin/java -version 2>&1 | awk '/version/ {print $3}' | cut -d_ -f 2 | tr -d '"')
if [ -z $CURRENT ] || [ $AVAILABLE -gt $CURRENT ]; then
cd /var/cache/oracle-jdk8-installer
rm -f jdk-8u"$CURRENT"-linux-x64.tar.gz
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" $URL
tar -xzf jdk-8u"$AVAILABLE"-linux-x64.tar.gz
rm -rf $J_INSTALL_DIR
mv jdk1.8.0_"$AVAILABLE"/ $J_INSTALL_DIR
LATEST=$(LANG=C update-alternatives --display java | grep ^/ | sed -e 's/.* //g' | sort -n | tail -1)
if [ -z $LATEST ]; then
LATEST=1
else
J_PATH=$(LANG=C update-alternatives --display java | grep "priority "$LATEST"" | awk '{print $1}')
[ $J_PATH = "$J_INSTALL_DIR"/jre/bin/java ] || LATEST=$((LATEST+1))
fi
#link JRE files
for f in $J_INSTALL_DIR/jre/bin/*; do
name=`basename $f`;
if [ ! -f "/usr/bin/$name" -o -L "/usr/bin/$name" ]; then #some files, like jvisualvm might not be links
if [ -f "$J_INSTALL_DIR/man/man1/$name.1.gz" ]; then
update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/jre/bin/$name $LATEST --slave /usr/share/man/man1/$name.1.gz $name.1.gz $J_INSTALL_DIR/man/man1/$name.1.gz
fi
else
update-alternatives --install /usr/bin/$name $name $J_INSTALL_DIR/jre/bin/$name $LATEST
fi
done
echo "Oracle Java 8 installed"
fi
if [ $AVAILABLE -eq $CURRENT ]; then
echo "Java is up to date"
fi