-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
288 lines (252 loc) · 9.22 KB
/
index.html
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/usr/bin/env bash
set -eo pipefail
function print_usage() {
echo "Usage: curl -skSL http://get.infini.cloud | bash -s -- [-p program_name] [-v program_version] [-d install_dir]"
echo "Options:"
echo " -p, --program-name <name> Name of the program to install which default is console"
echo " -v, --version <version> Version of the program to install which default is latest"
echo " -d, --install-dir <dir> Directory of the program install which default is /opt/program"
exit 1
}
function print_header() {
echo " "
echo " @@@@@@@@@@@"
echo " @@@@@@@@@@@@"
echo " @@@@@@@@@@@@"
echo " @@@@@@@@@&@@@"
echo " #@@@@@@@@@@@@@"
echo " @@@ @@@@@@@@@@@@@ "
echo " &@@@@@@@ &@@@@@@@@@@@@@ "
echo " @&@@@@@@@&@ @@@&@@@@@@@&@ "
echo " @@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@ "
echo " @@@@@@@@@@@@@@@@@@& @@@@@@@@@@@@@ "
echo " %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ "
echo " @@@@@@@@@@@@&@@@@@@@@@@@@@@@ "
echo " @@ ,@@@@@@@@@@@@@@@@@@@@@@@& "
echo " @@@@@. @@@@@&@@@@@@@@@@@@@@ "
echo " @@@@@@@@@@ @@@@@@@@@@@@@@@# "
echo " @&@@@&@@@&@@@ &@&@@@&@@@&@ "
echo " @@@@@@@@@@@@@. @@@@@@@* "
echo " @@@@@@@@@@@@@ %@@@ "
echo " @@@@@@@@@@@@@ "
echo "/@@@@@@@&@@@@@ "
echo "@@@@@@@@@@@@@ "
echo "@@@@@@@@@@@@@ "
echo "@@@@@@@@@@@@ Welcome to INFINI Labs!"
echo ""
echo ""
echo "Now attempting the installation... "
echo ""
}
function print_footprint() {
echo " __ _ __ ____ __ _ __ __ "
echo " / // |/ // __// // |/ // / "
echo " / // || // _/ / // || // / "
echo "/_//_/|_//_/ /_//_/|_//_/ "
echo ""
echo "©INFINI.LTD, All Rights Reserved."
echo ""
}
__try() {
if [[ $try_status -eq 0 ]]; then
! exception=$( $@ 2>&1 >/dev/null )
try_status=${PIPESTATUS[0]}
fi
}
__catch() {
_old_try=$try_status
try_status=0
[[ $_old_try -ne 0 ]]
}
function get_latest_version() {
echo $(curl -m30 -sk "https://release.infinilabs.com/.latest" |sed 's/",/"/;s/"//g;s/://1' |grep -Ev '^[{}]' |grep "$program_name" |awk '{print $NF}')
}
function check_dir() {
if [[ ! -d "${install_dir}" ]]; then
__try mkdir -p "${install_dir}"
if __catch e; then
echo -e "Error: Unable to create installation directory, please manually create and reinstall.\nsudo mkdir -p ${install_dir} && sudo chown -R \$(whoami) ${install_dir}" >&2; exit 1;
fi
fi
owner=$(ls -ld "${install_dir}" |awk '{print $3}')
if [[ "${owner}" != "$(whoami)" ]]; then
echo -e "Error: The installation directory ${install_dir} should be owner by current user.\nsudo chown -R \$(whoami) ${install_dir}" >&2; exit 1;
fi
if [[ "$(ls -A ${install_dir})" ]]; then
echo "Error: The installation directory ${install_dir} should be clean." >&2; exit 1;
fi
}
function compare_versions() {
# $1: version1 (e.g., 1.10.1-1978 or 1.10.1)
# $2: version2 (e.g., 1.9.5)
# Prints: "equal", "greater", or "less" to stdout
local v1_base=$(echo "$1" | cut -d'-' -f1)
local v2_base=$(echo "$2" | cut -d'-' -f1)
# Validate input format (major.minor.patch) and exit on error
[[ "$v1_base" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && [[ "$v2_base" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || {
echo "Error: Invalid version format. Expected major.minor.patch" >&2
exit 1
}
IFS=. read -r v1_major v1_minor v1_patch <<< "$v1_base"
IFS=. read -r v2_major v2_minor v2_patch <<< "$v2_base"
# Chain comparisons using short-circuit evaluation
(( v1_major > v2_major )) && echo "greater" && return
(( v1_major < v2_major )) && echo "less" && return
(( v1_minor > v2_minor )) && echo "greater" && return
(( v1_minor < v2_minor )) && echo "less" && return
(( v1_patch > v2_patch )) && echo "greater" && return
(( v1_patch < v2_patch )) && echo "less" && return
echo "equal"
}
function check_platform() {
local platform=$(uname)
local arch=$(uname -m)
case $platform in
"Linux")
case $arch in
"i386"|"i686"|"x86")
file_ext="linux-386.tar.gz"
;;
"x86_64"|"amd64")
file_ext="linux-amd64.tar.gz"
;;
"aarch64"|"arm64")
file_ext="linux-arm64.tar.gz"
;;
"armv5tel")
file_ext="linux-armv5.tar.gz"
;;
"armv6l")
file_ext="linux-armv6.tar.gz"
;;
"armv7"|"armv7l")
file_ext="linux-armv7.tar.gz"
;;
"mips"|"mipsel")
file_ext="linux-mips.tar.gz"
;;
"mips64")
file_ext="linux-mips64.tar.gz"
;;
"mips64el")
file_ext="linux-mips64le.tar.gz"
;;
"loong64"|"loongarch64")
file_ext="linux-loong64.tar.gz"
;;
"sw_64")
file_ext="linux-sw64.tar.gz"
;;
"riscv64")
file_ext="linux-riscv64.tar.gz"
;;
*)
echo "Unsupported architecture: ${arch}" >&2
exit 1
;;
esac
;;
"Darwin")
case $arch in
"x86_64"|"amd64")
file_ext="mac-amd64.zip"
;;
"arm64")
file_ext="mac-arm64.zip"
;;
*)
echo "Unsupported architecture: ${arch}" >&2
exit 1
;;
esac
;;
"MINGW"*|"WSL"*|"Cygwin")
case $arch in
"i386"|"i686")
file_ext="windows-386.zip"
;;
"x86_64"|"amd64")
file_ext="windows-amd64.zip"
;;
*)
echo "Unsupported architecture: ${arch}" >&2
exit 1
;;
esac
;;
*)
echo "Unsupported platform: ${platform}" >&2
exit 1
;;
esac
}
function install_binary() {
type="stable"
if [[ "$version" =~ NIGHTLY ]] || [[ "$version" =~ SNAPSHOT ]]; then
type="snapshot"
elif [[ -n "$version" ]] && [[ -n "$latest_version" ]]; then
local result=$(compare_versions "$version" "$latest_version")
if [[ "$result" == "greater" ]]; then
type="snapshot"
fi
fi
local download_url="https://release.infinilabs.com/${program_name}/${type}/${program_name}-${version}-${file_ext}"
echo "File: [$download_url]"
tmp_dir="$(mktemp -d)"
cd "$tmp_dir"
if command -v curl >/dev/null 2>&1; then
curl -# -kLO "$download_url"
elif command -v wget >/dev/null 2>&1; then
wget -q -nc --show-progress --progress=bar:force:noscroll "$download_url"
else
echo "Error: Could not find curl or wget, Please install wget or curl in advance." >&2; exit 1;
fi
if [[ "${file_ext}" == *".tar.gz" ]]; then
if ! tar -xzf "${program_name}-${version}-${file_ext}" -C "$install_dir" >/dev/null 2>&1; then
echo "Error: Failed to extract tar.gz archive." >&2
exit 1
fi
else
if ! unzip -q "${program_name}-${version}-${file_ext}" -d "$install_dir" >/dev/null 2>&1; then
echo "Error: Failed to extract zip archive." >&2
exit 1
fi
fi
cd "${install_dir}" && rm -rf "${tmp_dir}"
}
function main() {
while [[ $# -gt 0 ]]; do
case "$1" in
-p|--program-name) program_name="$2"; shift 2 ;;
-v|--version) version="$2"; shift 2 ;;
-d|--install-dir) install_dir="$2"; shift 2 ;;
*) print_usage ;;
esac
done
program_name=${program_name:-console}
install_dir=${install_dir:-/opt/$program_name}
latest_version=$(get_latest_version)
version=${version:-$latest_version}
file_ext=""
if [[ -z "${version}" ]]; then
echo "Error: Could not obtain the latest version number. Please check the network and try again.">&2; exit 1;
else
echo "Name: [${program_name}], Version: [${version}], Path: [${install_dir}]"
fi
check_dir
check_platform
install_binary
[[ "$program_name" == "easysearch" ]] && exe_name="bin/initialize.sh && bin/${program_name}" || exe_name=./${program_name}-${file_ext%%.*}
echo ""
echo "Installation complete. [${program_name}] is ready to use!"
echo ""
echo ""
echo "----------------------------------------------------------------"
echo "cd ${install_dir} && ${exe_name}"
echo "----------------------------------------------------------------"
echo ""
echo ""
print_footprint
}
print_header
main "$@"