-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
75 lines (54 loc) · 1.93 KB
/
install.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
#!/bin/bash
# Colors
red="\e[0;91m"
green="\e[0;92m"
bold="\e[1m"
reset="\e[0m"
status(){
clear
echo -e $green$@'...'$reset
sleep 1
}
runCommand(){
COMMAND=$1
if [[ ! -z "$2" ]]; then
status $2
fi
eval $COMMAND;
BASH_CODE=$?
if [ $BASH_CODE -ne 0 ]; then
echo -e "${red}An error occurred:${reset} ${white}${COMMAND}${reset}${red} returned${reset} ${white}${BASH_CODE}${reset}"
exit ${BASH_CODE}
fi
}
jq --version
if [[ $? == 127 ]]; then apt -y install jq; fi
#get BashSelect
source <(curl -s https://raw.githubusercontent.com/GermanJag/BashSelect.sh/main/BashSelect.sh)
clear
readarray -t VERSIONS <<<$(curl -s https://api.adoptium.net/v3/info/available_releases | jq '.available_releases[]')
export OPTIONS=(${VERSIONS[*]})
bashSelect
selectVersion=${VERSIONS[$?]}
downloadLink=$(curl -s "https://api.adoptium.net/v3/assets/feature_releases/${selectVersion}/ga?architecture=x64&heap_size=normal&image_type=jdk&os=linux&page=1&page_size=1&project=jdk&sort_method=DEFAULT&sort_order=DESC&vendor=eclipse" | jq '.[].binaries' | jq '.[].package.link')
javadir="/usr/lib/jvm/"
if [ ! -d "$javadir" ]; then
runCommand "mkdir $javadir"
fi
tmpJavaDir="/tmp/java-installer/"
if [ ! -d "$tmpJavaDir" ]; then
runCommand "mkdir $tmpJavaDir"
fi
runCommand "cd $tmpJavaDir"
runCommand "rm -rf $tmpJavaDir*"
runCommand "wget $downloadLink" "download Java SE $selectVersion"
runCommand "tar -xvzf *.tar.gz" "unpacking JDK"
runCommand "rm -rf *.tar.gz"
tmp=$(ls)
runCommand "mv $tmp java-$selectVersion-openjdk"
java=$(ls)
runCommand "mv $java $javadir"
runCommand "update-alternatives --install /usr/bin/java java $javadir$java/bin/java 1020"
runCommand "update-alternatives --install /usr/bin/javac javac $javadir$java/bin/javac 1020"
runCommand "update-alternatives --set java $javadir$java/bin/java"
runCommand "update-alternatives --set javac $javadir$java/bin/javac" "the installation was successful"