forked from databendlabs/databend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev_setup.sh
More file actions
executable file
·975 lines (853 loc) · 20.9 KB
/
Copy pathdev_setup.sh
File metadata and controls
executable file
·975 lines (853 loc) · 20.9 KB
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
#!/bin/bash
# Copyright (c) The Diem Core Contributors.
# Copyright 2020-2021 The Databend Authors.
# SPDX-License-Identifier: Apache-2.0.
set -e
SCRIPT_PATH="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
cd "$SCRIPT_PATH/../.." || exit
# NOTE: never use sudo under macos
PRE_COMMAND=()
if [[ "$(whoami)" != 'root' ]] && [[ ${PACKAGE_MANAGER} != "brew" ]]; then
PRE_COMMAND=(sudo)
fi
function add_to_profile {
eval "$1"
FOUND=$(grep -c "$1" "${HOME}/.profile" || true)
if [ "$FOUND" == "0" ]; then
echo "$1" >>"${HOME}"/.profile
fi
}
function update_path_and_profile {
touch "${HOME}"/.profile
mkdir -p "${HOME}"/bin
if [ -n "$CARGO_HOME" ]; then
add_to_profile "export CARGO_HOME=\"${CARGO_HOME}\""
add_to_profile "export PATH=\"${HOME}/bin:${CARGO_HOME}/bin:\$PATH\""
else
add_to_profile "export PATH=\"${HOME}/bin:${HOME}/.cargo/bin:\$PATH\""
fi
}
function install_pkg {
package=$1
PACKAGE_MANAGER=$2
if which "$package" &>/dev/null; then
echo "$package is already installed"
else
echo "Installing ${package}."
case "$PACKAGE_MANAGER" in
apt-get)
"${PRE_COMMAND[@]}" apt-get install --no-install-recommends -yq "${package}"
;;
yum)
"${PRE_COMMAND[@]}" yum install -y -q "${package}"
;;
pacman)
"${PRE_COMMAND[@]}" pacman --quiet --noconfirm -Syu "$package"
;;
apk)
apk --quiet --update add --no-cache "${package}"
;;
dnf)
dnf --quiet install "$package"
;;
brew)
brew install --quiet "$package"
;;
*)
echo "Unable to install ${package} package manager: $PACKAGE_MANAGER"
exit 1
;;
esac
fi
}
function install_build_essentials {
PACKAGE_MANAGER=$1
echo "==> installing build essentials..."
case "$PACKAGE_MANAGER" in
apt-get)
install_pkg build-essential "$PACKAGE_MANAGER"
;;
pacman)
install_pkg base-devel "$PACKAGE_MANAGER"
;;
apk)
install_pkg alpine-sdk "$PACKAGE_MANAGER"
install_pkg coreutils "$PACKAGE_MANAGER"
;;
yum | dnf)
install_pkg gcc "$PACKAGE_MANAGER"
install_pkg gcc-c++ "$PACKAGE_MANAGER"
install_pkg make "$PACKAGE_MANAGER"
;;
brew)
# skip
;;
*)
echo "Unable to install build essentials with package manager: $PACKAGE_MANAGER"
exit 1
;;
esac
}
function install_python3 {
PACKAGE_MANAGER=$1
if python3 --version; then
echo "==> python3 is already installed"
return
fi
echo "==> installing python3..."
case "$PACKAGE_MANAGER" in
apt-get)
install_pkg python3-all-dev "$PACKAGE_MANAGER"
install_pkg python3-setuptools "$PACKAGE_MANAGER"
install_pkg python3-pip "$PACKAGE_MANAGER"
install_pkg libcairo2-dev "$PACKAGE_MANAGER"
;;
apk)
install_pkg python3-dev "$PACKAGE_MANAGER"
install_pkg py3-pip "$PACKAGE_MANAGER"
install_pkg libffi-dev "$PACKAGE_MANAGER"
;;
brew | pacman)
install_pkg python3 "$PACKAGE_MANAGER"
install_pkg cairo "$PACKAGE_MANAGER"
;;
yum | dnf)
install_pkg python3-devel "$PACKAGE_MANAGER"
install_pkg cairo-devel "$PACKAGE_MANAGER"
;;
*)
echo "Unable to install python3 with package manager: $PACKAGE_MANAGER"
exit 1
;;
esac
}
function install_openssl {
PACKAGE_MANAGER=$1
echo "==> installing openssl libs..."
install_pkg perl-core "$PACKAGE_MANAGER" || echo "perl-core skipped"
install_pkg perl-CPAN "$PACKAGE_MANAGER" || echo "perl-CPAN skipped"
install_pkg perl-devel "$PACKAGE_MANAGER" || echo "perl-devel skipped"
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e 'install IPC::Cmd'
case "$PACKAGE_MANAGER" in
apt-get)
install_pkg libssl-dev "$PACKAGE_MANAGER"
;;
pacman)
install_pkg openssl "$PACKAGE_MANAGER"
;;
apk)
install_pkg openssl-dev "$PACKAGE_MANAGER"
install_pkg openssl-libs-static "$PACKAGE_MANAGER"
;;
yum)
install_pkg openssl-devel "$PACKAGE_MANAGER"
;;
dnf)
install_pkg openssl-devel "$PACKAGE_MANAGER"
;;
brew)
install_pkg openssl "$PACKAGE_MANAGER"
;;
*)
echo "Unable to install openssl with package manager: $PACKAGE_MANAGER"
exit 1
;;
esac
}
function install_protobuf {
PACKAGE_MANAGER=$1
if protoc --version; then
echo "==> protoc is already installed"
return
fi
echo "==> installing protobuf compiler..."
case "$PACKAGE_MANAGER" in
brew | apk)
install_pkg protobuf "$PACKAGE_MANAGER"
;;
*)
arch=$(uname -m)
arch=${arch/aarch64/aarch_64}
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v3.15.8/protoc-3.15.8-linux-${arch}.zip
unzip protoc-3.15.8-linux-${arch}.zip -d protoc-3.15.8
"${PRE_COMMAND[@]}" cp protoc-3.15.8/bin/protoc /usr/local/bin/
"${PRE_COMMAND[@]}" cp -r protoc-3.15.8/include /usr/local/
"${PRE_COMMAND[@]}" rm -rf protoc-3.15.8*
"${PRE_COMMAND[@]}" chmod +x /usr/local/bin/protoc
;;
esac
protoc --version
}
function ensure_clang_toolchain {
PACKAGE_MANAGER=$1
case "$PACKAGE_MANAGER" in
brew)
BREW_LLVM_PATHS=(
/opt/homebrew/opt/llvm/bin/clang
/usr/local/opt/llvm/bin/clang
)
for brew_clang in "${BREW_LLVM_PATHS[@]}"; do
if [[ -x "$brew_clang" ]]; then
echo "==> Homebrew llvm already installed (${brew_clang})"
return
fi
done
echo "==> Homebrew llvm clang not found, installing with brew"
;;
*)
if command -v clang >/dev/null 2>&1; then
clang_version=$(clang --version | head -n 1)
echo "==> clang is already installed (${clang_version})"
return
fi
echo "==> clang not found, installing with ${PACKAGE_MANAGER}"
;;
esac
install_pkg clang "$PACKAGE_MANAGER"
install_pkg llvm "$PACKAGE_MANAGER"
}
function install_jdk {
PACKAGE_MANAGER=$1
echo "==> installing java development kit..."
case "$PACKAGE_MANAGER" in
apt-get)
install_pkg openjdk-11-jdk-headless "$PACKAGE_MANAGER"
;;
pacman)
install_pkg jre11-openjdk-headless "$PACKAGE_MANAGER"
;;
apk)
install_pkg openjdk11 "$PACKAGE_MANAGER"
;;
yum)
install_pkg java-11-openjdk "$PACKAGE_MANAGER"
;;
dnf)
install_pkg java-11-openjdk "$PACKAGE_MANAGER"
;;
brew)
install_pkg java11 "$PACKAGE_MANAGER"
;;
*)
echo "Unable to install jdk with package manager: $PACKAGE_MANAGER"
exit 1
;;
esac
}
function install_lapack {
PACKAGE_MANAGER=$1
echo "==> installing lapack library..."
case "$PACKAGE_MANAGER" in
apt-get)
install_pkg liblapack-dev "$PACKAGE_MANAGER"
;;
pacman)
install_pkg lapack "$PACKAGE_MANAGER"
;;
apk)
install_pkg lapack-dev "$PACKAGE_MANAGER"
;;
yum)
install_pkg lapack-devel "$PACKAGE_MANAGER"
;;
dnf)
install_pkg lapack-devel "$PACKAGE_MANAGER"
;;
brew)
install_pkg lapack "$PACKAGE_MANAGER"
;;
*)
echo "Unable to install lapack with package manager: $PACKAGE_MANAGER"
exit 1
;;
esac
}
function install_pkg_config {
PACKAGE_MANAGER=$1
echo "==> installing pkg-config..."
case "$PACKAGE_MANAGER" in
apt-get | dnf)
install_pkg pkg-config "$PACKAGE_MANAGER"
;;
pacman)
install_pkg pkgconf "$PACKAGE_MANAGER"
;;
apk | brew | yum)
install_pkg pkgconfig "$PACKAGE_MANAGER"
;;
*)
echo "Unable to install pkg-config with package manager: $PACKAGE_MANAGER"
exit 1
;;
esac
}
function install_mysql_client {
PACKAGE_MANAGER=$1
echo "==> installing mysql client..."
case "$PACKAGE_MANAGER" in
apt-get)
install_pkg default-mysql-client "$PACKAGE_MANAGER"
;;
pacman)
install_pkg mysql-clients "$PACKAGE_MANAGER"
;;
apk)
install_pkg mysql-client "$PACKAGE_MANAGER"
;;
yum | dnf | brew)
install_pkg mysql "$PACKAGE_MANAGER"
;;
*)
echo "Unable to install mysql client with package manager: $PACKAGE_MANAGER"
exit 1
;;
esac
}
function install_sqlite3 {
PACKAGE_MANAGER=$1
echo "==> installing sqlite3..."
case "$PACKAGE_MANAGER" in
apt-get)
install_pkg libsqlite3-dev "$PACKAGE_MANAGER"
install_pkg sqlite3 "$PACKAGE_MANAGER"
;;
pacman)
install_pkg sqlite "$PACKAGE_MANAGER"
;;
apk)
install_pkg sqlite-dev "$PACKAGE_MANAGER"
;;
yum | dnf)
install_pkg sqlite-devel "$PACKAGE_MANAGER"
install_pkg sqlite "$PACKAGE_MANAGER"
;;
brew)
install_pkg sqlite "$PACKAGE_MANAGER"
;;
*)
echo "Unable to install sqlite3 with package manager: $PACKAGE_MANAGER"
exit 1
;;
esac
}
function install_libtiff {
PACKAGE_MANAGER=$1
echo "==> installing libtiff..."
case "$PACKAGE_MANAGER" in
apt-get)
install_pkg libtiff-dev "$PACKAGE_MANAGER"
;;
pacman)
install_pkg libtiff "$PACKAGE_MANAGER"
;;
apk)
install_pkg tiff-dev "$PACKAGE_MANAGER"
;;
yum | dnf)
install_pkg libtiff-devel "$PACKAGE_MANAGER"
;;
brew)
install_pkg libtiff "$PACKAGE_MANAGER"
;;
*)
echo "Unable to install libtiff with package manager: $PACKAGE_MANAGER"
exit 1
;;
esac
}
function install_binutils {
PACKAGE_MANAGER=$1
echo "==> installing binutils..."
case "$PACKAGE_MANAGER" in
apt-get)
install_pkg binutils "$PACKAGE_MANAGER"
;;
yum | dnf)
install_pkg binutils "$PACKAGE_MANAGER"
;;
brew)
# skip
;;
*)
echo "Unable to install binutils with package manager: $PACKAGE_MANAGER"
exit 1
;;
esac
}
function install_rustup {
RUST_TOOLCHAIN=$1
echo "==> Installing Rust......"
if rustup --version &>/dev/null; then
echo "Rust is already installed"
else
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain "${RUST_TOOLCHAIN}" --profile minimal
PATH="${HOME}/.cargo/bin:${PATH}"
source "$HOME"/.cargo/env
fi
rustup show
}
function install_sccache {
local version="$1"
echo "==> installing sccache..."
if sccache --version &>/dev/null; then
echo "sccache is already installed"
return
fi
if [[ -z "$version" ]]; then
echo "Missing sccache version"
return 1
fi
local os
os="$(uname -s)"
if [[ "$os" == "Darwin" ]]; then
brew install sccache
sccache --version
return
fi
if [[ "$os" != "Linux" ]]; then
echo "Unsupported operating system for sccache: $(uname -s)"
return 1
fi
local arch triple asset url tmpdir extract_dir cargo_bin
case "$(uname -m)" in
x86_64 | amd64)
triple="x86_64-unknown-linux-musl"
;;
aarch64 | arm64)
triple="aarch64-unknown-linux-musl"
;;
*)
echo "Unsupported architecture for sccache: $(uname -m)"
return 1
;;
esac
asset="sccache-${version}-${triple}.tar.gz"
url="https://github.com/mozilla/sccache/releases/download/${version}/${asset}"
tmpdir=$(mktemp -d)
if ! curl -fsSL "$url" -o "${tmpdir}/${asset}"; then
rm -rf "$tmpdir"
echo "Failed to download sccache from ${url}"
return 1
fi
if ! tar -xzf "${tmpdir}/${asset}" -C "$tmpdir"; then
rm -rf "$tmpdir"
echo "Failed to extract sccache archive"
return 1
fi
CARGO_HOME="${CARGO_HOME:-${HOME}/.cargo}"
cargo_bin="${CARGO_HOME}/bin"
mkdir -p "$cargo_bin"
extract_dir="${tmpdir}/sccache-${version}-${triple}"
if [[ ! -f "${extract_dir}/sccache" ]]; then
rm -rf "$tmpdir"
echo "sccache binary not found in archive"
return 1
fi
install -m 755 "${extract_dir}/sccache" "${cargo_bin}/sccache"
rm -rf "$tmpdir"
sccache --version
}
function install_cargo_nextest {
CARGO_HOME="${CARGO_HOME:-${HOME}/.cargo}"
if [[ "$(uname -s)" == "Darwin" ]]; then
brew install cargo-nextest
else
if [[ "$(uname -s)" != "Linux" ]]; then
echo "Unsupported operating system for cargo-nextest: $(uname -s)"
return 1
fi
local nextest_url
case "$(uname -m)" in
x86_64 | amd64)
nextest_url="https://get.nexte.st/latest/linux"
;;
aarch64 | arm64)
nextest_url="https://get.nexte.st/latest/linux-arm"
;;
*)
echo "Unsupported architecture for cargo-nextest: $(uname -m)"
return 1
;;
esac
mkdir -p "${CARGO_HOME}/bin"
curl -LsSf "${nextest_url}" | tar zxf - -C "${CARGO_HOME}/bin"
fi
cargo nextest --version
}
function install_taplo_cli {
echo "==> installing taplo CLI..."
if taplo --version &>/dev/null; then
echo "taplo CLI is already installed"
return
fi
local os
os="$(uname -s)"
if [[ "$os" == "Darwin" ]]; then
brew install taplo
taplo --version
return
fi
if [[ "$os" != "Linux" ]]; then
echo "Unsupported operating system for taplo CLI: $(uname -s)"
return 1
fi
local taplo_bin arch asset url tmpfile
CARGO_HOME="${CARGO_HOME:-${HOME}/.cargo}"
taplo_bin="${CARGO_HOME}/bin"
mkdir -p "$taplo_bin"
case "$(uname -m)" in
x86_64 | amd64)
arch="x86_64"
;;
aarch64 | arm64)
arch="aarch64"
;;
*)
echo "Unsupported architecture for taplo CLI: $(uname -m)"
return 1
;;
esac
asset="taplo-linux-${arch}.gz"
url="https://github.com/tamasfe/taplo/releases/latest/download/${asset}"
tmpfile=$(mktemp)
if ! curl -fsSL "$url" | gzip -dc >"$tmpfile"; then
rm -f "$tmpfile"
echo "Failed to download taplo CLI from ${url}"
return 1
fi
chmod +x "$tmpfile"
install -m 755 "$tmpfile" "${taplo_bin}/taplo"
rm -f "$tmpfile"
"${taplo_bin}/taplo" --version
}
function install_typos_cli {
echo "==> installing typos CLI..."
if typos --version &>/dev/null; then
echo "typos CLI is already installed"
return
fi
local os
os="$(uname -s)"
if [[ "$os" == "Darwin" ]]; then
brew install typos-cli
typos --version
return
fi
if [[ "$os" != "Linux" ]]; then
echo "Unsupported operating system for typos CLI: $(uname -s)"
return 1
fi
local typos_bin arch triple version tag package url tmpdir
CARGO_HOME="${CARGO_HOME:-${HOME}/.cargo}"
typos_bin="${CARGO_HOME}/bin"
mkdir -p "$typos_bin"
case "$(uname -m)" in
x86_64 | amd64)
triple="x86_64-unknown-linux-musl"
;;
aarch64 | arm64)
triple="aarch64-unknown-linux-musl"
;;
*)
echo "Unsupported architecture for typos CLI: $(uname -m)"
return 1
;;
esac
version="1.40.0"
tag="v${version}"
package="typos-${tag}-${triple}.tar.gz"
url="https://github.com/crate-ci/typos/releases/download/${tag}/${package}"
tmpdir=$(mktemp -d)
if ! curl -fsSL "$url" -o "${tmpdir}/${package}"; then
rm -rf "$tmpdir"
echo "Failed to download typos CLI from ${url}"
return 1
fi
if ! tar -xzf "${tmpdir}/${package}" -C "$tmpdir"; then
rm -rf "$tmpdir"
echo "Failed to extract typos CLI package"
return 1
fi
if [[ ! -f "${tmpdir}/typos" ]]; then
rm -rf "$tmpdir"
echo "typos binary not found in package ${package}"
return 1
fi
install -m 755 "${tmpdir}/typos" "${typos_bin}/typos"
rm -rf "$tmpdir"
"${typos_bin}/typos" --version
}
function install_cargo_valgrind {
echo "==> installing cargo-valgrind..."
if cargo valgrind --version &>/dev/null; then
echo "cargo-valgrind is already installed"
return
fi
cargo install cargo-valgrind
cargo valgrind --version
}
function usage {
cat <<EOF
usage: $0 [options]
options:
-y Auto approve installation
-b Install build tools
-d Install development tools
-p Install profile
-s Install codegen tools
-t Install tpch data set
-v Verbose mode
EOF
}
function welcome_message {
cat <<EOF
Welcome to DatabendQuery!
This script will download and install the necessary dependencies needed to
build, test and inspect DatabendQuery.
Based on your selection, these tools will be included:
EOF
if [[ "$INSTALL_BUILD_TOOLS" == "true" ]]; then
cat <<EOF
Build tools (since -b or no option was provided):
* Rust (and the necessary components, e.g. rust-fmt, clippy)
* build-essential
* pkg-config
* libssl-dev
* protobuf-compiler
* openjdk
* python3-dev
* cargo-valgrind
EOF
fi
if [[ "$INSTALL_CHECK_TOOLS" == "true" ]]; then
cat <<EOF
Check tools (since -c was provided):
* lcov
* taplo CLI
* typos CLI
EOF
fi
if [[ "$INSTALL_DEV_TOOLS" == "true" ]]; then
cat <<EOF
Development tools (since -d was provided):
* mysql client
* python3 (boto3, ruff, yamllint, ...)
* python database drivers (mysql-connector-python, pymysql, sqlalchemy)
EOF
fi
if [[ "$INSTALL_CODEGEN" == "true" ]]; then
cat <<EOF
Codegen tools (since -s was provided):
* Python3 (numpy, pyre-check)
EOF
fi
if [[ "$INSTALL_PROFILE" == "true" ]]; then
cat <<EOF
Moreover, ~/.profile will be updated (since -p was provided).
EOF
fi
if [[ "$INSTALL_TPCH_DATA" == "true" ]]; then
cat <<EOF
Tpch dataset (since -t was provided):
EOF
fi
cat <<EOF
If you'd prefer to install these dependencies yourself, please exit this script
now with Ctrl-C.
EOF
}
AUTO_APPROVE=false
VERBOSE=false
INSTALL_BUILD_TOOLS=false
INSTALL_CHECK_TOOLS=false
INSTALL_DEV_TOOLS=false
INSTALL_PROFILE=false
INSTALL_CODEGEN=false
INSTALL_TPCH_DATA=false
TPCH_SCALE_FACTOR=$2
# parse args
while getopts "ybcdpstv" arg; do
case "$arg" in
y)
AUTO_APPROVE="true"
;;
b)
INSTALL_BUILD_TOOLS="true"
;;
c)
INSTALL_CHECK_TOOLS="true"
;;
d)
INSTALL_DEV_TOOLS="true"
;;
p)
INSTALL_PROFILE="true"
;;
s)
INSTALL_CODEGEN="true"
;;
v)
VERBOSE="true"
;;
t)
INSTALL_TPCH_DATA="true"
;;
*)
usage
exit 0
;;
esac
done
if [[ "$VERBOSE" == "true" ]]; then
set -x
fi
if [[ "$INSTALL_BUILD_TOOLS" == "false" ]] &&
[[ "$INSTALL_CHECK_TOOLS" == "false" ]] &&
[[ "$INSTALL_DEV_TOOLS" == "false" ]] &&
[[ "$INSTALL_PROFILE" == "false" ]] &&
[[ "$INSTALL_TPCH_DATA" == "false" ]] &&
[[ "$INSTALL_CODEGEN" == "false" ]]; then
INSTALL_BUILD_TOOLS="true"
fi
if [ ! -f rust-toolchain.toml ]; then
echo "Unknown location. Please run this from the databend repository. Abort."
exit 1
fi
RUST_TOOLCHAIN="$(awk -F'[ ="]+' '$1 == "channel" { print $2 }' rust-toolchain.toml)"
PACKAGE_MANAGER=
if [[ "$(uname)" == "Linux" ]]; then
if command -v yum &>/dev/null; then
PACKAGE_MANAGER="yum"
elif command -v apt-get &>/dev/null; then
PACKAGE_MANAGER="apt-get"
elif command -v pacman &>/dev/null; then
PACKAGE_MANAGER="pacman"
elif command -v apk &>/dev/null; then
PACKAGE_MANAGER="apk"
elif command -v dnf &>/dev/null; then
echo "WARNING: dnf package manager support is experimental"
PACKAGE_MANAGER="dnf"
else
echo "Unable to find supported package manager (yum, apt-get, dnf, apk, or pacman). Abort"
exit 1
fi
elif [[ "$(uname)" == "Darwin" ]]; then
if which brew &>/dev/null; then
PACKAGE_MANAGER="brew"
else
echo "Missing package manager Homebrew (https://brew.sh/). Abort"
exit 1
fi
else
echo "Unknown OS. Abort."
exit 1
fi
if [[ "$AUTO_APPROVE" == "false" ]]; then
welcome_message
printf "Proceed with installing necessary dependencies? (y/N) > "
read -e -r input
if [[ "$input" != "y"* ]]; then
echo "Exiting..."
exit 0
fi
fi
case "$PACKAGE_MANAGER" in
apt-get)
"${PRE_COMMAND[@]}" apt-get update
install_pkg ca-certificates "$PACKAGE_MANAGER"
;;
yum | dnf)
install_pkg epel-release "$PACKAGE_MANAGER"
;;
*) ;;
esac
[[ "$INSTALL_PROFILE" == "true" ]] && update_path_and_profile
install_pkg curl "$PACKAGE_MANAGER"
if [[ "$INSTALL_BUILD_TOOLS" == "true" ]]; then
install_rustup "$RUST_TOOLCHAIN"
install_pkg unzip "$PACKAGE_MANAGER"
install_build_essentials "$PACKAGE_MANAGER"
install_pkg_config "$PACKAGE_MANAGER"
install_openssl "$PACKAGE_MANAGER"
install_protobuf "$PACKAGE_MANAGER"
install_jdk "$PACKAGE_MANAGER"
install_lapack "$PACKAGE_MANAGER"
install_pkg cmake "$PACKAGE_MANAGER"
ensure_clang_toolchain "$PACKAGE_MANAGER"
install_python3 "$PACKAGE_MANAGER"
install_sqlite3 "$PACKAGE_MANAGER"
install_libtiff "$PACKAGE_MANAGER"
install_binutils "$PACKAGE_MANAGER"
# Any call to cargo will make rustup install the correct toolchain
cargo version
install_sccache "v0.12.0"
install_cargo_nextest
install_cargo_valgrind
fi
if [[ "$INSTALL_CHECK_TOOLS" == "true" ]]; then
if [[ "$PACKAGE_MANAGER" == "apk" ]]; then
# needed by lcov
echo http://nl.alpinelinux.org/alpine/edge/testing >>/etc/apk/repositories
fi
install_pkg lcov "$PACKAGE_MANAGER"
install_taplo_cli
install_typos_cli
fi
if [[ "$INSTALL_DEV_TOOLS" == "true" ]]; then
install_mysql_client "$PACKAGE_MANAGER"
install_pkg git "$PACKAGE_MANAGER"
install_python3 "$PACKAGE_MANAGER"
if [[ "$PACKAGE_MANAGER" == "apt-get" ]]; then
# for killall & timeout
install_pkg psmisc "$PACKAGE_MANAGER"
install_pkg coreutils "$PACKAGE_MANAGER"
# for graphviz, that fuzzingbook depends on
install_pkg graphviz "$PACKAGE_MANAGER"
install_pkg graphviz-dev "$PACKAGE_MANAGER"
fi
python3 -m pip install --quiet boto3 "moto[all]" shfmt-py toml yamllint ruff
# drivers
python3 -m pip install --quiet pymysql sqlalchemy
# sqllogic dependencies
python3 -m pip install --quiet mysql-connector-python==8.0.30
fi
if [[ "$INSTALL_CODEGEN" == "true" ]]; then
ensure_clang_toolchain "$PACKAGE_MANAGER"
install_python3 "$PACKAGE_MANAGER"
"${PRE_COMMAND[@]}" python3 -m pip install --quiet coscmd PyYAML
fi
if [[ "$INSTALL_TPCH_DATA" == "true" ]]; then
# Construct a docker imagine to generate tpch-data
if [[ -z ${TPCH_SCALE_FACTOR} ]]; then
docker build -f scripts/setup/tpchdata.dockerfile -t databend:latest .
else
docker build -f scripts/setup/tpchdata.dockerfile -t databend:latest \
--build-arg scale_factor="${TPCH_SCALE_FACTOR}" .
fi
# Generate data into the ./data directory if it does not already exist
FILE=benchmark/tpch/data/customer.tbl
if test -f "$FILE"; then
echo "$FILE exists."
else
mkdir "$(pwd)/benchmark/tpch/data" 2>/dev/null
docker run -v "$(pwd)/benchmark/tpch/data:/data" --rm databend:latest
fi
fi
if [[ "${AUTO_APPROVE}" == "false" ]]; then
if [[ "$INSTALL_BUILD_TOOLS" == "true" ]]; then
cat <<EOF
Finished installing all build dependencies.
You should now be able to build the project by running:
cargo build
EOF
fi
if [[ "$INSTALL_DEV_TOOLS" == "true" ]]; then
cat <<EOF
Finished installing all dev dependencies.
You should now be able to run tests with:
make xxx-test (check Makefile for detailed target)
EOF
fi
fi
exit 0