-
Notifications
You must be signed in to change notification settings - Fork 9
/
installer.sh
executable file
·187 lines (175 loc) · 5.75 KB
/
installer.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/sh
epirus_version=${1:-$(curl https://internal.services.web3labs.com/api/epirus/versions/latest)}
installed_flag=0
installed_version=""
check_if_installed() {
if [ -x "$(command -v epirus)" ] >/dev/null 2>&1; then
printf 'An Epirus installation exists on your system.\n'
installed_flag=1
fi
}
setup_color() {
# Only use colors if connected to a terminal
if [ -t 1 ]; then
RED=$(printf '\033[31m')
GREEN=$(printf '\033[32m')
YELLOW=$(printf '\033[33m')
BLUE=$(printf '\033[34m')
BOLD=$(printf '\033[1m')
RESET=$(printf '\033[m')
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
RESET=""
fi
}
install_epirus() {
echo "Downloading Epirus ..."
mkdir -p "$HOME/.epirus"
if [ "$(curl --write-out "%{http_code}" --silent --output /dev/null "https://github.com/epirus-io/epirus-cli/releases/download/v${epirus_version}/epirus-cli-shadow-${epirus_version}.tar")" -eq 302 ]; then
curl -# -L -o "$HOME/.epirus/epirus-cli-shadow-${epirus_version}.tar" "https://github.com/epirus-io/epirus-cli/releases/download/v${epirus_version}/epirus-cli-shadow-${epirus_version}.tar"
echo "Installing Epirus..."
tar -xf "$HOME/.epirus/epirus-cli-shadow-${epirus_version}.tar" -C "$HOME/.epirus"
echo "export PATH=\$PATH:$HOME/.epirus" >"$HOME/.epirus/source.sh"
chmod +x "$HOME/.epirus/source.sh"
echo "Removing downloaded archive..."
rm "$HOME/.epirus/epirus-cli-shadow-${epirus_version}.tar"
else
echo "Looks like there was an error while trying to download epirus"
exit 0
fi
}
get_user_input() {
while echo "Would you like to update Epirus [Y/n]" && read -r user_input </dev/tty ; do
case $user_input in
n)
echo "Aborting instalation ..."
exit 0
;;
*)
echo "Updating Epirus ..."
break
;;
esac
done
}
check_version() {
installed_version=$(epirus --version | grep Version | awk -F" " '{print $NF}')
if [ "$installed_version" = "$epirus_version" ]; then
echo "You have the latest version of Epirus (${installed_version}). Exiting."
exit 0
else
echo "Your Epirus version is not up to date."
get_user_input
fi
}
source_epirus() {
SOURCE_EPIRUS="\n[ -s \"$HOME/.epirus/source.sh\" ] && source \"$HOME/.epirus/source.sh\""
if [ -f "$HOME/.bashrc" ]; then
bash_rc="$HOME/.bashrc"
touch "${bash_rc}"
if ! grep -qc '.epirus/source.sh' "${bash_rc}"; then
echo "Adding source string to ${bash_rc}"
printf "${SOURCE_EPIRUS}\n" >>"${bash_rc}"
else
echo "Skipped update of ${bash_rc} (source string already present)"
fi
fi
if [ -f "$HOME/.bash_profile" ]; then
bash_profile="${HOME}/.bash_profile"
touch "${bash_profile}"
if ! grep -qc '.epirus/source.sh' "${bash_profile}"; then
echo "Adding source string to ${bash_profile}"
printf "${SOURCE_EPIRUS}\n" >>"${bash_profile}"
else
echo "Skipped update of ${bash_profile} (source string already present)"
fi
fi
if [ -f "$HOME/.bash_login" ]; then
bash_login="$HOME/.bash_login"
touch "${bash_login}"
if ! grep -qc '.epirus/source.sh' "${bash_login}"; then
echo "Adding source string to ${bash_login}"
printf "${SOURCE_EPIRUS}\n" >>"${bash_login}"
else
echo "Skipped update of ${bash_login} (source string already present)"
fi
fi
if [ -f "$HOME/.profile" ]; then
profile="$HOME/.profile"
touch "${profile}"
if ! grep -qc '.epirus/source.sh' "${profile}"; then
echo "Adding source string to ${profile}"
printf "$SOURCE_EPIRUS\n" >>"${profile}"
else
echo "Skipped update of ${profile} (source string already present)"
fi
fi
if [ -f "$(command -v zsh 2>/dev/null)" ]; then
file="$HOME/.zshrc"
touch "${file}"
if ! grep -qc '.epirus/source.sh' "${file}"; then
echo "Adding source string to ${file}"
printf "$SOURCE_EPIRUS\n" >>"${file}"
else
echo "Skipped update of ${file} (source string already present)"
fi
fi
}
check_if_epirus_homebrew() {
if (command -v brew && ! (brew info epirus 2>&1 | grep -e "Not installed\|No available formula") >/dev/null 2>&1); then
echo "Looks like Epirus is installed with Homebrew. Please use Homebrew to update. Exiting."
exit 0
fi
}
clean_up() {
if [ -d "$HOME/.epirus" ]; then
rm -f "$HOME/.epirus/source.sh"
rm -rf "$HOME/.epirus/epirus-cli-shadow-$installed_version" >/dev/null 2>&1
echo "Deleting older installation ..."
fi
}
completed() {
cd "$HOME/.epirus"
ln -sf "epirus-cli-shadow-$epirus_version/bin/epirus" epirus
printf '\n'
printf "$GREEN"
echo "Epirus was succesfully installed."
echo "To use epirus in your current shell run:"
echo "source \$HOME/.epirus/source.sh"
echo "When you open a new shell this will be performed automatically."
echo "To see what epirus's CLI can do you can check the documentation bellow."
echo "https://docs.epirus.io/sdk/cli/"
printf "$RESET"
exit 0
}
check_java_version() {
java_version=$(java -version 2>&1 | awk -F '"' '/version/ {print $2}')
echo "Your current java version is ${java_version}"
is_compatible=$(curl "https://internal.services.web3labs.com/api/epirus/compatibility/${java_version}")
if [ "$is_compatible" != "True" ]; then
echo "The Epirus CLI requires a Java version between 1.8 and 12. Please ensure you have a compatible Java version before installing Epirus for full functionality."
read -s -n 1 -p "Press any key to continue, or press Ctrl+C to cancel the installation." </dev/tty
fi
}
main() {
setup_color
check_java_version
check_if_installed
if [ $installed_flag -eq 1 ]; then
check_if_epirus_homebrew
check_version
clean_up
install_epirus
source_epirus
completed
else
install_epirus
source_epirus
completed
fi
}
main