-
Notifications
You must be signed in to change notification settings - Fork 0
/
java
executable file
·85 lines (67 loc) · 1.89 KB
/
java
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
#!/bin/bash
set -e -o pipefail
error() {
echo -e "\e[1m$@\e[0m" > /dev/stderr
false
}
nativeDir=
classPath=
cpArg=
args=("$@")
for i in $(seq 0 $((${#args}-1))); do
if [[ "${args[$i]}" == "-Djava.library.path="* ]]; then
nativeDir=$(echo "${args[i]}" | cut -d= -f2)
elif [[ "${args[$i]}" == "-cp" ]]; then
cpArg=$(($i+1))
IFS=$'\n' classPath=($(echo ${args[$cpArg]} | tr : $'\n'))
fi
done
if [[ $nativeDir == "" || $cpArg == "" ]]; then
exec java "$@"
fi
mmcdir="$(echo "$nativeDir" | sed -E 's@/instances/.*/natives$@@')"
IFS=$'\n' lwjglLibs=($(printf '%s\n' "${classPath[@]}" | grep lwjgl))
IFS=$'\n' otherLibs=($(printf '%s\n' "${classPath[@]}" | grep -v lwjgl))
jars=($(for lib in "${lwjglLibs[@]}"; do echo "$lib" | sed -nE 's/.*\/(lwjgl.*)-.*.jar/\1/p'; done))
lwjglVersion=$(basename ${lwjglLibs[0]} | sed -nE 's/.*-([0-9\.]*)\.jar/\1/p')
archsuffix=
case $(uname -m) in
x86_64)
;;
aarch64)
archsuffix=-arm64
;;
armhf)
archsuffix=-arm32
;;
*)
echo "This architecture is not supported."
exit 1
;;
esac
if [[ $(echo $lwjglVersion | sed 's/\.//g') < 323 ]]; then
lwjglVersion=3.2.3
fi
mavenbase="https://repo1.maven.org/maven2"
jarurl() {
echo "$mavenbase/org/lwjgl/$1/$lwjglVersion/$1-$lwjglVersion.jar"
}
nativeurl() {
echo "$mavenbase/org/lwjgl/$1/$lwjglVersion/$1-$lwjglVersion-natives-linux$archsuffix.jar"
}
destDir="${mmcdir}/arm-jars/$lwjglVersion"
mkdir -p "$destDir"
for file in "${jars[@]}"; do
jar="$(jarurl $file)"
natives="$(nativeurl $file)"
destJar="$destDir/$(basename $jar)"
destNatives="$destDir/$(basename $natives)"
if [[ ! -f "$destJar" ]]; then
curl -o "$destJar" "$jar" || error "Failed to download jar!"
fi
if [[ ! -f "$destNatives" ]]; then
curl -o "$destNatives" "$natives" || error "Failed to download natives jar!"
fi
done
args[$cpArg]="$(cat <(find $destDir -type f) <(printf '%s\n' "${otherLibs[@]}") | tr $'\n' :)"
exec java "${args[@]}"