forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupgrade.sh
More file actions
825 lines (745 loc) · 33.2 KB
/
upgrade.sh
File metadata and controls
825 lines (745 loc) · 33.2 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
#!/bin/bash
# Hestia Control Panel - Upgrade Control Script
#####################################################################
####### Functions & Initialization #######
#####################################################################
is_debug_build() {
if [[ "$new_version" =~ "alpha" ]] || [[ "$new_version" =~ "beta" ]]; then
DEBUG_MODE="true"
fi
# Remove pre-release designation tags from display version
DISPLAY_VER=$(echo $new_version | sed "s|~alpha||g" | sed "s|~beta||g")
}
upgrade_health_check() {
echo "============================================================================="
echo "[ ! ] Performing system health check before proceeding with installation... "
# Perform basic health check against hestia.conf to ensure that
# system variables exist and are set to expected defaults.
if [ -z "$VERSION" ]; then
export VERSION="1.1.0"
$BIN/v-change-sys-config-value 'VERSION' "$VERSION"
echo
echo "[ ! ] Unable to detect installed version of Hestia Control Panel."
echo " Setting default version to $VERSION and processing upgrade steps."
echo
fi
# Release branch
if [ -z "$RELEASE_BRANCH" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: RELEASE_BRANCH ('release')"
$BIN/v-change-sys-config-value 'RELEASE_BRANCH' 'release'
fi
# Webmail alias
if [ ! -z "$IMAP_SYSTEM" ]; then
if [ -z "$WEBMAIL_ALIAS" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: WEBMAIL_ALIAS ('webmail')"
$BIN/v-change-sys-config-value 'WEBMAIL_ALIAS' 'webmail'
fi
fi
# phpMyAdmin/phpPgAdmin alias
if [ ! -z "$DB_SYSTEM" ]; then
if [ "$DB_SYSTEM" = "mysql" ]; then
if [ -z "$DB_PMA_ALIAS" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: DB_PMA_ALIAS ('phpMyAdmin')"
$BIN/v-change-sys-config-value 'DB_PMA_ALIAS' 'phpMyAdmin'
fi
fi
if [ "$DB_SYSTEM" = "pgsql" ]; then
if [ -z "$DB_PGA_ALIAS" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: DB_PGA_ALIAS ('phpPgAdmin')"
$BIN/v-change-sys-config-value 'DB_PGA_ALIAS' 'phpPgAdmin'
fi
fi
fi
# Backup compression level
if [ -z "$BACKUP_GZIP" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: BACKUP_GZIP ('9')"
$BIN/v-change-sys-config-value 'BACKUP_GZIP' '9'
fi
# Theme
if [ -z "$THEME" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: THEME ('default')"
$BIN/v-change-sys-config-value 'THEME' 'default'
fi
# Default language
if [ -z "$LANGUAGE" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: LANGUAGE ('en')"
$BIN/v-change-sys-language 'en'
fi
# Disk Quota
if [ -z "$DISK_QUOTA" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: DISK_QUOTA ('no')"
$BIN/v-change-sys-config-value 'DISK_QUOTA' 'no'
fi
# CRON daemon
if [ -z "$CRON_SYSTEM" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: CRON_SYSTEM ('cron')"
$BIN/v-change-sys-config-value 'CRON_SYSTEM' 'cron'
fi
# Backend port
if [ -z "$BACKEND_PORT" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: BACKEND_PORT ('8083')"
$BIN/v-change-sys-port '8083' >/dev/null 2>&1
fi
# Upgrade: Send email notification
if [ -z "$UPGRADE_SEND_EMAIL" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: UPGRADE_SEND_EMAIL ('true')"
$BIN/v-change-sys-config-value 'UPGRADE_SEND_EMAIL' 'true'
fi
# Upgrade: Send email notification
if [ -z "$UPGRADE_SEND_EMAIL_LOG" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: UPGRADE_SEND_EMAIL_LOG ('false')"
$BIN/v-change-sys-config-value 'UPGRADE_SEND_EMAIL_LOG' 'false'
fi
# File Manager
if [ -z "$FILE_MANAGER" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: FILE_MANAGER ('true')"
echo "[ ! ] File Manager is enabled but not installed, repairing components..."
$BIN/v-add-sys-filemanager quiet
fi
# Support for ZSTD / GZIP Change
if [ -z "$BACKUP_MODE" ]; then
echo "[ ! ] Setting zstd backup compression type as default..."
$BIN/v-change-sys-config-value "BACKUP_MODE" "zstd"
fi
# Login style switcher
if [ -z "$LOGIN_STYLE" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: LOGIN_STYLE ('default')"
$BIN/v-change-sys-config-value "LOGIN_STYLE" "default"
fi
# Webmail clients
if [ -z "$WEBMAIL_SYSTEM" ]; then
if [ -d "/var/lib/roundcube" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: WEBMAIL_SYSTEM ('roundcube')"
$BIN/v-change-sys-config-value "WEBMAIL_SYSTEM" "roundcube"
else
echo "[ ! ] Adding missing variable to hestia.conf: WEBMAIL_SYSTEM ('')"
$BIN/v-change-sys-config-value "WEBMAIL_SYSTEM" ""
fi
fi
# Inactive session timeout
if [ -z "$INACTIVE_SESSION_TIMEOUT" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: INACTIVE_SESSION_TIMEOUT ('60')"
$BIN/v-change-sys-config-value "INACTIVE_SESSION_TIMEOUT" "60"
fi
# Enforce Subdomain ownership
if [ -z "$ENFORCE_SUBDOMAIN_OWNERSHIP" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: ENFORCE_SUBDOMAIN_OWNERSHIP ('yes')"
$BIN/v-change-sys-config-value "ENFORCE_SUBDOMAIN_OWNERSHIP" "yes"
fi
# Debug Mode
if [ -z "$DEBUG_MODE" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: DEBUG_MODE ('false')"
$BIN/v-change-sys-config-value "DEBUG_MODE" "false"
fi
# API Allowed IP
if [ -z "$API_ALLOWED_IP" ]; then
echo "[ ! ] Adding missing variable to hestia.conf: API_ALLOWED_IP ('allow-all')"
$BIN/v-change-sys-config-value "API_ALLOWED_IP" "allow-all"
fi
echo "[ * ] Health check complete. Starting upgrade from $VERSION to $new_version..."
echo "============================================================================="
}
upgrade_welcome_message() {
echo
echo ' _ _ _ _ ____ ____ '
echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) | '
echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
echo " "
echo " Hestia Control Panel Software Update "
echo " Version: ${DISPLAY_VER} "
if [[ "$new_version" =~ "beta" ]]; then
echo " BETA RELEASE "
fi
if [[ "$new_version" =~ "alpha" ]]; then
echo " DEVELOPMENT SNAPSHOT "
echo " NOT INTENDED FOR PRODUCTION USE "
echo " USE AT YOUR OWN RISK "
fi
echo
echo "=============================================================================="
echo
echo "[ ! ] IMPORTANT INFORMATION: "
echo
echo "Default configuration files and templates may be modified or replaced "
echo "during the upgrade process. You may restore these files from: "
echo ""
echo "Backup directory: $HESTIA_BACKUP/ "
echo "Installation log: $LOG "
}
upgrade_welcome_message_log() {
echo "=============================================================================="
echo "Hestia Control Panel Software Update Log"
echo "=============================================================================="
echo
echo "OPERATING SYSTEM: $OS_TYPE ($OS_VERSION)"
echo "CURRENT VERSION: $VERSION"
echo "NEW VERSION: $new_version"
echo "RELEASE BRANCH: $RELEASE_BRANCH"
if [[ "$new_version" =~ "alpha" ]]; then
echo "BUILD TYPE: Development snapshot"
elif [[ "$new_version" =~ "beta" ]]; then
echo "BUILD TYPE: Beta release"
else
echo "BUILD TYPE: Production release"
fi
echo
echo "INSTALLER OPTIONS:"
echo "============================================================================="
echo "Send email notification on upgrade complete: $UPGRADE_SEND_EMAIL"
echo "Send installed log output to admin email: $UPGRADE_SEND_EMAIL_LOG"
echo
}
upgrade_step_message() {
echo
echo "[ - ] Now applying any necessary patches from version v$version_step..."
}
upgrade_complete_message() {
# Echo message to console output
echo "============================================================================="
echo
echo "Upgrade complete! If you encounter any issues or find a bug, "
echo "please take a moment to report it to us on GitHub at the URL below: "
echo "https://github.com/hestiacp/hestiacp/issues "
echo
echo "We hope that you enjoy using this version of Hestia Control Panel, "
echo "have a wonderful day! "
echo
echo "Sincerely, "
echo "The Hestia Control Panel development team "
echo
echo "Web: https://www.hestiacp.com/ "
echo "Forum: https://forum.hestiacp.com/ "
echo "Discord: https://discord.gg/nXRUZch "
echo "GitHub: https://github.com/hestiacp/hestiacp/ "
echo
echo "Help support the Hestia Control Panel project by donating via PayPal: "
echo "https://www.hestiacp.com/donate "
echo
echo "Made with love & pride by the open-source community around the world. "
echo
echo "============================================================================="
echo
}
upgrade_complete_message_log() {
echo
echo "============================================================================="
echo "UPGRADE COMPLETE. "
echo "Please report any issues on GitHub: "
echo "https://github.com/hestiacp/hestiacp/issues "
echo "============================================================================="
echo
}
upgrade_cleanup_message() {
echo "============================================================================="
echo "Installation tasks complete, performing clean-up... "
echo "============================================================================="
}
upgrade_get_version() {
# Retrieve new version number for Hestia Control Panel from .deb package
new_version=$(dpkg -l | awk '$2=="hestia" { print $3 }')
}
upgrade_set_version() {
# Set new version number in hestia.conf
sed -i "/VERSION/d" $HESTIA/conf/hestia.conf
echo "VERSION='$@'" >> $HESTIA/conf/hestia.conf
}
upgrade_send_notification_to_panel () {
# Add notification to panel if variable is set to true or is not set
if [[ "$new_version" =~ "alpha" ]]; then
# Send notifications for development releases
$HESTIA/bin/v-add-user-notification admin 'Development snapshot installed' '<b>Version:</b> '$new_version'<br><b>Code Branch:</b> '$RELEASE_BRANCH'<br><br>Please tell us about any bugs or issues by opening an issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a> and feel free to share your feedback on our <a href="https://forum.hestiacp.com" target="_new">discussion forum</a>.<br><br><i class="fas fa-heart status-icon red"></i> The Hestia Control Panel development team'
elif [[ "$new_version" =~ "beta" ]]; then
# Send feedback notification for beta releases
$HESTIA/bin/v-add-user-notification admin 'Thank you for testing Hestia Control Panel '$new_version'.' '<b>Please share your feedback with our development team through our <a href="https://forum.hestiacp.com" target="_new">discussion forum</a>.<br><br>Found a bug? Report it on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>!</b><br><br><i class="fas fa-heart status-icon red"></i> The Hestia Control Panel development team'
else
# Send normal upgrade complete notification for stable releases
$HESTIA/bin/v-add-user-notification admin 'Upgrade complete' 'Your server has been updated to Hestia Control Panel <b>v'$new_version'</b>.<br><br>Please tell us about any bugs or issues by opening an issue report on <a href="https://github.com/hestiacp/hestiacp/issues" target="_new"><i class="fab fa-github"></i> GitHub</a>.<br><br><b>Have a wonderful day!</b><br><br><i class="fas fa-heart status-icon red"></i> The Hestia Control Panel development team'
fi
}
upgrade_send_notification_to_email () {
if [ "$UPGRADE_SEND_EMAIL" = "true" ]; then
# Retrieve admin email address, sendmail path, and message temp file path
admin_email=$($HESTIA/bin/v-list-user admin json | grep "CONTACT" | cut -d'"' -f4)
send_mail="$HESTIA/web/inc/mail-wrapper.php"
message_tmp_file="/tmp/hestia-upgrade-complete.txt"
# Create temporary file
touch $message_tmp_file
# Write message to file
echo "$HOSTNAME has been upgraded from Hestia Control Panel v$VERSION to v${new_version}." >> $message_tmp_file
echo "Installation log: $LOG" >> $message_tmp_file
echo "" >> $message_tmp_file
echo "What's new: https://github.com/hestiacp/hestiacp/blob/$RELEASE_BRANCH/CHANGELOG.md" >> $message_tmp_file
echo >> $message_tmp_file
echo "What to do if you run into issues:" >> $message_tmp_file
echo "- Check our forums for possible solutions: https://forum.hestiacp.com" >> $message_tmp_file
echo "- File an issue report on GitHub: https://github.com/hestiacp/hestiacp/issues" >> $message_tmp_file
echo "" >> $message_tmp_file
echo "===================================================" >> $message_tmp_file
echo "Have a wonderful day," >> $message_tmp_file
echo "The Hestia Control Panel development team" >> $message_tmp_file
# Read back message from file and pass through to sendmail
cat $message_tmp_file | $send_mail -s "Update Installed - v${new_version}" $admin_email
rm -f $message_tmp_file
fi
}
upgrade_send_log_to_email() {
if [ "$UPGRADE_SEND_EMAIL_LOG" = "true" ]; then
admin_email=$($BIN/v-list-user admin json | grep "CONTACT" | cut -d'"' -f4)
send_mail="$HESTIA/web/inc/mail-wrapper.php"
cat $LOG | $send_mail -s "Update Installation Log - v${new_version}" $admin_email
fi
}
upgrade_init_backup() {
# Ensure that backup directories are created
# Hestia Control Panel configuration files
mkdir -p $HESTIA_BACKUP/conf/hestia/
# System services (apache2, nginx, bind9, vsftpd, etc).
if [ ! -z "$WEB_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
fi
if [ ! -z "$IMAP_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
fi
if [ ! -z "$MAIL_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
fi
if [ ! -z "$DNS_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
fi
if [ ! -z "$PROXY_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
fi
if [ ! -z "$DB_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$DB_SYSTEM/
fi
if [ ! -z "$FTP_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
fi
if [ ! -z "$FIREWALL_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
fi
if [ ! -z "$FIREWALL_EXTENSION" ]; then
mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
fi
if [ -e "/etc/ssh/sshd_config" ]; then
mkdir -p $HESTIA_BACKUP/conf/ssh/
fi
# Hosting Packages
mkdir -p $HESTIA_BACKUP/packages/
# Domain template files
mkdir -p $HESTIA_BACKUP/templates/
# System services (apache2, nginx, bind9, vsftpd, etc).
if [ ! -z "$WEB_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$WEB_SYSTEM/
fi
if [ ! -z "$IMAP_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
fi
if [ ! -z "$MAIL_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
fi
if [ ! -z "$DNS_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$DNS_SYSTEM/
fi
if [ ! -z "$PROXY_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
fi
if [ ! -z "$DB_SYSTEM" ]; then
if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
mkdir -p $HESTIA_BACKUP/conf/mysql/
fi
if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
mkdir -p $HESTIA_BACKUP/conf/pgsql/
fi
fi
if [ ! -z "$FTP_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$FTP_SYSTEM/
fi
if [ ! -z "$FIREWALL_SYSTEM" ]; then
mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_SYSTEM/
fi
if [ ! -z "$FIREWALL_EXTENSION" ]; then
mkdir -p $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
fi
if [ -e "/etc/ssh/sshd_config" ]; then
mkdir -p $HESTIA_BACKUP/conf/ssh/
fi
}
upgrade_init_logging() {
# Set log file path
LOG="$HESTIA_BACKUP/hst-upgrade-$(date +%d%m%Y%H%M).log"
# Create log file
touch $LOG
}
upgrade_start_backup() {
echo "[ * ] Backing up existing templates and configuration files..."
if [ "$DEBUG_MODE" = "true" ]; then
echo " - Packages"
fi
cp -rf $HESTIA/data/packages/* $HESTIA_BACKUP/packages/
if [ "$DEBUG_MODE" = "true" ]; then
echo " - Templates"
fi
cp -rf $HESTIA/data/templates/* $HESTIA_BACKUP/templates/
if [ "$DEBUG_MODE" = "true" ]; then
echo " - Configuration files:"
fi
# Hestia Control Panel configuration files
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- hestia"
fi
cp -rf $HESTIA/conf/* $HESTIA_BACKUP/conf/hestia/
# System service configuration files (apache2, nginx, bind9, vsftpd, etc).
if [ ! -z "$WEB_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- $WEB_SYSTEM"
fi
cp -f /etc/$WEB_SYSTEM/*.conf $HESTIA_BACKUP/conf/$WEB_SYSTEM/
cp -f /etc/$WEB_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$WEB_SYSTEM/
fi
if [ ! -z "$PROXY_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- $PROXY_SYSTEM"
fi
cp -f /etc/$PROXY_SYSTEM/*.conf $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
cp -f /etc/$PROXY_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
cp -f /etc/$PROXY_SYSTEM/conf.d/*.inc $HESTIA_BACKUP/conf/$PROXY_SYSTEM/
fi
if [ ! -z "$IMAP_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- $IMAP_SYSTEM"
fi
cp -f /etc/$IMAP_SYSTEM/*.conf $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
cp -f /etc/$IMAP_SYSTEM/conf.d/*.conf $HESTIA_BACKUP/conf/$IMAP_SYSTEM/
fi
if [ ! -z "$MAIL_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- $MAIL_SYSTEM"
fi
cp -f /etc/$MAIL_SYSTEM/*.conf $HESTIA_BACKUP/conf/$MAIL_SYSTEM/
fi
if [ ! -z "$DNS_SYSTEM" ]; then
if [ "$DNS_SYSTEM" = "bind9" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- $DNS_SYSTEM"
fi
cp -f /etc/bind/*.conf $HESTIA_BACKUP/conf/$DNS_SYSTEM/
fi
fi
if [ ! -z "$DB_SYSTEM" ]; then
if [[ "$DB_SYSTEM" =~ "mysql" ]]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- mysql"
fi
cp -f /etc/mysql/*.cnf $HESTIA_BACKUP/conf/mysql/
cp -f /etc/mysql/conf.d/*.cnf $HESTIA_BACKUP/conf/mysql/ > /dev/null 2>&1
cp -f /etc/mysql/mariadb.conf.d/*.cnf $HESTIA_BACKUP/conf/mysql/ > /dev/null 2>&1
fi
if [[ "$DB_SYSTEM" =~ "pgsql" ]]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- pgsql"
fi
cp -f /etc/mysql/*.cnf $HESTIA_BACKUP/conf/pgsql/
cp -f /etc/mysql/conf.d/*.cnf $HESTIA_BACKUP/conf/pgsql/
fi
fi
if [ ! -z "$FTP_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- $FTP_SYSTEM"
fi
if [ "$FTP_SYSTEM" = "vsftpd" ]; then
cp -f /etc/$FTP_SYSTEM.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
fi
if [ "$FTP_SYSTEM" = "proftpd" ]; then
cp -f /etc/proftpd/proftpd.conf $HESTIA_BACKUP/conf/$FTP_SYSTEM/
fi
fi
if [ ! -z "$FIREWALL_EXTENSION" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- $FIREWALL_EXTENSION"
fi
cp -f /etc/$FIREWALL_EXTENSION/*.conf $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
cp -f /etc/$FIREWALL_EXTENSION/*.local $HESTIA_BACKUP/conf/$FIREWALL_EXTENSION/
fi
if [ -e "/etc/ssh/sshd_config" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- sshd"
fi
cp -f /etc/ssh/sshd_config $HESTIA_BACKUP/conf/ssh/sshd_config
fi
}
upgrade_refresh_config() {
source /usr/local/hestia/conf/hestia.conf
source /usr/local/hestia/func/main.sh
}
upgrade_start_routine() {
# Parse version numbers for comparison
function check_version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
# Remove pre-release designation from version number for upgrade scripts
VERSION=$(echo $VERSION | sed "s|~alpha||g" | sed "s|~beta||g")
# Get list of all available version steps and create array
upgrade_steps=$(ls $HESTIA/install/upgrade/versions/*.sh)
for script in $upgrade_steps; do
declare -a available_versions
available_versions+=($(echo $script | sed "s|/usr/local/hestia/install/upgrade/versions/||g" | sed "s|.sh||g"))
done
# Define variables for accessing supported versions
all_versions=$(printf "%s\n" ${available_versions[@]})
oldest_version=$(printf "%s\n" ${available_versions[@]} | sort -r | tail -n1)
latest_version=$(printf "%s\n" ${available_versions[@]} | tail -n1)
# Check for supported versions and process necessary upgrade steps
if [ $(check_version $latest_version) -gt $(check_version $VERSION) ]; then
for version_step in "${available_versions[@]}"
do
if [ $(check_version $VERSION) -lt $(check_version "$version_step") ]; then
upgrade_step_message
source $HESTIA/install/upgrade/versions/$version_step.sh
fi
done
upgrade_set_version $VERSION
upgrade_refresh_config
else
echo ""
echo "[ ! ] The latest version of Hestia Control Panel is already installed."
echo " Verifying configuration..."
echo ""
if [ -e "$HESTIA/install/upgrade/versions/$VERSION.sh" ]; then
source $HESTIA/install/upgrade/versions/$VERSION.sh
fi
VERSION="$new_version"
upgrade_set_version $VERSION
upgrade_refresh_config
fi
#####################################################################
####### End version-specific upgrade instruction sets #######
#####################################################################
}
upgrade_phpmyadmin() {
if [ "$UPGRADE_UPDATE_PHPMYADMIN" = "true" ]; then
# Check if MariaDB/MySQL is installed on the server before attempting to install or upgrade phpMyAdmin
if [ "$DB_SYSTEM" = "mysql" ]; then
# Define version check function
function version_ge(){ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o ! -z "$1" -a "$1" = "$2"; }
pma_release_file=$(ls /usr/share/phpmyadmin/RELEASE-DATE-* 2>/dev/null |tail -n 1)
if version_ge "${pma_release_file##*-}" "$pma_v"; then
echo "[ ! ] Verifying phpMyAdmin v${pma_release_file##*-} installation..."
# Update permissions
if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
chmod 0644 /var/lib/phpmyadmin/blowfish_secret.inc.php
fi
else
# Display upgrade information
echo "[ * ] Upgrading phpMyAdmin to version v$pma_v..."
[ -d /usr/share/phpmyadmin ] || mkdir -p /usr/share/phpmyadmin
# Download latest phpMyAdmin release
wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
# Unpack files
tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
# Delete file to prevent error
rm -fr /usr/share/phpmyadmin/doc/html
# Overwrite old files
cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
# Set config and log directory
sed -i "s|define('CONFIG_DIR', ROOT_PATH);|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
sed -i "s|define('TEMP_DIR', ROOT_PATH . 'tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
# Create temporary folder and change permissions
if [ ! -d /usr/share/phpmyadmin/tmp ]; then
mkdir /usr/share/phpmyadmin/tmp
chmod 777 /usr/share/phpmyadmin/tmp
fi
if [ -e /var/lib/phpmyadmin/blowfish_secret.inc.php ]; then
chmod 0644 /var/lib/phpmyadmin/blowfish_secret.inc.php
fi
# Clean up source files
rm -fr phpMyAdmin-$pma_v-all-languages
rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
fi
fi
fi
}
upgrade_filemanager() {
if [ "$UPGRADE_UPDATE_FILEMANAGER" = "true" ]; then
FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
if [ -z "$FILE_MANAGER_CHECK" ]; then
echo "[ * ] Updating File Manager..."
# Reinstall the File Manager
$HESTIA/bin/v-delete-sys-filemanager quiet
$HESTIA/bin/v-add-sys-filemanager quiet
fi
fi
}
upgrade_filemanager_update_config() {
if [ "$UPGRADE_UPDATE_FILEMANAGER_CONFIG" = "true" ]; then
FILE_MANAGER_CHECK=$(cat $HESTIA/conf/hestia.conf | grep "FILE_MANAGER='false'")
if [ -z "$FILE_MANAGER_CHECK" ]; then
if [ -e "$HESTIA/web/fm/configuration.php" ]; then
echo "[ * ] Updating File Manager configuration..."
# Update configuration.php
cp -f $HESTIA_INSTALL_DIR/filemanager/filegator/configuration.php $HESTIA/web/fm/configuration.php
# Set environment variable for interface
$HESTIA/bin/v-change-sys-config-value 'FILE_MANAGER' 'true'
fi
fi
fi
}
upgrade_roundcube(){
if [ "UPGRADE_UPDATE_ROUNDCUBE" = "true" ]; then
if [ ! -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'roundcube')" ]; then
rc_version=$(cat /var/lib/roundcube/index.php | grep -o -E '[0-9].[0-9].[0-9]+' | head -1);
if [ "$rc_version" == "$rc_v" ]; then
echo "[ * ] Upgrading Roundcube to version v$rc_v..."
$HESTIA/bin/v-add-sys-roundcube
fi
fi
fi
}
upgrade_rainloop(){
if [ "UPGRADE_UPDATE_RAINLOOP" = "true" ]; then
if [ ! -z "$(echo "$WEBMAIL_SYSTEM" | grep -w 'rainloop')" ]; then
rc_version=$(cat /var/lib/rainloop/data/VERSION);
if [ "$rc_version" == "$rc_v" ]; then
echo "[ * ] Upgrading Rainloop to version v$rl_v..."
$HESTIA/bin/v-add-sys-rainloop
fi
fi
fi
}
disable_api(){
if [ "$API" = "no" ]; then
echo "[ ! ] Disable Api..."
sed -i 's|//die("Error: Disabled");|die("Error: Disabled");|g' $HESTIA/web/api/index.php
$HESTIA/bin/v-change-sys-config-value "API_ALLOWED_IP" ""
fi
}
upgrade_rebuild_web_templates() {
if [ "$UPGRADE_UPDATE_WEB_TEMPLATES" = "true" ]; then
echo "[ ! ] Updating default web domain templates..."
$BIN/v-update-web-templates "no" "skip"
fi
}
upgrade_rebuild_mail_templates() {
if [ "$UPGRADE_UPDATE_MAIL_TEMPLATES" = "true" ]; then
echo "[ ! ] Updating default mail domain templates..."
$BIN/v-update-mail-templates "no" "skip"
fi
}
upgrade_rebuild_dns_templates() {
if [ "$UPGRADE_UPDATE_DNS_TEMPLATES" = "true" ]; then
echo "[ ! ] Updating default DNS zone templates..."
$BIN/v-update-dns-templates
fi
}
upgrade_rebuild_users() {
if [ "$UPGRADE_REBUILD_USERS" = "true" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo "[ * ] Rebuilding user accounts and domains:"
else
echo "[ * ] Rebuilding user accounts and domains, this may take a few minutes..."
fi
for user in $($HESTIA/bin/v-list-sys-users plain); do
export restart="no"
if [ "$DEBUG_MODE" = "true" ]; then
echo " - $user:"
else
echo " - $user..."
fi
if [ ! -z "$WEB_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- Web domains..."
$BIN/v-rebuild-web-domains $user 'no'
else
$BIN/v-rebuild-web-domains $user 'no' >/dev/null 2>&1
fi
fi
if [ ! -z "$DNS_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- DNS zones..."
$BIN/v-rebuild-dns-domains $user 'no'
else
$BIN/v-rebuild-dns-domains $user 'no' >/dev/null 2>&1
fi
fi
if [ ! -z "$MAIL_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- Mail domains..."
$BIN/v-rebuild-mail-domains $user 'no'
else
$BIN/v-rebuild-mail-domains $user 'no' >/dev/null 2>&1
fi
fi
if [ "$DEBUG_MODE" = "true" ]; then
echo " ---- User configuration..."
$BIN/v-rebuild-user $user 'no'
else
$BIN/v-rebuild-user $user 'no' >/dev/null 2>&1
fi
done
fi
}
upgrade_restart_services() {
if [ "$UPGRADE_RESTART_SERVICES" = "true" ]; then
echo "[ * ] Restarting services..."
export restart="yes"
sleep 2
if [ ! -z "$MAIL_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " - $MAIL_SYSTEM"
fi
$BIN/v-restart-mail $restart
fi
if [ ! -z "$WEB_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " - $WEB_SYSTEM"
fi
$BIN/v-restart-web $restart
fi
if [ ! -z "$PROXY_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " - $PROXY_SYSTEM"
fi
$BIN/v-restart-proxy $restart
fi
if [ ! -z "$DNS_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " - $DNS_SYSTEM"
fi
$BIN/v-restart-dns $restart
fi
for v in `ls /etc/php/`; do
if [ -e /etc/php/$v/fpm ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " - php$v-fpm"
fi
$BIN/v-restart-service php$v-fpm
fi
done
if [ ! -z "$FTP_SYSTEM" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " - $FTP_SYSTEM"
fi
$BIN/v-restart-ftp $restart
fi
if [ ! -z "$FIREWALL_EXTENSION" ]; then
if [ "$DEBUG_MODE" = "true" ]; then
echo " - $FIREWALL_EXTENSION"
fi
$BIN/v-restart-service $FIREWALL_EXTENSION
fi
# Restart SSH daemon service
if [ "$DEBUG_MODE" = "true" ]; then
echo " - sshd"
fi
$BIN/v-restart-service ssh
fi
# Always restart the Hestia Control Panel service
if [ "$DEBUG_MODE" = "true" ]; then
echo " - hestia"
fi
$BIN/v-restart-service hestia
}
upgrade_perform_cleanup() {
# Remove upgrade configuration file as it's not needed
rm -f $HESTIA_INSTALL_DIR/upgrade/upgrade.conf
}