-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrevolt-multi-os-install.sh
More file actions
executable file
·1399 lines (1225 loc) · 38.5 KB
/
revolt-multi-os-install.sh
File metadata and controls
executable file
·1399 lines (1225 loc) · 38.5 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
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -Eeuo pipefail
# Revolt interactive installer (multi-OS)
# - Debian/Ubuntu + Fedora/RHEL-family
# - Docker-based deployment with all required services
# - Optional components: Nginx + TLS, firewall rules, fail2ban
# - Services: MongoDB, RabbitMQ, Redis, MinIO, Revolt (API, Delta, Events, etc.)
SCRIPT_VERSION="1.0.0"
# Docker image versions - pinned for stability
MONGO_VERSION="${REVOLT_MONGO_VERSION:-7.0}"
REDIS_VERSION="${REVOLT_REDIS_VERSION:-7-alpine}"
RABBITMQ_VERSION="${REVOLT_RABBITMQ_VERSION:-4}"
MINIO_VERSION="${REVOLT_MINIO_VERSION:-RELEASE.2024-01-01T00-00-00Z}"
MINIO_MC_VERSION="${REVOLT_MINIO_MC_VERSION:-RELEASE.2024-01-01T00-00-00Z}"
REVOLT_API_VERSION="${REVOLT_API_VERSION:-0.7.2}"
REVOLT_BONFIRE_VERSION="${REVOLT_BONFIRE_VERSION:-0.7.2}"
REVOLT_PUSHD_VERSION="${REVOLT_PUSHD_VERSION:-0.7.2}"
REVOLT_WEB_VERSION="${REVOLT_WEB_VERSION:-1.0.0}"
REVOLT_USER="revolt"
REVOLT_GROUP="revolt"
REVOLT_ROOT="/opt/revolt"
REVOLT_DATA="${REVOLT_ROOT}/data"
REVOLT_CONFIG="${REVOLT_ROOT}/.env"
SUMMARY_FILE="/root/revolt-install-summary.txt"
OS_FAMILY=""
PKG_MANAGER=""
PRETTY_NAME=""
REVOLT_DOMAIN=""
REVOLT_API_URL=""
REVOLT_APP_URL=""
REVOLT_EXTERNAL_WS_URL=""
REVOLT_EXTERNAL_API_URL=""
RABBITMQ_USERNAME=""
RABBITMQ_PASSWORD=""
RABBITMQ_URI=""
MONGODB_URI=""
MONGODB_USERNAME=""
MONGODB_PASSWORD=""
REDIS_URI=""
MINIO_ROOT_USER=""
MINIO_ROOT_PASSWORD=""
VAPID_PRIVATE_KEY=""
VAPID_PUBLIC_KEY=""
INSTALL_NGINX="false"
USE_LETSENCRYPT="false"
LETSENCRYPT_EMAIL=""
CONFIGURE_FIREWALL="false"
INSTALL_FAIL2BAN="false"
SSH_ALLOWED_CIDR="any"
TLS_CERT_FILE=""
TLS_KEY_FILE=""
# Optional automation overrides
FORCE_INSTALL_NGINX="${REVOLT_FORCE_INSTALL_NGINX:-}"
FORCE_USE_LETSENCRYPT="${REVOLT_FORCE_USE_LETSENCRYPT:-}"
FORCE_CONFIGURE_FIREWALL="${REVOLT_FORCE_CONFIGURE_FIREWALL:-}"
FORCE_SSH_ALLOWED_CIDR="${REVOLT_FORCE_SSH_ALLOWED_CIDR:-}"
# Preferred defaults
PREFERRED_REVOLT_DOMAIN="${REVOLT_DEFAULT_DOMAIN:-revolt.local}"
if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then
echo "[ERROR] Please run this script as root." >&2
exit 1
fi
if ! command -v systemctl >/dev/null 2>&1; then
echo "[ERROR] systemd is required by this installer." >&2
exit 1
fi
log() { printf '\033[1;32m[INFO]\033[0m %s\n' "$*"; }
warn() { printf '\033[1;33m[WARN]\033[0m %s\n' "$*"; }
err() { printf '\033[1;31m[ERROR]\033[0m %s\n' "$*" >&2; }
die() { err "$*"; exit 1; }
command_exists() { command -v "$1" >/dev/null 2>&1; }
check_prerequisites() {
log "Checking system prerequisites..."
# Check Docker version
if command_exists docker; then
local docker_version
docker_version="$(docker --version 2>/dev/null | grep -oP '\d+\.\d+' | head -1)"
local docker_major
docker_major="${docker_version%%.*}"
if [[ -n "$docker_major" && "$docker_major" -lt 20 ]]; then
warn "Docker version ${docker_version} detected. Version 20.10+ is recommended."
fi
fi
# Check available disk space (require at least 10GB free)
local disk_free_gb
disk_free_gb="$(df -BG / | awk 'NR==2 {print $4}' | sed 's/G//')"
if [[ "$disk_free_gb" -lt 10 ]]; then
warn "Low disk space: ${disk_free_gb}GB free. At least 10GB recommended."
if ! ask_yes_no "Continue anyway?" "n"; then
die "Installation cancelled due to insufficient disk space."
fi
fi
# Check available RAM (require at least 2GB)
local ram_mb
ram_mb="$(free -m | awk 'NR==2 {print $2}')"
if [[ "$ram_mb" -lt 2048 ]]; then
warn "Low RAM: ${ram_mb}MB available. At least 2GB recommended."
if ! ask_yes_no "Continue anyway?" "n"; then
die "Installation cancelled due to insufficient RAM."
fi
fi
# Check CPU cores (recommend at least 2)
local cpu_cores
cpu_cores="$(nproc 2>/dev/null || echo 1)"
if [[ "$cpu_cores" -lt 2 ]]; then
warn "Only ${cpu_cores} CPU core(s) detected. 2+ cores recommended for better performance."
fi
log "Prerequisites check passed."
}
cleanup_on_failure() {
err "Installation failed. Cleaning up..."
# Stop and remove containers if they exist
if [[ -f "${REVOLT_ROOT}/docker-compose.yml" ]]; then
cd "$REVOLT_ROOT" 2>/dev/null && docker compose down -v 2>/dev/null || true
fi
# Note: We don't remove the revolt user or directories as they may contain important data
warn "Partial installation cleanup completed. Check logs for errors."
warn "To fully remove, run: docker compose down -v && rm -rf ${REVOLT_ROOT}"
}
gen_alnum() {
local len="${1:-32}"
local out=""
local iterations=0
local max_iterations=100
while [[ "${#out}" -lt "$len" ]]; do
if [[ "$iterations" -ge "$max_iterations" ]]; then
die "Failed to generate random string after ${max_iterations} attempts"
fi
if command_exists openssl; then
out+=$(openssl rand -base64 64 | tr -dc 'A-Za-z0-9' | awk -v L="$len" '{print substr($0,1,L)}')
else
out+=$(tr -dc 'A-Za-z0-9' </dev/urandom | head -c "$len")
fi
iterations=$((iterations + 1))
done
printf '%s' "${out:0:len}"
}
gen_hex() {
local len="${1:-32}"
if command_exists openssl; then
openssl rand -hex "$len" | head -c "$((len*2))"
else
tr -dc 'a-f0-9' </dev/urandom | head -c "$((len*2))"
fi
}
gen_base64url() {
local bytes="${1:-32}"
if command_exists openssl; then
openssl rand -base64 "$bytes" | tr '+/' '-_' | tr -d '='
else
head -c "$bytes" </dev/urandom | base64 | tr '+/' '-_' | tr -d '='
fi
}
pick_nologin_shell() {
if [[ -x /usr/sbin/nologin ]]; then
printf '/usr/sbin/nologin'
elif [[ -x /sbin/nologin ]]; then
printf '/sbin/nologin'
else
printf '/bin/false'
fi
}
ask_yes_no() {
local prompt="$1"
local default="${2:-y}"
local suffix="[Y/n]"
local answer=""
if [[ "${default,,}" == "n" ]]; then
suffix="[y/N]"
fi
while true; do
read -r -p "${prompt} ${suffix}: " answer || true
answer="${answer:-$default}"
case "${answer,,}" in
y|yes) return 0 ;;
n|no) return 1 ;;
*) warn "Please answer yes or no." ;;
esac
done
}
ask_text() {
local prompt="$1"
local default="${2:-}"
local value=""
if [[ -n "$default" ]]; then
read -r -p "${prompt} [${default}]: " value || true
value="${value:-$default}"
else
read -r -p "${prompt}: " value || true
fi
printf '%s' "$value"
}
ask_required_text() {
local prompt="$1"
local default="${2:-}"
local value=""
while true; do
value="$(ask_text "$prompt" "$default")"
if [[ -n "$value" ]]; then
printf '%s' "$value"
return 0
fi
warn "Value cannot be empty."
done
}
detect_os() {
if [[ ! -r /etc/os-release ]]; then
die "Cannot detect OS: /etc/os-release is missing."
fi
# shellcheck disable=SC1091
source /etc/os-release
PRETTY_NAME="${PRETTY_NAME:-$ID}"
case "${ID,,}" in
debian|ubuntu)
OS_FAMILY="debian"
PKG_MANAGER="apt-get"
export DEBIAN_FRONTEND=noninteractive
;;
fedora)
OS_FAMILY="fedora"
PKG_MANAGER="dnf"
;;
rhel|centos|rocky|almalinux|ol|oraclelinux)
OS_FAMILY="rhel"
if command_exists dnf; then
PKG_MANAGER="dnf"
elif command_exists yum; then
PKG_MANAGER="yum"
else
die "Neither dnf nor yum found."
fi
;;
*)
if [[ "${ID_LIKE:-}" =~ (debian|ubuntu) ]]; then
OS_FAMILY="debian"
PKG_MANAGER="apt-get"
export DEBIAN_FRONTEND=noninteractive
elif [[ "${ID_LIKE:-}" =~ (rhel|fedora|centos) ]]; then
OS_FAMILY="rhel"
if command_exists dnf; then
PKG_MANAGER="dnf"
elif command_exists yum; then
PKG_MANAGER="yum"
else
die "Neither dnf nor yum found."
fi
else
die "Unsupported OS: ${ID}"
fi
;;
esac
}
pkg_update() {
case "$OS_FAMILY" in
debian)
apt-get update -y
;;
fedora|rhel)
if [[ "$PKG_MANAGER" == "dnf" ]]; then
dnf makecache -y
else
yum makecache -y
fi
;;
*)
die "Unknown OS family: $OS_FAMILY"
;;
esac
}
pkg_install() {
case "$OS_FAMILY" in
debian)
apt-get install -y "$@"
;;
fedora|rhel)
if [[ "$PKG_MANAGER" == "dnf" ]]; then
dnf install -y "$@"
else
yum install -y "$@"
fi
;;
*)
die "Unknown OS family: $OS_FAMILY"
;;
esac
}
configure_prompts() {
local default_host
default_host="$(hostname -f 2>/dev/null || hostname)"
if [[ -z "$default_host" ]]; then
default_host="revolt.local"
fi
printf "\nRevolt interactive installer v%s\n" "$SCRIPT_VERSION"
printf "Detected OS: %s\n\n" "$PRETTY_NAME"
REVOLT_DOMAIN="$(ask_required_text "Revolt domain (e.g., revolt.example.com)" "${PREFERRED_REVOLT_DOMAIN:-$default_host}")"
RABBITMQ_USERNAME="$(ask_required_text "RabbitMQ username" "rabbituser")"
local rabbit_pass_prompt
rabbit_pass_prompt="$(ask_text "RabbitMQ password (leave empty to auto-generate)" "")"
RABBITMQ_PASSWORD="${rabbit_pass_prompt:-$(gen_alnum 32)}"
RABBITMQ_URI="amqp://${RABBITMQ_USERNAME}:${RABBITMQ_PASSWORD}@rabbit:5672/"
MINIO_ROOT_USER="$(ask_required_text "MinIO root user" "minio")"
local minio_pass_prompt
minio_pass_prompt="$(ask_text "MinIO root password (leave empty to auto-generate)" "")"
MINIO_ROOT_PASSWORD="${minio_pass_prompt:-$(gen_alnum 32)}"
# MongoDB authentication
MONGODB_USERNAME="$(ask_required_text "MongoDB username" "revoltuser")"
local mongodb_pass_prompt
mongodb_pass_prompt="$(ask_text "MongoDB password (leave empty to auto-generate)" "")"
MONGODB_PASSWORD="${mongodb_pass_prompt:-$(gen_alnum 32)}"
MONGODB_URI="mongodb://${MONGODB_USERNAME}:${MONGODB_PASSWORD}@database:27017/revolt?authSource=admin"
REDIS_URI="redis://redis:6379/"
if [[ -n "$FORCE_INSTALL_NGINX" ]]; then
case "${FORCE_INSTALL_NGINX,,}" in
1|true|yes|y)
INSTALL_NGINX="true"
log "Nginx install forced by REVOLT_FORCE_INSTALL_NGINX=${FORCE_INSTALL_NGINX}"
;;
0|false|no|n)
INSTALL_NGINX="false"
USE_LETSENCRYPT="false"
log "Nginx install forced OFF by REVOLT_FORCE_INSTALL_NGINX=${FORCE_INSTALL_NGINX}"
;;
*)
die "Invalid REVOLT_FORCE_INSTALL_NGINX value: ${FORCE_INSTALL_NGINX} (use true/false)"
;;
esac
elif ask_yes_no "Install and configure Nginx reverse proxy + TLS?" "y"; then
INSTALL_NGINX="true"
fi
if [[ "$INSTALL_NGINX" == "true" ]]; then
if [[ -n "$FORCE_USE_LETSENCRYPT" ]]; then
case "${FORCE_USE_LETSENCRYPT,,}" in
1|true|yes|y)
USE_LETSENCRYPT="true"
log "Let's Encrypt forced ON by REVOLT_FORCE_USE_LETSENCRYPT=${FORCE_USE_LETSENCRYPT}"
;;
0|false|no|n)
USE_LETSENCRYPT="false"
log "Let's Encrypt forced OFF by REVOLT_FORCE_USE_LETSENCRYPT=${FORCE_USE_LETSENCRYPT}"
;;
*)
die "Invalid REVOLT_FORCE_USE_LETSENCRYPT value: ${FORCE_USE_LETSENCRYPT} (use true/false)"
;;
esac
elif ask_yes_no "Use Let's Encrypt certificate (requires working public DNS + port 80)?" "n"; then
USE_LETSENCRYPT="true"
fi
if [[ "$USE_LETSENCRYPT" == "true" ]]; then
LETSENCRYPT_EMAIL="$(ask_required_text "Let's Encrypt email" "admin@${REVOLT_DOMAIN}")"
fi
fi
if [[ -n "$FORCE_CONFIGURE_FIREWALL" ]]; then
case "${FORCE_CONFIGURE_FIREWALL,,}" in
1|true|yes|y)
CONFIGURE_FIREWALL="true"
if [[ -n "$FORCE_SSH_ALLOWED_CIDR" ]]; then
SSH_ALLOWED_CIDR="$FORCE_SSH_ALLOWED_CIDR"
else
SSH_ALLOWED_CIDR="any"
fi
log "Firewall config forced ON by REVOLT_FORCE_CONFIGURE_FIREWALL=${FORCE_CONFIGURE_FIREWALL}"
;;
0|false|no|n)
CONFIGURE_FIREWALL="false"
log "Firewall config forced OFF by REVOLT_FORCE_CONFIGURE_FIREWALL=${FORCE_CONFIGURE_FIREWALL}"
;;
*)
die "Invalid REVOLT_FORCE_CONFIGURE_FIREWALL value: ${FORCE_CONFIGURE_FIREWALL} (use true/false)"
;;
esac
elif ask_yes_no "Configure firewall automatically?" "y"; then
CONFIGURE_FIREWALL="true"
SSH_ALLOWED_CIDR="$(ask_text "Allow SSH from CIDR (or 'any')" "any")"
fi
if ask_yes_no "Install fail2ban hardening?" "y"; then
INSTALL_FAIL2BAN="true"
fi
# Set URLs based on Nginx configuration
if [[ "$INSTALL_NGINX" == "true" ]]; then
REVOLT_API_URL="https://${REVOLT_DOMAIN}/api"
REVOLT_APP_URL="https://${REVOLT_DOMAIN}"
REVOLT_EXTERNAL_WS_URL="wss://${REVOLT_DOMAIN}/ws"
REVOLT_EXTERNAL_API_URL="https://${REVOLT_DOMAIN}/api"
else
REVOLT_API_URL="http://${REVOLT_DOMAIN}:8000"
REVOLT_APP_URL="http://${REVOLT_DOMAIN}:3000"
REVOLT_EXTERNAL_WS_URL="ws://${REVOLT_DOMAIN}:9000"
REVOLT_EXTERNAL_API_URL="http://${REVOLT_DOMAIN}:8000"
fi
# Generate VAPID keys (required for push notifications)
# VAPID keys must be base64url encoded (RFC 4648) without padding
log "Generating VAPID keys for push notifications..."
VAPID_PRIVATE_KEY="$(gen_base64url 32)"
VAPID_PUBLIC_KEY="$(gen_base64url 65)"
}
install_system_packages() {
log "Installing base dependencies..."
pkg_update
if [[ "$OS_FAMILY" == "debian" ]]; then
pkg_install \
ca-certificates curl gnupg2 jq openssl sudo lsb-release git
else
pkg_install \
ca-certificates curl gnupg2 jq openssl sudo git
fi
if [[ "$INSTALL_NGINX" == "true" ]]; then
pkg_install nginx
if [[ "$USE_LETSENCRYPT" == "true" ]]; then
pkg_install certbot
fi
fi
if [[ "$CONFIGURE_FIREWALL" == "true" ]]; then
if [[ "$OS_FAMILY" == "debian" ]]; then
pkg_install ufw
else
pkg_install firewalld
fi
fi
if [[ "$INSTALL_FAIL2BAN" == "true" ]]; then
if [[ "$OS_FAMILY" == "debian" ]]; then
pkg_install fail2ban
else
# RHEL/Fedora family - fail2ban requires EPEL
log "Installing EPEL repository for fail2ban..."
if [[ "$OS_FAMILY" == "fedora" ]]; then
pkg_install fail2ban || warn "fail2ban installation failed - skipping"
else
# RHEL-based systems need EPEL
if ! pkg_install epel-release 2>/dev/null; then
warn "EPEL repository not available, trying to install from URL..."
if [[ "$PKG_MANAGER" == "dnf" ]]; then
dnf install -y "https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %rhel).noarch.rpm" 2>/dev/null || warn "Could not install EPEL"
else
yum install -y "https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %rhel).noarch.rpm" 2>/dev/null || warn "Could not install EPEL"
fi
fi
pkg_install fail2ban || {
warn "fail2ban installation failed - this is optional, continuing without it"
INSTALL_FAIL2BAN="false"
}
fi
fi
fi
}
install_docker() {
log "Installing Docker and Docker Compose..."
if command_exists docker; then
log "Docker already installed: $(docker --version)"
else
if [[ "$OS_FAMILY" == "debian" ]]; then
# Add Docker's official GPG key
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/${ID}/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
# Add the repository to Apt sources
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/${ID} \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update -y
pkg_install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
else
# RHEL/Fedora family
if [[ "$OS_FAMILY" == "fedora" ]]; then
dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
else
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
fi
pkg_install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
fi
systemctl enable --now docker
fi
# Verify Docker Compose is available
if ! docker compose version >/dev/null 2>&1; then
die "Docker Compose plugin not available. Please install it manually."
fi
log "Docker installed: $(docker --version)"
log "Docker Compose installed: $(docker compose version)"
}
create_revolt_user_and_dirs() {
local nologin_shell
nologin_shell="$(pick_nologin_shell)"
if ! id -u "$REVOLT_USER" >/dev/null 2>&1; then
useradd \
--system \
--user-group \
--home-dir "$REVOLT_ROOT" \
--create-home \
--shell "$nologin_shell" \
"$REVOLT_USER"
fi
REVOLT_GROUP="$(id -gn "$REVOLT_USER")"
# Add revolt user to docker group
usermod -aG docker "$REVOLT_USER" || true
mkdir -p "$REVOLT_ROOT" "$REVOLT_DATA"
chown -R "$REVOLT_USER:$REVOLT_GROUP" "$REVOLT_ROOT" "$REVOLT_DATA"
chmod 750 "$REVOLT_ROOT" "$REVOLT_DATA"
}
write_revolt_env() {
log "Writing Revolt environment configuration..."
cat >"$REVOLT_CONFIG" <<EOF
# Revolt Configuration
# Generated on $(date)
# Domain Configuration
REVOLT_DOMAIN=${REVOLT_DOMAIN}
REVOLT_PUBLIC_URL=${REVOLT_APP_URL}
REVOLT_API_URL=${REVOLT_API_URL}
REVOLT_APP_URL=${REVOLT_APP_URL}
REVOLT_EXTERNAL_WS_URL=${REVOLT_EXTERNAL_WS_URL}
# RabbitMQ Configuration
RABBITMQ_USERNAME=${RABBITMQ_USERNAME}
RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD}
RABBITMQ_URI=${RABBITMQ_URI}
# Database Configuration
MONGODB_URI=${MONGODB_URI}
MONGODB_USERNAME=${MONGODB_USERNAME}
MONGODB_PASSWORD=${MONGODB_PASSWORD}
REDIS_URI=${REDIS_URI}
# MinIO Configuration (File Storage)
MINIO_ROOT_USER=${MINIO_ROOT_USER}
MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD}
MINIO_ENDPOINT=http://minio:9000
S3_REGION=revolt
S3_BUCKET=revolt-files
# VAPID Keys (Push Notifications)
VAPID_PRIVATE_KEY=${VAPID_PRIVATE_KEY}
VAPID_PUBLIC_KEY=${VAPID_PUBLIC_KEY}
# Optional: App Configuration
# REVOLT_APP_NAME=Revolt
# REVOLT_SMTP_HOST=smtp.example.com
# REVOLT_SMTP_PORT=587
# REVOLT_SMTP_USERNAME=
# REVOLT_SMTP_PASSWORD=
# REVOLT_SMTP_FROM=noreply@${REVOLT_DOMAIN}
# Security
# Set to 'true' for production
REVOLT_UNSAFE_NO_EMAIL=true
# Logging
RUST_LOG=info
EOF
chown "$REVOLT_USER:$REVOLT_GROUP" "$REVOLT_CONFIG"
chmod 640 "$REVOLT_CONFIG"
}
write_docker_compose() {
log "Writing Docker Compose configuration..."
# Determine port exposure based on Nginx installation
local expose_ports="true"
if [[ "$INSTALL_NGINX" == "true" ]]; then
expose_ports="false"
log "Nginx enabled: Docker services will not expose ports to host"
else
log "Nginx disabled: Docker services will expose ports to host"
fi
cat >"${REVOLT_ROOT}/docker-compose.yml" <<EOF
version: '3.8'
# Revolt Multi-OS Installer
# Docker Compose Configuration
#
# IMPORTANT: Backup these volumes regularly:
# - mongodb_data: User data, messages, channels
# - minio_data: File uploads and attachments
# - redis_data: Session cache
# - rabbitmq_data: Message queue state
services:
# MongoDB Database
database:
image: mongo:${MONGO_VERSION}
container_name: revolt-database
restart: unless-stopped
environment:
MONGO_INITDB_ROOT_USERNAME: \${MONGODB_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: \${MONGODB_PASSWORD}
MONGO_INITDB_DATABASE: revolt
volumes:
- mongodb_data:/data/db
networks:
- revolt-network
healthcheck:
test: |
if command -v mongosh >/dev/null 2>&1; then
mongosh --quiet "mongodb://\$MONGO_INITDB_ROOT_USERNAME:\$MONGO_INITDB_ROOT_PASSWORD@localhost:27017/admin" --eval "db.adminCommand('ping')" || exit 1
else
echo 'db.adminCommand("ping")' | mongo "mongodb://\$MONGO_INITDB_ROOT_USERNAME:\$MONGO_INITDB_ROOT_PASSWORD@localhost:27017/admin" --quiet || exit 1
fi
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# Redis Cache
redis:
image: redis:${REDIS_VERSION}
container_name: revolt-redis
restart: unless-stopped
volumes:
- redis_data:/data
networks:
- revolt-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# RabbitMQ Message Queue
rabbit:
image: rabbitmq:${RABBITMQ_VERSION}
container_name: revolt-rabbit
restart: unless-stopped
environment:
RABBITMQ_DEFAULT_USER: \${RABBITMQ_USERNAME}
RABBITMQ_DEFAULT_PASS: \${RABBITMQ_PASSWORD}
volumes:
- rabbitmq_data:/var/lib/rabbitmq
networks:
- revolt-network
healthcheck:
test: ["CMD", "rabbitmq-diagnostics", "-q", "ping"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# MinIO S3-compatible Storage
minio:
image: minio/minio:${MINIO_VERSION}
container_name: revolt-minio
restart: unless-stopped
command: server /data --console-address ":9001"
environment:
MINIO_ROOT_USER: \${MINIO_ROOT_USER}
MINIO_ROOT_PASSWORD: \${MINIO_ROOT_PASSWORD}
volumes:
- minio_data:/data
networks:
- revolt-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# MinIO bucket initialization with retry logic
createbuckets:
image: minio/mc:${MINIO_MC_VERSION}
container_name: revolt-minio-setup
depends_on:
minio:
condition: service_healthy
environment:
MINIO_ROOT_USER: \${MINIO_ROOT_USER}
MINIO_ROOT_PASSWORD: \${MINIO_ROOT_PASSWORD}
networks:
- revolt-network
entrypoint: >
/bin/sh -c "
set -e;
echo 'Waiting for MinIO to be fully ready...';
sleep 5;
max_attempts=30;
attempt=0;
while [ \$\$attempt -lt \$\$max_attempts ]; do
if /usr/bin/mc alias set myminio http://minio:9000 \$\$MINIO_ROOT_USER \$\$MINIO_ROOT_PASSWORD 2>/dev/null; then
echo 'MinIO connection established';
break;
fi;
attempt=\$\$((attempt + 1));
echo \"Attempt \$\$attempt/\$\$max_attempts failed, retrying in 2 seconds...\";
sleep 2;
done;
if [ \$\$attempt -eq \$\$max_attempts ]; then
echo 'Failed to connect to MinIO after \$\$max_attempts attempts';
exit 1;
fi;
/usr/bin/mc mb --ignore-existing myminio/revolt-files;
/usr/bin/mc anonymous set download myminio/revolt-files;
echo 'Bucket setup completed successfully';
exit 0;
"
# Revolt API (Delta)
api:
image: ghcr.io/revoltchat/server:${REVOLT_API_VERSION}
container_name: revolt-api
restart: unless-stopped
env_file:
- .env
environment:
RABBITMQ_URI: \${RABBITMQ_URI}
MONGODB_URI: \${MONGODB_URI}
REDIS_URI: \${REDIS_URI}
S3_REGION: \${S3_REGION}
S3_BUCKET: \${S3_BUCKET}
MINIO_ENDPOINT: \${MINIO_ENDPOINT}
MINIO_ROOT_USER: \${MINIO_ROOT_USER}
MINIO_ROOT_PASSWORD: \${MINIO_ROOT_PASSWORD}
depends_on:
rabbit:
condition: service_healthy
database:
condition: service_healthy
redis:
condition: service_healthy
minio:
condition: service_healthy
EOF
if [[ "$expose_ports" == "true" ]]; then
cat >>"${REVOLT_ROOT}/docker-compose.yml" <<EOF
ports:
- "8000:8000"
EOF
fi
cat >>"${REVOLT_ROOT}/docker-compose.yml" <<EOF
networks:
- revolt-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# Revolt Events WebSocket
events:
image: ghcr.io/revoltchat/bonfire:${REVOLT_BONFIRE_VERSION}
container_name: revolt-events
restart: unless-stopped
env_file:
- .env
environment:
RABBITMQ_URI: \${RABBITMQ_URI}
depends_on:
rabbit:
condition: service_healthy
EOF
if [[ "$expose_ports" == "true" ]]; then
cat >>"${REVOLT_ROOT}/docker-compose.yml" <<EOF
ports:
- "9000:9000"
EOF
fi
cat >>"${REVOLT_ROOT}/docker-compose.yml" <<EOF
networks:
- revolt-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# Revolt Push Notifications Daemon
pushd:
image: ghcr.io/revoltchat/pushd:${REVOLT_PUSHD_VERSION}
container_name: revolt-pushd
restart: unless-stopped
env_file:
- .env
environment:
RABBITMQ_URI: \${RABBITMQ_URI}
VAPID_PRIVATE_KEY: \${VAPID_PRIVATE_KEY}
VAPID_PUBLIC_KEY: \${VAPID_PUBLIC_KEY}
depends_on:
rabbit:
condition: service_healthy
networks:
- revolt-network
# Note: pushd service doesn't expose a health endpoint, so we check if the process is running
# This is a best-effort check and may need adjustment based on the actual process name
healthcheck:
test: ["CMD-SHELL", "test -e /proc/1/exe || exit 1"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
# Revolt Web Client
web:
image: ghcr.io/revoltchat/client:${REVOLT_WEB_VERSION}
container_name: revolt-web
restart: unless-stopped
environment:
REVOLT_API_URL: \${REVOLT_EXTERNAL_API_URL}
REVOLT_WS_URL: \${REVOLT_EXTERNAL_WS_URL}
EOF
if [[ "$expose_ports" == "true" ]]; then
cat >>"${REVOLT_ROOT}/docker-compose.yml" <<EOF
ports:
- "3000:3000"
EOF
fi
cat >>"${REVOLT_ROOT}/docker-compose.yml" <<EOF
networks:
- revolt-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
networks:
revolt-network:
driver: bridge
volumes:
mongodb_data:
driver: local
redis_data:
driver: local
rabbitmq_data:
driver: local
minio_data:
driver: local
EOF
chown "$REVOLT_USER:$REVOLT_GROUP" "${REVOLT_ROOT}/docker-compose.yml"
chmod 644 "${REVOLT_ROOT}/docker-compose.yml"
}
start_revolt_services() {
log "Starting Revolt services..."
cd "$REVOLT_ROOT"
# Pull images first
runuser -u "$REVOLT_USER" -- docker compose pull
# Start services
runuser -u "$REVOLT_USER" -- docker compose up -d
log "Waiting for services to start..."
sleep 10
# Check service status
runuser -u "$REVOLT_USER" -- docker compose ps
}
create_self_signed_cert() {
local cert_dir="$1"
local cert_name="$2"
mkdir -p "$cert_dir"
TLS_CERT_FILE="${cert_dir}/${cert_name}.crt"
TLS_KEY_FILE="${cert_dir}/${cert_name}.key"
if [[ ! -f "$TLS_CERT_FILE" || ! -f "$TLS_KEY_FILE" ]]; then
log "Generating self-signed TLS certificate for ${REVOLT_DOMAIN}..."
if ! openssl req -x509 -nodes -newkey rsa:2048 -days 825 \
-keyout "$TLS_KEY_FILE" \
-out "$TLS_CERT_FILE" \
-subj "/CN=${REVOLT_DOMAIN}" \
-addext "subjectAltName=DNS:${REVOLT_DOMAIN}" >/dev/null 2>&1; then
openssl req -x509 -nodes -newkey rsa:2048 -days 825 \
-keyout "$TLS_KEY_FILE" \
-out "$TLS_CERT_FILE" \
-subj "/CN=${REVOLT_DOMAIN}" >/dev/null 2>&1
fi
chmod 640 "$TLS_KEY_FILE"
chmod 644 "$TLS_CERT_FILE"
fi
}
configure_nginx() {
log "Configuring Nginx reverse proxy..."
mkdir -p /etc/nginx/conf.d /var/www/certbot
rm -f /etc/nginx/conf.d/default.conf /etc/nginx/sites-enabled/default /etc/nginx/sites-available/default