-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
679 lines (595 loc) · 25.9 KB
/
build
File metadata and controls
679 lines (595 loc) · 25.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
#!/bin/bash
#==============================================================#
# File : setup.sh
# Desc : setup extension building environment
# Ctime : 2024-12-12
# Mtime : 2025-01-10
# Path : setup.sh
# License : AGPLv3 @ https://pigsty.io/docs/about/license
# Copyright : 2018-2024 Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#
# curl https://repo.pigsty.cc/build | sh
# curl https://repo.pigsty.cc/rays | sh
#--------------------------------------------------------------#
# Usage
#--------------------------------------------------------------#
# boostrap [-r <region>] [-p <path>] [-k|--keep]
#
# ./boostrap
# [-r|--region <region] [default,china,europe]
# [-p|--path <path>] specify another offline pkg path
# [-k|--keep] keep existing upstream repo during bootstrap
#--------------------------------------------------------------#
# args
# -r --region <region> : mirror region to use (default|china|europe)
# -p --path <path> : offline packages path, /tmp/pkg.tgz by default
# -k --keep : keep upstream repo during bootstrap?
#--------------------------------------------------------------#
REGION="" # which mirror to use? (default|china)
REMOVE_REPO="yes" # keep existing upstream repo file?
#--------------------------------------------------------------#
# Utils
#--------------------------------------------------------------#
__CN='\033[0m';__CB='\033[0;30m';__CR='\033[0;31m';__CG='\033[0;32m';
__CY='\033[0;33m';__CB='\033[0;34m';__CM='\033[0;35m';__CC='\033[0;36m';__CW='\033[0;37m';
function log_info() { printf "[${__CG} OK ${__CN}] ${__CG}$*${__CN}\n"; }
function log_warn() { printf "[${__CY}WARN${__CN}] ${__CY}$*${__CN}\n"; }
function log_error() { printf "[${__CR}FAIL${__CN}] ${__CR}$*${__CN}\n"; }
function log_debug() { printf "[${__CB}HINT${__CN}] ${__CB}$*${__CN}\n"; }
function log_input() { printf "[${__CM} IN ${__CN}] ${__CM}$*\n=> ${__CN}"; }
function log_hint() { printf "${__CB}$*${__CN}"; }
ipv4_regexp='(([0-9]|[0-9]{2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[0-9]{2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])'
#--------------------------------------------------------------#
# Param
#--------------------------------------------------------------#
PROG_NAME="$(basename $0)"
PROG_DIR="$(cd $(dirname $0) && pwd)"
PIGSTY_HOME="${PROG_DIR}"
REPO_NAME=pigsty
NGINX_HOME=/www
REPO_DIR=${NGINX_HOME}/${REPO_NAME}
BIN_DIR=${PIGSTY_HOME}/files/bin
# extract os vendor & version from /etc/os-release
OS_VENDOR=""
OS_VERSION=""
OS_PACKAGE=""
OS_MANAGER=""
OS_CODENAME=""
ARCH=$(uname -m)
#----------------------------------------------#
# region
#----------------------------------------------#
# return 0 if behind gfw (inside mainland china), otherwise 1
function behind_gfw() {
local return_code=$(curl -I -s --connect-timeout 1 www.google.com -w %{http_code} | tail -n1)
if [ "${return_code}" = "200" ]; then
return 1
fi
return 0
}
function check_internet() {
if ping -c 1 -W 1 1.1.1.1 >/dev/null 2>&1; then
return 0
else
return 1
fi
}
function check_region(){
if [ "${REGION}" == "" ]; then
if behind_gfw; then
REGION=china # mainland china is behind GFW
else
REGION=default # otherwise use default mirror
fi
log_info "region = ${REGION}"
fi
}
#----------------------------------------------#
# kernel
#----------------------------------------------#
function check_kernel(){
local kernel_name=$(uname -s)
if [[ "${kernel_name}" == "Linux" ]]; then
log_info "kernel = ${kernel_name}"
return 0
else
log_error "kernel = ${kernel_name}, not supported, Linux only"
exit 1
fi
}
#----------------------------------------------#
# machine
#----------------------------------------------#
function check_machine(){
local machine_name=$(uname -m)
if [[ "${machine_name}" == "x86_64" ]]; then
log_info "machine = ${machine_name}"
return 0
elif [[ "${machine_name}" == "aarch64" ]]; then
log_warn "machine = ${machine_name}"
return 0
else
log_error "machine = ${machine_name}, not supported, x86_64/aarch64 only"
exit 2
fi
}
#----------------------------------------------#
# os package manager (yum|apt|...)
#----------------------------------------------#
function check_package_manager(){
# get package / manager: rpm|deb and dnf|yum|apt|apt-get|zypper
if command -v dpkg >/dev/null 2>&1; then
OS_PACKAGE="deb"
if command -v apt >/dev/null 2>&1; then
OS_MANAGER="apt"
elif command -v apt-get >/dev/null 2>&1; then
OS_MANAGER="apt-get"
else
log_error "fail to determine os package manager for deb"
exit 4
fi
elif command -v rpm >/dev/null 2>&1; then
OS_PACKAGE="rpm"
if command -v dnf >/dev/null 2>&1; then
OS_MANAGER="dnf"
elif command -v yum >/dev/null 2>&1; then
OS_MANAGER="yum"
elif command -v zypper >/dev/null 2>&1; then
OS_MANAGER="zypper"
else
log_error "fail to determine os package manager for rpm"
exit 4
fi
else
log_error "fail to determine os package type"
exit 3
fi
log_info "package = ${OS_PACKAGE},${OS_MANAGER}"
}
#----------------------------------------------#
# os release (Linux|Darwin etc..)
#----------------------------------------------#
function check_vendor_version(){
if [[ -f /etc/os-release ]]; then
. /etc/os-release
OS_VENDOR="$ID"
OS_VERSION="$VERSION_ID"
OS_CODENAME=${VERSION_CODENAME-''}
if [[ $VERSION_ID == *.* ]]; then
OS_VERSION=$(echo "$VERSION_ID" | cut -d. -f1)
else
OS_VERSION="${VERSION_ID}"
fi
log_info "vendor = ${OS_VENDOR} (${NAME})"
log_info "version = ${OS_VERSION} (${VERSION_ID})"
return 0
else
log_error "/etc/os-release file not found, unknown OS"
exit 5
fi
}
function add_el8_repo(){
cat > "/tmp/el8.repo" <<-'EOF'
# el8
[baseos]
name = EL 8+ BaseOS $releasever - $basearch
baseurl = https://mirrors.aliyun.com/rockylinux/8/BaseOS/$basearch/os/
gpgcheck = 0
enabled = 1
module_hotfixes=1
[appstream]
name = EL 8+ AppStream $releasever - $basearch
baseurl = https://mirrors.aliyun.com/rockylinux/8/AppStream/$basearch/os/
gpgcheck = 0
enabled = 1
module_hotfixes=1
[extras]
name = EL 8+ Extras $releasever - $basearch
baseurl = https://mirrors.aliyun.com/rockylinux/8/extras/$basearch/os/
gpgcheck = 0
enabled = 1
module_hotfixes=1
[powertools]
name = EL 8 PowerTools $releasever - $basearch
baseurl = https://mirrors.aliyun.com/rockylinux/8/PowerTools/$basearch/os/
gpgcheck = 0
enabled = 1
module_hotfixes=1
[epel]
name = EL 8+ EPEL $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/epel/8/Everything/$basearch/
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg12]
name = PostgreSQL 12 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/12/redhat/rhel-8-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg13]
name = PostgreSQL 13 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/13/redhat/rhel-8-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg14]
name = PostgreSQL 14 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/14/redhat/rhel-8-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg15]
name = PostgreSQL 15 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/15/redhat/rhel-8-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg16]
name = PostgreSQL 16 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/16/redhat/rhel-8-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg17]
name = PostgreSQL 17 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/17/redhat/rhel-8-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg-common]
name = PostgreSQL Common $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/common/redhat/rhel-8-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pigsty-infra]
name = Pigsty Infra $releasever - $basearch
baseurl = https://repo.pigsty.cc/yum/infra/$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
EOF
# add x86_64 only repo
if [[ "${ARCH}" == "x86_64" ]]; then
cat >> "/tmp/el8.repo" <<-'EOF'
[pgdg-el8fix]
name = PostgreSQL EL8FIX $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/common/pgdg-centos8-sysupdates/redhat/rhel-8-x86_64/
gpgcheck = 0
enabled = 1
module_hotfixes=1
EOF
fi
sudo mv -f "/tmp/el8.repo" "/etc/yum.repos.d/el8.repo"
}
function add_el9_repo(){
cat > "/tmp/el9.repo" <<-'EOF'
# el9
# el9
[baseos]
name = EL 8+ BaseOS $releasever - $basearch
baseurl = https://mirrors.aliyun.com/rockylinux/9/BaseOS/$basearch/os/
gpgcheck = 0
enabled = 1
module_hotfixes=1
[appstream]
name = EL 8+ AppStream $releasever - $basearch
baseurl = https://mirrors.aliyun.com/rockylinux/9/AppStream/$basearch/os/
gpgcheck = 0
enabled = 1
module_hotfixes=1
[extras]
name = EL 8+ Extras $releasever - $basearch
baseurl = https://mirrors.aliyun.com/rockylinux/9/extras/$basearch/os/
gpgcheck = 0
enabled = 1
module_hotfixes=1
[crb]
name = EL 9 CRB $releasever - $basearch
baseurl = https://mirrors.aliyun.com/rockylinux/9/CRB/$basearch/os/
gpgcheck = 0
enabled = 1
module_hotfixes=1
[epel]
name = EL 8+ EPEL $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/epel/9/Everything/$basearch/
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg12]
name = PostgreSQL 12 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/12/redhat/rhel-9-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg13]
name = PostgreSQL 13 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/13/redhat/rhel-9-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg14]
name = PostgreSQL 14 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/14/redhat/rhel-9-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg15]
name = PostgreSQL 15 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/15/redhat/rhel-9-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg16]
name = PostgreSQL 16 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/16/redhat/rhel-9-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg17]
name = PostgreSQL 17 $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/17/redhat/rhel-9-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pgdg-common]
name = PostgreSQL Common $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/common/redhat/rhel-9-$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
[pigsty-infra]
name = Pigsty Infra $releasever - $basearch
baseurl = https://repo.pigsty.cc/yum/infra/$basearch
gpgcheck = 0
enabled = 1
module_hotfixes=1
EOF
# add x86_64 only repo
if [[ "${ARCH}" == "x86_64" ]]; then
cat >> "/tmp/el9.repo" <<-'EOF'
[pgdg-el9fix]
name = PostgreSQL EL9FIX $releasever - $basearch
baseurl = https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/yum/common/pgdg-rocky9-sysupdates/redhat/rhel-9-x86_64/
gpgcheck = 0
enabled = 1
module_hotfixes=1
EOF
fi
sudo mv -f "/tmp/el9.repo" "/etc/yum.repos.d/el9.repo"
}
function add_d12_repo(){
cat > "/tmp/sources.list" <<-'EOF'
# d12
deb [trusted=yes] https://mirrors.aliyun.com/debian/ bookworm main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/debian/ bookworm-updates main restricted universe multiverse
#deb [trusted=yes] http://security.debian.org/debian-security bookworm-security main non-free-firmware
deb [trusted=yes] https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/apt/ bookworm-pgdg main
EOF
sudo mv -f "/tmp/sources.list" "/etc/apt/sources.list"
}
function add_u22_repo(){
cat > "/tmp/sources.list" <<-'EOF'
# u22
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb [trusted=yes] https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/apt/ jammy-pgdg main
EOF
sudo mv -f "/tmp/sources.list" "/etc/apt/sources.list"
}
function add_u22_arm_repo(){
cat > "/tmp/sources.list" <<-'EOF'
# u22
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu-ports/ jammy main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu-ports/ jammy-security main restricted universe multiverse
deb [trusted=yes] https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/apt/ jammy-pgdg main
EOF
sudo mv -f "/tmp/sources.list" "/etc/apt/sources.list"
}
function add_u24_repo(){
cat > "/tmp/sources.list" <<-'EOF'
# u24
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb [trusted=yes] https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/apt/ noble-pgdg main
EOF
sudo mv -f "/tmp/sources.list" "/etc/apt/sources.list"
}
function add_u24_arm_repo(){
cat > "/tmp/sources.list" <<-'EOF'
# u24
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu-ports/ noble main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu-ports/ noble-updates main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu-ports/ noble-backports main restricted universe multiverse
deb [trusted=yes] https://mirrors.aliyun.com/ubuntu-ports/ noble-security main restricted universe multiverse
deb [trusted=yes] https://mirrors.tuna.tsinghua.edu.cn/postgresql/repos/apt/ noble-pgdg main
EOF
sudo mv -f "/tmp/sources.list" "/etc/apt/sources.list"
}
function remove_existing_repo(){
if [[ ${REMOVE_REPO} == "yes" ]]; then
if [[ ${OS_PACKAGE} == "rpm" ]]; then
log_warn "old repos = moved to /etc/yum.repos.d/backup"
sudo mkdir -p /etc/yum.repos.d/backup
sudo mv -f /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/ 2> /dev/null || true
fi
if [[ ${OS_PACKAGE} == "deb" ]]; then
log_warn "old repos = moved to /etc/apt/backup"
sudo mkdir -p /etc/apt/backup
sudo mv -f /etc/apt/sources.list.d/* /etc/apt/backup/ 2> /dev/null || true
sudo mv -f /etc/apt/sources.list /etc/apt/backup/ 2> /dev/null || true
sudo rm -rf /tmp/pigsty-local.list;
fi
fi
}
function restore_backup_repo(){
if [[ ${OS_PACKAGE} == "rpm" ]]; then
sudo cp -f /etc/yum.repos.d/backup/*.repo /etc/yum.repos.d/ 2> /dev/null || true
fi
if [[ ${OS_PACKAGE} == "deb" ]]; then
if [[ -f /etc/apt/backup/sources.list ]]; then
sudo mv -f /etc/apt/backup/sources.list /etc/apt/sources.list 2> /dev/null || true
fi
sudo mv -f /etc/apt/backup/* /etc/apt/sources.list.d/ 2> /dev/null || true
fi
}
function add_upstream_repo(){
if [[ ${OS_PACKAGE} == "rpm" ]]; then
if [[ $OS_VERSION == "8" ]]; then
log_info "repo file = add el8 upstream"
add_el8_repo "${REGION}"
elif [[ $OS_VERSION == "9" ]]; then
log_info "repo file = add el9 upstream"
add_el9_repo "${REGION}"
fi
log_info "repo file = add el${OS_VERSION}.${ARCH} ${REGION} upstream"
elif [[ ${OS_PACKAGE} == "deb" ]]; then
if [[ ${OS_VENDOR} == "ubuntu" && ${OS_VERSION} == "22" && ${ARCH} == "x86_64" ]]; then
log_info "repo file = add ubuntu 22 x86_64 upstream"
add_u22_repo "${REGION}"
elif [[ ${OS_VENDOR} == "ubuntu" && ${OS_VERSION} == "22" && ${ARCH} == "aarch64" ]]; then
log_info "repo file = add ubuntu 22 aarch64 upstream"
add_u22_arm_repo "${REGION}"
elif [[ ${OS_VENDOR} == "ubuntu" && ${OS_VERSION} == "24" && ${ARCH} == "x86_64" ]]; then
log_info "repo file = add ubuntu 24 x86_64 upstream"
add_u24_repo "${REGION}"
elif [[ ${OS_VENDOR} == "ubuntu" && ${OS_VERSION} == "24" && ${ARCH} == "aarch64" ]]; then
log_info "repo file = add ubuntu 24 aarch64 upstream"
add_u24_arm_repo "${REGION}"
elif [[ ${OS_VENDOR} == "debian" && ${OS_VERSION} == "12" ]]; then
log_info "repo file = add debian 12 upstream"
add_d12_repo "${REGION}"
fi
log_info "repo file = add ${OS_VENDOR} ${OS_CODENAME} ${REGION} upstream"
fi
}
function make_repo_cache(){
if [[ ${OS_PACKAGE} == "rpm" ]]; then
log_warn "rpm cache = updating, may take a while"
sudo yum clean all -q
sudo yum makecache
elif [[ ${OS_PACKAGE} == "deb" ]]; then
log_warn "apt cache = updating, may take a while"
sudo apt update
fi
log_info "repo cache = created"
}
#----------------------------------------------#
# check_repo_file
#----------------------------------------------#
function check_repo_file(){
remove_existing_repo
add_upstream_repo
make_repo_cache
}
#----------------------------------------------#
# check utils
#----------------------------------------------#
# install ansible sshpass unzip wget yum , etc...
function check_utils(){
local repo_name=${1-${REPO_NAME}}
local nginx_home=${2-${NGINX_HOME}}
local repo_file=/etc/yum.repos.d/${repo_name}-local.repo
# install el utils
if [[ ${OS_PACKAGE} == "rpm" ]]; then
if [[ $OS_VERSION == "8" ]]; then
log_info "install el8 utils"
sudo dnf install -y createrepo_c unzip wget dnf-utils sshpass modulemd-tools
sudo dnf install -y rpm-build rpmdevtools createrepo_c createrepo pkg-config dnf-utils dnf-plugins-core modulemd-tools make cmake ninja-build ccache flex bison CUnit git ncdu wget openssl jq
sudo dnf install -y pgdg-srpm-macros postgresql1*-devel postgresql1*-server python3 python3-pip python3-virtualenv python3.11 python3.11-devel llvm llvm-devel clang libomp libomp-devel lld pam-devel libxslt-devel xxhash-devel systemtap-sdt-devel
sudo dnf install -y readline-devel zlib-devel lz4-devel libzstd-devel openssl-devel krb5-devel hiredis-devel gsl-devel python3-docutils libcurl-devel libxml2-devel gd-devel pcre-devel libical-devel clamav-devel uriparser-devel librdkafka-devel libsodium-devel firebird-devel libfq openblas poppler-glib-devel
elif [[ $OS_VERSION == "9" ]]; then
log_info "install el9 utils"
sudo dnf install -y createrepo_c unzip wget dnf-utils sshpass modulemd-tools
sudo dnf install -y rpm-build rpmdevtools createrepo_c createrepo pkg-config dnf-utils dnf-plugins-core modulemd-tools make cmake ninja-build ccache flex bison CUnit git ncdu wget openssl jq perl-FindBin
sudo dnf install -y pgdg-srpm-macros postgresql1*-devel postgresql1*-server python3 python3-pip python3-virtualenv python3.11 python3.11-devel llvm llvm-devel clang libomp libomp-devel lld pam-devel libxslt-devel xxhash-devel systemtap-sdt-devel #libtinfo5
sudo dnf install -y readline-devel zlib-devel lz4-devel libzstd-devel openssl-devel krb5-devel hiredis-devel gsl-devel python3-docutils libcurl-devel libxml2-devel gd-devel pcre-devel libical-devel clamav-devel uriparser-devel librdkafka-devel libsodium-devel firebird-devel libfq openblas poppler-glib-devel
fi
fi
# install deb utils
if [[ ${OS_PACKAGE} == "deb" ]]; then
if [[ ${OS_VERSION} == "12" ]]; then
log_info "install deb12 utils"
sudo apt install -y unzip wget sshpass acl rsync
sudo apt install -y postgresql-all postgresql-server-dev-all build-essential debhelper devscripts fakeroot pkg-config ninja-build flex bison make cmake git ncdu wget libstdc++-12-dev firebird-dev libtinfo5
sudo apt install -y lz4 unzip bzip2 pv jq git ncdu make patch bash lsof wget uuid tuned nvme-cli numactl sysstat iotop htop rsync tcpdump python3 python3-pip socat lrzsz net-tools ipvsadm telnet ca-certificates openssl chrony zlib1g acl dnsutils libreadline-dev libxxhash-dev systemtap-sdt-dev
sudo apt install -y libreadline-dev zlib1g-dev libicu-dev libssl-dev libpq-dev libxml2-dev libxslt1-dev libldap2-dev libperl-dev libsodium23 libsodium-dev libgd-dev libgc-dev libpam0g-dev libsqlite3-dev libhiredis-dev libgsl-dev python3-dev tcl-dev libkrb5-dev libsasl2-dev uuid-dev libossp-uuid-dev gettext libcurl4-openssl-dev libopenblas-dev liblz4-dev libzstd-dev libpulse-dev liburiparser-dev libcrack2-dev librdkafka-dev python3-docutils libpoppler-glib-dev
elif [[ ${OS_VERSION} == "22" ]]; then
log_info "install deb22 utils"
sudo apt install -y unzip wget sshpass acl
sudo apt install -y postgresql-all postgresql-server-dev-all build-essential debhelper devscripts fakeroot pkg-config ninja-build flex bison make cmake git ncdu wget libstdc++-12-dev firebird-dev libtinfo5
sudo apt install -y lz4 unzip bzip2 pv jq git ncdu make patch bash lsof wget uuid tuned nvme-cli numactl sysstat iotop htop rsync tcpdump python3 python3-pip socat lrzsz net-tools ipvsadm telnet ca-certificates openssl chrony zlib1g acl dnsutils libreadline-dev libxxhash-dev systemtap-sdt-dev
sudo apt install -y libreadline-dev zlib1g-dev libicu-dev libssl-dev libpq-dev libxml2-dev libxslt1-dev libldap2-dev libperl-dev libsodium23 libsodium-dev libgd-dev libgc-dev libpam0g-dev libsqlite3-dev libhiredis-dev libgsl-dev python3-dev tcl-dev libkrb5-dev libsasl2-dev uuid-dev libossp-uuid-dev gettext libcurl4-openssl-dev libopenblas-dev liblz4-dev libzstd-dev libpulse-dev liburiparser-dev libcrack2-dev librdkafka-dev python3-docutils libpoppler-glib-dev
elif [[ ${OS_VERSION} == "24" ]]; then
log_info "install deb24 utils"
sudo apt install -y unzip wget sshpass acl
sudo apt install -y postgresql-all postgresql-server-dev-all build-essential debhelper devscripts fakeroot pkg-config ninja-build flex bison make cmake git ncdu wget libstdc++-12-dev firebird-dev #libtinfo5
sudo apt install -y lz4 unzip bzip2 pv jq git ncdu make patch bash lsof wget uuid tuned nvme-cli numactl sysstat iotop htop rsync tcpdump python3 python3-pip socat lrzsz net-tools ipvsadm telnet ca-certificates openssl chrony zlib1g acl dnsutils libreadline-dev libxxhash-dev systemtap-sdt-dev vim-tiny
sudo apt install -y libreadline-dev zlib1g-dev libicu-dev libssl-dev libpq-dev libxml2-dev libxslt1-dev libldap2-dev libperl-dev libsodium23 libsodium-dev libgd-dev libgc-dev libpam0g-dev libsqlite3-dev libhiredis-dev libgsl-dev python3-dev tcl-dev libkrb5-dev libsasl2-dev uuid-dev libossp-uuid-dev gettext libcurl4-openssl-dev libopenblas-dev liblz4-dev libzstd-dev libpulse-dev liburiparser-dev libcrack2-dev librdkafka-dev python3-docutils libpoppler-glib-dev
fi
fi
}
function setup_rust() {
echo "setup rust"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
}
function setup_pgrx() {
cargo install --locked cargo-pgrx@0.12.9 # build latest extensions
cargo pgrx init
}
function stop_default_pg_service(){
if [[ ${OS_PACKAGE} == "deb" ]]; then
systemctl stop postgresql@17-main.service;
systemctl disable postgresql@17-main.service;
systemctl stop postgresql@16-main.service;
systemctl disable postgresql@16-main.service;
systemctl stop postgresql@15-main.service;
systemctl disable postgresql@15-main.service;
systemctl stop postgresql@14-main.service;
systemctl disable postgresql@14-main.service;
systemctl stop postgresql@13-main.service;
systemctl disable postgresql@13-main.service;
systemctl stop postgresql@12-main.service;
systemctl disable postgresql@12-main.service;
systemctl stop postgresql@11-main.service;
systemctl disable postgresql@11-main.service;
systemctl stop postgresql@10-main.service;
systemctl disable postgresql@10-main.service;
fi
}
#--------------------------------------------------------------#
# Main
#--------------------------------------------------------------#
function main(){
# arg parsing
while [ $# -gt 0 ]; do
case $1 in
-h|--help)
echo './setup-ext'
exit 0;;
-r|--region) REGION="$2" ; shift ;;
-k|--keep) REMOVE_REPO=no ;;
(--) shift; break;;
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
(*) break;;
esac
shift
done
check_region # region = default
check_kernel # kernel = Linux
check_machine # machine = x86_64 or aarch64
check_package_manager # package = rpm|deb, manager = dnf|yum|zypper|apt|apt-get
check_vendor_version # release = rocky, version = 7,8,9...
check_repo_file # create local file repo file if repo exists
check_utils # check ansible sshpass and other utils installed
stop_default_pg_service
}
main $@