forked from 7emotions/run_java
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·49 lines (37 loc) · 1020 Bytes
/
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
#!/data/data/com.termux/files/usr/bin/bash
javac=/data/data/com.termux/files/usr/bin/javac
java=/data/data/com.termux/files/usr/bin/java
cat > $javac <<-'EOF'
#!/system/bin/sh
if [ -z "$1" ] || ! [ -f "$1" ]; then
echo "$1 File not Found" >&2
exit
elif [ -z "$(command -v ecj)" ] || [ -z "$(command -v dx)" ]; then
echo "ecj/dx not Found" >&2
exit
fi
dir="$(dirname "$(realpath "$1")")"
name="$(basename "$1" .java)"
tempdir="$dir/tmp$RANDOM"
ecj -sourcepath "$dir" "$dir/${name}.java" -d "$tempdir" || {
echo "Unable to compile $1"; exit
}
cd "$tempdir"
dx --dex --output="$dir/${name}.dex" * || {
echo "Unable to dex classes"; exit
}
rm -rf "$tempdir"
EOF
cat > $java <<-'EOF'
#!/system/bin/sh
if [ -z "$1" ] || ! [ -f "${1}.dex" ]; then
echo "$1 File not Found" >&2
exit
fi
dir="$(dirname "$(realpath "${1}.dex")")"
name="$(basename "$1")"
dalvikvm -cp "${dir}/${name}.dex" "${name}" || {
echo "Unable to run java package"; exit
}
EOF
chmod 755 $javac $java