forked from apache/age
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·141 lines (126 loc) · 4.58 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/sh
os=$(uname)
arch=$(uname -m)
java=$(java -version 2>&1 | head -n 1 | cut -d ' ' -f 3 | cut -d '.' -f 1 | cut -d '"' -f 2)
# Check JDK version
echo "Checking for JDK..."
if ! java -version >/dev/null 2>&1 || [ $java -lt 11 ]; then
echo "JDK not found or less than version 11, would you like to install? ()"
echo "Y/N ->"
read answer
if [ "$answer" = y ] || [ "$answer" = Y ]; then
echo "Installing..."
if [[ "$os" == "Darwin" ]]; then
cd /tmp
if [[ "$arch" == "x86_64" ]]; then
curl "https://download.oracle.com/java/20/latest/jdk-20_macos-x64_bin.dmg" -o jdk-20_bin.dmg
elif [[ "$arch" == "arm64" ]]; then
curl "https://download.oracle.com/java/20/latest/jdk-20_macos-aarch64_bin.dmg" -o jdk-20_bin.dmg
fi
hdiutil mount jdk-20_bin.dmg
# sudo installer -pkg "/Volumes/JDK 20/JDK 20.pkg" -target "/"
sudo open -w "/Volumes/JDK 20/JDK 20.pkg"
hdiutil unmount "/Volumes/JDK 20"
rm jdk-20_bin.dmg
elif [[ "$os" == "Linux" ]]; then
mkdir -p ~/tmp/jdk20
cd ~/tmp/jdk20
if [[ "$arch" == "x86_64" ]]; then
curl "https://download.oracle.com/java/20/latest/jdk-20_linux-x64_bin.tar.gz" -o jdk-20_bin.tar.gz
elif [[ "$arch" == "arm64" ]]; then
curl "https://download.oracle.com/java/20/latest/jdk-20_linux-aarch64_bin.tar.gz" -o jdk-20_bin.tar.gz
fi
sudo tar zxvf jdk-20_bin.tar.gz -C /usr/local/
cd ~/
rm -rf ~/tmp/jdk20/
fi
echo "JDK installation complete."
else
echo "Please install JDK >= 11.0.16"
exit 0
fi
else
echo "JDK already installed."
fi
antlr=$(/usr/local/jdk-20/bin/jar xf /usr/local/antlr/antlr-*-complete.jar META-INF/MANIFEST.MF >/dev/null 2>&1 && grep 'Implementation-Version' META-INF/MANIFEST.MF | cut -d ' ' -f 2 && rm -rf META-INF)
# Check ANTLR installation and version
echo "Checking for ANTLR..."
check_antlr () {
if [ ! -z $antlr ]; then
if ([ "$(echo $antlr | cut -d '.' -f 1)" -lt 4 ] && [ "$(echo $antlr | cut -d '.' -f 2)" -lt 11 ] && [ "$(echo $antlr | cut -d '.' -f 3)" -lt 1 ]); then
return 0
else
return 1
fi
else
return 0
fi
}
if check_antlr; then
echo "ANTLR not found in Default Location or less than version 4.11.1, would you like to Install?"
echo "(If installed in other location, please edit the location inside the shell script before running)"
echo "Y/N ->"
read answer
if [ "$answer" = y ] || [ "$answer" = Y ]; then
mkdir -p ~/tmp/antlr4.11.1
cd ~/tmp/antlr4.11.1
curl -LO "https://www.antlr.org/download/antlr-4.11.1-complete.jar"
sudo mkdir -p /usr/local/antlr
sudo mv ~/tmp/antlr4.11.1/antlr-4.11.1-complete.jar /usr/local/antlr/antlr-4.11.1-complete.jar
echo 'export CLASSPATH=".:/usr/local/antlr/antlr-4.11.1-complete.jar"' >>~/.bashrc
. ~/.bashrc
echo "ANTLR installation complete."
else
echo "Please install ANTLR >= 4.11.1"
exit 0
fi
#
else
echo "ANTLR already installed."
fi
# Check Go installation and version
echo "Checking for Go..."
if ! command -v go >/dev/null 2>&1 || { [ $(go version | grep -o -E '[0-9]+\.[0-9]+' | head -n 1 | cut -d '.' -f 1) -lt 1 ] && [ $(go version | grep -o -E '[0-9]+\.[0-9]+' | head -n 1 | cut -d '.' -f 2) -lt 19 ]; }; then
echo "Go not installed or version is less than 1.19, would you like to install?"
echo "Y/N ->"
read answer
if [ "$answer" = y ] || [ "$answer" = Y ]; then
if [[ "$os" == "Darwin" ]]; then
cd /tmp
if [[ "$arch" == "x86_64" ]]; then
curl "https://go.dev/dl/go1.20.2.darwin-amd64.pkg" -o go1.20.2.pkg
elif [[ "$arch" == "arm64" ]]; then
curl "https://go.dev/dl/go1.20.2.darwin-arm64.pkg" -o go1.20.2.pkg
fi
#sudo installer -pkg "go1.20.2.pkg" -target "/"
sudo open -w golang.pkg
elif [[ "$os" == "Linux" ]]; then
mdkir -p ~/tmp/go1.20.2
cd ~/tmp/go1.20.2
if [[ "$arch" == "x86_64" ]]; then
curl "https://go.dev/dl/go1.20.2.linux-amd64.tar.gz" -o go1.20.2.tar.gz
elif [[ "$arch" == "arm64" ]]; then
curl "https://go.dev/dl/go1.20.2.linux-arm64.tar.gz" -o go1.20.2.tar.gz
fi
if command -v go >/dev/null 2>&1; then
rm -rf /usr/local/go
fi
sudo tar -C /usr/local -xzf go1.20.2.linux-amd64.tar.gz
if ! [[ ":$PATH:" == *":/usr/local/go/bin:"* ]]; then
export PATH=$PATH:/usr/local/go/bin
fi
fi
echo "Go installation complete"
else
echo "Please install Go >= 1.19"
exit 0
fi
else
echo "Go already installed."
fi
echo "Generating Parser & Lexer..."
java -Xmx500M -cp "/usr/local/lib/antlr-4.11.1-complete.jar:$CLASSPATH" org.antlr.v4.Tool -Dlanguage=Go -visitor Age.g4
echo "Installing Driver..."
go get -u ./...
echo "Successfully Installed Driver!"
exit 0