forked from holatuwol/liferay-faster-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavahome
executable file
·91 lines (67 loc) · 1.84 KB
/
javahome
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
javahome() {
# Check for a valid operating system
local BASE_JAVA=
local JAVA_VERSION=$1
if [ -d /usr/java ]; then
BASE_JAVA=/usr/java
elif [ -d /usr/lib/jvm ]; then
BASE_JAVA=/usr/lib/jvm
else
echo "Unable to change Java on your operating system"
return 0
fi
# If this is diagnostic, just report JAVA_HOME
if [ "" == "${JAVA_VERSION}" ]; then
if [ "" != "${JAVA_HOME}" ]; then
echo JAVA_HOME=$JAVA_HOME
$JAVA_HOME/bin/java 2>&1 -version | head -1
return 0
fi
JAVA_VERSION=8
fi
# Remove the existing JAVA_HOME from the path
if [ "" != "$JAVA_HOME" ]; then
export PATH=$(echo $PATH | sed -e "s;:$JAVA_HOME/bin;;g" | sed -e "s;$JAVA_HOME/bin:;;g")
fi
# Check for a valid /etc/alternatives value
local ALT_ID=
# Choose the closest matching version
for folder in $(ls -1 ${BASE_JAVA} | grep -F "jdk1.${JAVA_VERSION}.0" | sort -t'_' -k2nr); do
if [ ! -f $BASE_JAVA/$folder/bin/java ]; then
continue
fi
ALT_ID=$BASE_JAVA/$folder
break
done
# If we couldn't find one, maybe they installed it through a package manager
if [ "" == "$ALT_ID" ]; then
for folder in $(ls -1 ${BASE_JAVA} | grep -F java-${JAVA_VERSION}-oracle); do
if [ ! -f $BASE_JAVA/$folder/bin/java ]; then
continue
fi
ALT_ID=$BASE_JAVA/$folder
break
done
fi
if [ "" == "$ALT_ID" ]; then
for folder in $(ls -1 ${BASE_JAVA} | grep -F java-${JAVA_VERSION}-openjdk); do
if [ ! -f $BASE_JAVA/$folder/bin/java ]; then
continue
fi
ALT_ID=$BASE_JAVA/$folder
break
done
fi
# If we still couldn't find it, report that Java could not be found
if [ "" == "$ALT_ID" ]; then
echo "Unable to find Java ${JAVA_VERSION}"
return 1
fi
export JAVA_HOME=$ALT_ID
# Prepend Java to the path
echo JAVA_HOME=$JAVA_HOME
$JAVA_HOME/bin/java 2>&1 -version | head -1
export PATH=$JAVA_HOME/bin:$PATH
}
javahome $@