-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
install.sh
332 lines (285 loc) · 8.99 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
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
# https://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
set -u
get_firedbg_version() {
local _rustc_version="$(rustc --version)"
case "$_rustc_version" in
rustc\ 1.74.*)
local _firedbg_version="1.74.2"
;;
rustc\ 1.75.*)
local _firedbg_version="1.75.1"
;;
rustc\ 1.76.*)
local _firedbg_version="1.76.0"
;;
rustc\ 1.77.*)
local _firedbg_version="1.77.1"
;;
rustc\ 1.78.*)
local _firedbg_version="1.78.0"
;;
rustc\ 1.79.*)
local _firedbg_version="1.79.0"
;;
rustc\ 1.80.*)
local _firedbg_version="1.80.0"
;;
rustc\ 1.81.*)
local _firedbg_version="1.81.0"
;;
*)
err "no precompiled binaries available for $_rustc_version";
;;
esac
RETVAL="$_firedbg_version"
}
main() {
downloader --check
need_cmd uname
need_cmd mktemp
need_cmd mkdir
need_cmd rm
need_cmd tar
need_cmd which
get_architecture || return 1
local _arch="$RETVAL"
assert_nz "$_arch" "arch"
which rustup > /dev/null 2>&1
need_ok "failed to find Rust installation, is rustup installed?"
get_firedbg_version || return 1
local _firedbg_version="$RETVAL"
assert_nz "$_firedbg_version" "firedbg version"
local _url="https://github.com/SeaQL/FireDBG.for.Rust/releases/download/$_firedbg_version/$_arch.tar.gz"
local _dir="$(mktemp -d 2>/dev/null || ensure mktemp -d -t FireDBG)"
local _file="$_dir/$_arch.tar.gz"
set u
local _cargo_home="$CARGO_HOME"
if [ -z "$_cargo_home" ]; then
_cargo_home="$HOME/.cargo";
fi
local _cargo_bin="$_cargo_home/bin"
ensure mkdir -p "$_cargo_bin"
set -u
printf '%s `%s`\n' 'info: downloading FireDBG from' "$_url" 1>&2
ensure mkdir -p "$_dir"
downloader "$_url" "$_file"
if [ $? != 0 ]; then
say "failed to download $_url"
say "this may be a standard network error, but it may also indicate"
say "that FireDBG's release process is not working. When in doubt"
say "please feel free to open an issue!"
exit 1
fi
ensure tar xf "$_file" --strip-components 1 -C "$_dir"
printf '%s `%s`\n' 'info: installing FireDBG binaries to' "$_cargo_bin" 1>&2
ignore rm -rf "$_cargo_bin/firedbg*"
ignore rm -rf "$_cargo_bin/firedbg-lib"
ensure mv "$_dir/firedbg-lib" "$_cargo_bin/firedbg-lib"
ensure mv "$_dir/firedbg" "$_cargo_bin/firedbg"
ensure mv "$_dir/firedbg-indexer" "$_cargo_bin/firedbg-indexer"
ensure mv "$_dir/firedbg-debugger" "$_cargo_bin/firedbg-debugger"
printf '%s\n' 'info: performing FireDBG self tests' 1>&2
local _self_test="$_cargo_home/bin/firedbg-lib/debugger-self-test"
cd "$_self_test"
"$_cargo_home/bin/firedbg" run debugger_self_test --output "$_self_test/output.firedbg.ss"
cd - > /dev/null
if [ $? != 0 ]; then
say "fail to run FireDBG debugger"
exit 1
fi
"$_cargo_home/bin/firedbg-indexer" --input "$_self_test/output.firedbg.ss" validate --json "$_self_test/expected_data.json"
if [ $? != 0 ]; then
say "fail to validate FireDBG debugger result"
exit 1
fi
printf '%s\n' 'info: completed FireDBG self tests' 1>&2
}
get_architecture() {
local _ostype="$(uname -s)"
local _cputype="$(uname -m)"
set u
if [ -n "$TARGETOS" ]; then
_ostype="$TARGETOS"
fi
if [ -n "$TARGETARCH" ]; then
_cputype="$TARGETARCH"
fi
set -u
if [ "$_ostype" = Darwin ] && [ "$_cputype" = i386 ]; then
if sysctl hw.optional.x86_64 | grep -q ': 1'; then
local _cputype=x86_64
fi
fi
case "$_ostype" in
Linux | linux)
local _os_id="$(awk -F= '$1=="ID" { print $2 ;}' /etc/os-release | tr -d '"')"
local _os_version_id="$(awk -F= '$1=="VERSION_ID" { print $2 ;}' /etc/os-release | tr -d '"')"
local _ostype="$_os_id$_os_version_id"
case "$_ostype" in
pop*)
local _ostype="ubuntu$_os_version_id"
;;
esac
local _os_id_like="$(awk -F= '$1=="ID_LIKE" { print $2 ;}' /etc/os-release | tr -d '"')"
case "$_os_id" in
linuxmint*)
case "$_os_id_like" in
ubuntu*)
case "$_os_version_id" in
24*) # Ubuntu Noble
local _ostype="ubuntu24.04"
;;
21*) # Ubuntu Jammy
local _ostype="ubuntu22.04"
;;
20*) # Ubuntu Focal
local _ostype="ubuntu20.04"
;;
esac
;;
debian*) # Debian Bookworm
local _ostype="debian12"
;;
esac
esac
case "$_ostype" in
ubuntu24*)
check_apt_install libc abi1-18
local _ostype="ubuntu22.04"
;;
ubuntu22*)
check_apt_install libc abi1-15
;;
ubuntu20*)
check_apt_install libc abi1-10
;;
debian12*)
check_apt_install libc abi1-14
;;
debian10*)
check_apt_install libc abi1-7
;;
debian*)
check_apt_install libc abi1-16
local _ostype="debian12"
;;
fedora39* | fedora40* | fedora41*)
check_dnf_install libcxxabi
local _ostype="fedora39"
;;
centos9*)
check_yum_install_rpm libcxxabi https://kojipkgs.fedoraproject.org//packages/libcxx/17.0.4/1.fc39/x86_64/libcxxabi-17.0.4-1.fc39.x86_64.rpm
;;
arch* | manjaro* | endeavouros* | garuda*)
check_pacman_install libc abi
local _ostype="ubuntu20.04"
;;
*)
err "no precompiled binaries available for OS: $_ostype"
;;
esac
;;
Darwin)
local _ostype=darwin
;;
MINGW* | MSYS* | CYGWIN*)
err "please run this installation script inside Windows Subsystem for Linux (WSL 2)"
;;
*)
err "no precompiled binaries available for OS: $_ostype"
;;
esac
case "$_cputype" in
x86_64 | x86-64 | x64 | amd64)
local _cputype=x86_64
;;
arm64 | aarch64)
local _cputype=aarch64
;;
*)
err "no precompiled binaries available for CPU architecture: $_cputype"
esac
if [ "$_cputype" = aarch64 ] && [ "$_ostype" = apple-darwin ]; then
_cputype="x86_64"
fi
local _arch="$_cputype-$_ostype"
RETVAL="$_arch"
}
say() {
echo "FireDBG: $1"
}
err() {
say "$1" >&2
exit 1
}
need_cmd() {
if ! check_cmd "$1"
then err "need '$1' (command not found)"
fi
}
check_cmd() {
command -v "$1" > /dev/null 2>&1
return $?
}
need_ok() {
if [ $? != 0 ]; then err "$1"; fi
}
assert_nz() {
if [ -z "$1" ]; then err "assert_nz $2"; fi
}
# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing
# command.
ensure() {
"$@"
need_ok "command failed: $*"
}
ignore() {
"$@"
}
# This wraps curl or wget. Try curl first, if not installed,
# use wget instead.
downloader() {
if check_cmd curl
then _dld=curl
elif check_cmd wget
then _dld=wget
else _dld='curl or wget' # to be used in error message of need_cmd
fi
if [ "$1" = --check ]
then need_cmd "$_dld"
elif [ "$_dld" = curl ]
then curl -sSfL "$1" -o "$2"
elif [ "$_dld" = wget ]
then wget "$1" -O "$2"
else err "Unknown downloader" # should not reach here
fi
}
check_apt_install() {
if [ "$(dpkg-query -l | grep $1 | wc -l)" = 0 ]; then
run_sudo apt install -y $1
fi
}
check_dnf_install() {
if [ "$(dnf list installed | grep $1 | wc -l)" = 0 ]; then
run_sudo dnf install -y $1
fi
}
check_yum_install_rpm() {
if [ "$(dnf list installed | grep $1 | wc -l)" = 0 ]; then
run_sudo yum install -y $2
fi
}
check_pacman_install() {
if [ "$(pacman -Q | grep $1 | wc -l)" = 0 ]; then
run_sudo pacman -S --noconfirm $1
fi
}
run_sudo() {
if ! check_cmd "sudo"
then $@
else sudo $@
fi
}
main "$@" || exit 1