-
Notifications
You must be signed in to change notification settings - Fork 67
/
virtualmin-install.sh
1605 lines (1451 loc) · 51.1 KB
/
virtualmin-install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
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
#!/bin/sh
# shellcheck disable=SC2059 disable=SC2181 disable=SC2154 disable=SC2317 disable=SC2034
# virtualmin-install.sh
# Copyright 2005-2024 Virtualmin
# Simple script to install Virtualmin on a supported OS
# Different installation guides are available at:
# https://www.virtualmin.com/docs/installation/guides
# License and version
SERIAL=GPL
KEY=GPL
VER=7.5.1
vm_version=7
# Server
download_virtualmin_host="${download_virtualmin_host:-software.virtualmin.com}"
download_virtualmin_host_lib="$download_virtualmin_host/lib"
# Save current working directory
pwd="$PWD"
# Script name
if [ "$0" = "--" ] || [ -z "$0" ]; then
script_name="virtualmin-install.sh"
else
script_name=$(basename -- "$0")
fi
# Set log type
log_file_name="${install_log_file_name:-virtualmin-install}"
# Set defaults
bundle='LAMP' # Other option is LEMP
mode='full' # Other option is minimal
skipyesno=0
usage() {
# shellcheck disable=SC2046
echo
printf "Usage: %s [options]\\n" "$(basename "$0")"
echo
echo " If called without arguments, installs Virtualmin with default options."
echo
printf " --bundle|-b <LAMP|LEMP> choose bundle to install (defaults to LAMP)\\n"
printf " --minimal|-m install a minimal package set for low-memory systems\\n"
printf " --unstable|-e enable Grade B system support (see documentation)\\n"
printf " --module|-o source custom shell module in post-install phase\\n"
echo
printf " --hostname|-n force hostname during installation\\n"
printf " --no-package-updates|-x skip package updates during installation\\n"
echo
printf " --setup|-s reconfigure Virtualmin repos without installation\\n"
echo
printf " --insecure-downloads|-i skip SSL certificate check for remote downloads\\n"
echo
printf " --uninstall|-u remove all Virtualmin packages and dependencies\\n"
echo
printf " --force|-f|--yes|-y assume \"yes\" to all prompts\\n"
printf " --force-reinstall|-fr force reinstall Virtualmin (not recommended)\\n"
printf " --no-banner|-nb suppress installation messages and warnings\\n"
printf " --verbose|-v enable verbose mode\\n"
printf " --version|-V show installer version\\n"
printf " --help|-h show this help\\n"
echo
}
# Bind hooks
bind_hook() {
hook="$1"
shift
pre_hook="pre_hook__$hook"
post_hook="post_hook__$hook"
# Do we want to completely override the original function?
if command -v "hook__$hook" > /dev/null 2>&1; then
"hook__$hook" "$@"
# Or do we want to run the original function wrapped by third-party functions?
else
if command -v "$pre_hook" > /dev/null 2>&1; then
"$pre_hook" "$@"
fi
if command -v "$hook" > /dev/null 2>&1; then
"$hook" "$@"
fi
if command -v "$post_hook" > /dev/null 2>&1; then
"$post_hook" "$@"
fi
fi
}
# Default function to parse arguments
parse_args() {
while [ "$1" != "" ]; do
case $1 in
--help | -h)
bind_hook "usage"
exit 0
;;
--bundle | -b)
shift
case "$1" in
LAMP)
shift
bundle='LAMP'
;;
LEMP)
shift
bundle='LEMP'
;;
*)
printf "Unknown bundle $1: exiting\\n"
exit 1
;;
esac
;;
--minimal | -m)
shift
mode='minimal'
;;
--insecure-downloads | -i)
shift
insecure_download_wget_flag=' --no-check-certificate'
insecure_download_curl_flag=' -k'
;;
--no-package-updates | -x)
shift
noupdates=1
;;
--setup | -s)
shift
setup_only=1
mode='setup'
unstable='unstable'
log_file_name="${setup_log_file_name:-virtualmin-repos-setup}"
;;
--unstable | -e)
shift
unstable='unstable'
virtualmin_config_system_excludes=""
virtualmin_stack_custom_packages=""
;;
--module | -o)
shift
module_name=$1
shift
;;
--hostname | -n)
shift
forcehostname=$1
shift
;;
--force | -f | --yes | -y)
shift
skipyesno=1
;;
--force-reinstall | -fr)
shift
forcereinstall=1
;;
--no-banner | -nb)
shift
skipbanner=1
;;
--verbose | -v)
shift
VERBOSE=1
;;
--version | -V)
shift
showversion=1
;;
--uninstall | -u)
shift
mode="uninstall"
log_file_name="${uninstall_log_file_name:-virtualmin-uninstall}"
;;
*)
printf "Unrecognized option: $1\\n"
bind_hook "usage"
exit 1
;;
esac
done
}
# Hook arguments
bind_hook "parse_args" "$@"
# Default function to show installer version
show_version() {
echo "$VER"
exit 0
}
# Hook version
if [ -n "$showversion" ]; then
bind_hook "show_version"
fi
# Force setup mode, if script name is `setup-repos.sh` as it
# is used by Virtualmin API, to make sure users won't run an
# actuall install script under any circumstances
if [ "$script_name" = "setup-repos.sh" ]; then
setup_only=1
mode='setup'
unstable='unstable'
fi
# Store new log each time
log="$pwd/$log_file_name.log"
if [ -e "$log" ]; then
while true; do
logcnt=$((logcnt+1))
logold="$log.$logcnt"
if [ ! -e "$logold" ]; then
mv "$log" "$logold"
break
fi
done
fi
# If Pro user downloads GPL version of `install.sh` script
# to fix repos check if there is an active license exists
if [ -n "$setup_only" ]; then
if [ "$SERIAL" = "GPL" ] && [ "$KEY" = "GPL" ] && [ -f /etc/virtualmin-license ]; then
virtualmin_license_existing_serial="$(grep 'SerialNumber=' /etc/virtualmin-license | sed 's/SerialNumber=//')"
virtualmin_license_existing_key="$(grep 'LicenseKey=' /etc/virtualmin-license | sed 's/LicenseKey=//')"
if [ -n "$virtualmin_license_existing_serial" ] && [ -n "$virtualmin_license_existing_key" ]; then
SERIAL="$virtualmin_license_existing_serial"
KEY="$virtualmin_license_existing_key"
fi
fi
fi
arch="$(uname -m)"
if [ "$arch" = "i686" ]; then
arch="i386"
fi
if [ "$SERIAL" = "GPL" ]; then
LOGIN=""
PRODUCT="GPL"
repopath="gpl/"
packagetype="gpl"
else
LOGIN="$SERIAL:$KEY@"
PRODUCT="Professional"
packagetype="pro"
repopath="pro/"
fi
# Virtualmin-provided packages
vmgroup="'Virtualmin Core'"
vmgrouptext="Virtualmin $vm_version provided packages"
debvmpackages="virtualmin-core"
deps=
if [ "$mode" = 'full' ]; then
if [ "$bundle" = 'LAMP' ]; then
rhgroup="'Virtualmin LAMP Stack'"
rhgrouptext="Virtualmin $vm_version LAMP stack"
debdeps="virtualmin-lamp-stack"
ubudeps="virtualmin-lamp-stack"
elif [ "$bundle" = 'LEMP' ]; then
rhgroup="'Virtualmin LEMP Stack'"
rhgrouptext="Virtualmin $vm_version LEMP stack"
debdeps="virtualmin-lemp-stack"
ubudeps="virtualmin-lemp-stack"
fi
elif [ "$mode" = 'minimal' ]; then
if [ "$bundle" = 'LAMP' ]; then
rhgroup="'Virtualmin LAMP Stack Minimal'"
rhgrouptext="Virtualmin $vm_version LAMP stack minimal"
debdeps="virtualmin-lamp-stack-minimal"
ubudeps="virtualmin-lamp-stack-minimal"
elif [ "$bundle" = 'LEMP' ]; then
rhgroup="'Virtualmin LEMP Stack Minimal'"
rhgrouptext="Virtualmin $vm_version LEMP stack minimal'"
debdeps="virtualmin-lemp-stack-minimal"
ubudeps="virtualmin-lemp-stack-minimal"
fi
fi
# Find temp directory
if [ -z "$TMPDIR" ]; then
TMPDIR=/tmp
fi
# Check whether $TMPDIR is mounted noexec (everything will fail, if so)
# XXX: This check is imperfect. If $TMPDIR is a full path, but the parent dir
# is mounted noexec, this won't catch it.
TMPNOEXEC="$(grep "$TMPDIR" /etc/mtab | grep noexec)"
if [ -n "$TMPNOEXEC" ]; then
echo "Error: $TMPDIR directory is mounted noexec. Cannot continue."
exit 1
fi
if [ -z "$VIRTUALMIN_INSTALL_TEMPDIR" ]; then
VIRTUALMIN_INSTALL_TEMPDIR="$TMPDIR/.virtualmin-$$"
if [ -e "$VIRTUALMIN_INSTALL_TEMPDIR" ]; then
rm -rf "$VIRTUALMIN_INSTALL_TEMPDIR"
fi
mkdir "$VIRTUALMIN_INSTALL_TEMPDIR"
fi
# Export temp directory for Virtualmin Config
export VIRTUALMIN_INSTALL_TEMPDIR
# "files" subdir for libs
mkdir "$VIRTUALMIN_INSTALL_TEMPDIR/files"
srcdir="$VIRTUALMIN_INSTALL_TEMPDIR/files"
# Switch to temp directory or exit with error
goto_tmpdir() {
if ! cd "$srcdir" >>"$log" 2>&1; then
echo "Error: Failed to enter $srcdir temporary directory"
exit 1
fi
}
goto_tmpdir
pre_check_http_client() {
# Check for wget or curl or fetch
printf "Checking for HTTP client .." >>"$log"
while true; do
if [ -x "/usr/bin/wget" ]; then
download="/usr/bin/wget -nv$insecure_download_wget_flag"
break
elif [ -x "/usr/bin/curl" ]; then
download="/usr/bin/curl -f$insecure_download_curl_flag -s -L -O"
break
elif [ -x "/usr/bin/fetch" ]; then
download="/usr/bin/fetch"
break
elif [ "$wget_attempted" = 1 ]; then
printf " error: No HTTP client available. The installation of a download command has failed. Cannot continue.\\n" >>"$log"
return 1
fi
# Made it here without finding a downloader, so try to install one
wget_attempted=1
if [ -x /usr/bin/dnf ]; then
dnf -y install wget >>"$log"
elif [ -x /usr/bin/yum ]; then
yum -y install wget >>"$log"
elif [ -x /usr/bin/apt-get ]; then
apt-get update >>/dev/null
apt-get -y -q install wget >>"$log"
fi
done
if [ -z "$download" ]; then
printf " not found\\n" >>"$log"
return 1
else
printf " found %s\\n" "$download" >>"$log"
return 0;
fi
}
download_slib() {
# If slib.sh is available locally in the same directory use it
if [ -f "$pwd/slib.sh" ]; then
chmod +x "$pwd/slib.sh"
# shellcheck disable=SC1091
. "$pwd/slib.sh"
# Download the slib (source: http://github.com/virtualmin/slib)
else
# We need HTTP client first
pre_check_http_client
$download "https://$download_virtualmin_host_lib/slib.sh" >>"$log" 2>&1
if [ $? -ne 0 ]; then
echo "Error: Failed to download utility function library. Cannot continue. Check your network connection and DNS settings, and verify that your system's time is accurately synchronized."
exit 1
fi
chmod +x slib.sh
# shellcheck disable=SC1091
. ./slib.sh
fi
}
# Check if already installed successfully
already_installed_block() {
log_error "Your system already has a successful Virtualmin installation deployed."
log_error "Re-installation is neither possible nor necessary. This script must be"
log_error "run on a freshly installed supported operating system. It does not fit"
log_error "for package updates or license changes. For further assistance, please"
log_error "visit the Virtualmin Community forum."
exit 100
}
# Utility function library
##########################################
download_slib # for production this block
# can be replaces with the
# content of slib.sh file,
# minus its header
##########################################
# Get OS type
get_distro
# Check the serial number and key
serial_ok "$SERIAL" "$KEY"
# Setup slog
LOG_PATH="$log"
# Setup run_ok
RUN_LOG="$log"
# Exit on any failure during shell stage
RUN_ERRORS_FATAL=1
# Console output level; ignore debug level messages.
if [ "$VERBOSE" = "1" ]; then
LOG_LEVEL_STDOUT="DEBUG"
else
LOG_LEVEL_STDOUT="INFO"
fi
# Log file output level; catch literally everything.
LOG_LEVEL_LOG="DEBUG"
# If already installed successfully, do not allow running again
if [ -f "/etc/webmin/virtual-server/installed-auto" ] && [ -z "$setup_only" ] && [ -z "$forcereinstall" ]; then
bind_hook "already_installed_block"
fi
if [ -n "$setup_only" ]; then
log_info "Setup log is written to $LOG_PATH"
elif [ "$mode" = "uninstall" ]; then
log_info "Uninstallation log is written to $LOG_PATH"
else
log_info "Installation log is written to $LOG_PATH"
fi
log_debug "LOG_ERRORS_FATAL=$RUN_ERRORS_FATAL"
log_debug "LOG_LEVEL_STDOUT=$LOG_LEVEL_STDOUT"
log_debug "LOG_LEVEL_LOG=$LOG_LEVEL_LOG"
# log_fatal calls log_error
log_fatal() {
log_error "$1"
}
# Test if grade B system
grade_b_system() {
case "$os_type" in
rhel | centos | rocky | almalinux | debian | ubuntu)
return 1
;;
esac
return 0
}
if grade_b_system && [ "$unstable" != 'unstable' ]; then
log_error "Unsupported operating system detected. You may be able to install with"
log_error "${YELLOW}--unstable${NORMAL} flag, but this is not recommended. Consult the installation"
log_error "documentation."
exit 1
fi
remove_virtualmin_release() {
case "$os_type" in
rhel | fedora | centos | centos_stream | rocky | almalinux | openEuler | ol | cloudlinux | amzn )
rm -f /etc/yum.repos.d/virtualmin.repo
rm -f /etc/pki/rpm-gpg/RPM-GPG-KEY-virtualmin*
rm -f /etc/pki/rpm-gpg/RPM-GPG-KEY-webmin
;;
debian | ubuntu | kali)
grep -v "virtualmin" /etc/apt/sources.list >"$VIRTUALMIN_INSTALL_TEMPDIR"/sources.list
mv "$VIRTUALMIN_INSTALL_TEMPDIR"/sources.list /etc/apt/sources.list
rm -f /etc/apt/sources.list.d/virtualmin.list
rm -f /etc/apt/auth.conf.d/virtualmin.conf
rm -f /usr/share/keyrings/debian-virtualmin*
rm -f /usr/share/keyrings/debian-webmin
rm -f /usr/share/keyrings/ubuntu-virtualmin*
rm -f /usr/share/keyrings/ubuntu-webmin
rm -f /usr/share/keyrings/kali-virtualmin*
rm -f /usr/share/keyrings/kali-webmin
;;
esac
}
fatal() {
echo
log_fatal "Fatal Error Occurred: $1"
printf "${RED}Cannot continue installation.${NORMAL}\\n"
remove_virtualmin_release
if [ -x "$VIRTUALMIN_INSTALL_TEMPDIR" ]; then
log_warning "Removing temporary directory and files."
rm -rf "$VIRTUALMIN_INSTALL_TEMPDIR"
fi
log_fatal "If you are unsure of what went wrong, you may wish to review the log"
log_fatal "in $log"
exit 1
}
success() {
log_success "$1 Succeeded."
}
# Function to find out if some services were pre-installed
is_preconfigured() {
preconfigured=""
if named -v 1>/dev/null 2>&1; then
preconfigured="${preconfigured}${YELLOW}${BOLD}BIND${NORMAL} "
fi
if apachectl -v 1>/dev/null 2>&1; then
preconfigured="${preconfigured}${YELLOW}${BOLD}Apache${NORMAL} "
fi
if nginx -v 1>/dev/null 2>&1; then
preconfigured="${preconfigured}${YELLOW}${BOLD}Nginx${NORMAL} "
fi
if command -pv mariadb 1>/dev/null 2>&1; then
preconfigured="${preconfigured}${YELLOW}${BOLD}MariaDB${NORMAL} "
fi
if postconf mail_version 1>/dev/null 2>&1; then
preconfigured="${preconfigured}${YELLOW}${BOLD}Postfix${NORMAL} "
fi
if php -v 1>/dev/null 2>&1; then
preconfigured="${preconfigured}${YELLOW}${BOLD}PHP${NORMAL} "
fi
preconfigured=$(echo "$preconfigured" | sed 's/ /, /g' | sed 's/, $/ /')
echo "$preconfigured"
}
# Function to find out if Virtualmin is already installed, so we can get
# rid of some of the warning message. Nobody reads it, and frequently
# folks run the install script on a production system; either to attempt
# to upgrade, or to "fix" something. That's never the right thing.
is_installed() {
if [ -f /etc/virtualmin-license ]; then
# looks like it's been installed before
return 0
fi
# XXX Probably not installed? Maybe we should remove license on uninstall, too.
return 1
}
# This function performs a rough uninstallation of Virtualmin
# all related packages and configurations
uninstall() {
log_debug "Initiating Virtualmin uninstallation procedure"
log_debug "Operating system name: $os_real"
log_debug "Operating system version: $os_version"
log_debug "Operating system type: $os_type"
log_debug "Operating system major: $os_major_version"
if [ "$skipyesno" -ne 1 ]; then
echo
printf " ${REDBG}WARNING${NORMAL}\\n"
echo
echo " This operation is highly disruptive and cannot be undone. It removes all of"
echo " the packages and configuration files installed by the Virtualmin installer."
echo
echo " It must never be executed on a live production system."
echo
printf " ${RED}Uninstall?${NORMAL} (y/N) "
if ! yesno; then
exit
fi
fi
# Always sleep just a bit in case the user changes their mind
sleep 3
# Go to the temp directory
goto_tmpdir
# Uninstall packages
uninstall_packages()
{
# Detect the package manager
case "$os_type" in
rhel | fedora | centos | centos_stream | rocky | almalinux | openEuler | ol | cloudlinux | amzn )
package_type=rpm
if command -pv dnf 1>/dev/null 2>&1; then
uninstall_cmd="dnf remove -y"
uninstall_cmd_group="dnf groupremove -y"
else
uninstall_cmd="yum remove -y"
uninstall_cmd_group="yum groupremove -y"
fi
;;
debian | ubuntu | kali)
package_type=deb
uninstall_cmd="apt-get remove --assume-yes --purge"
;;
esac
case "$package_type" in
rpm)
$uninstall_cmd_group "Virtualmin Core" "Virtualmin LAMP Stack" "Virtualmin LEMP Stack" "Virtualmin LAMP Stack Minimal" "Virtualmin LEMP Stack Minimal"
$uninstall_cmd wbm-* wbt-* webmin* usermin* virtualmin*
os_type="rhel"
return 0
;;
deb)
$uninstall_cmd "virtualmin*" "webmin*" "usermin*"
apt-get autoremove --assume-yes
os_type="debian"
return 0
;;
*)
log_error "Unknown package manager, cannot uninstall"
return 1
;;
esac
}
# Uninstall repos and helper command
uninstall_repos()
{
echo "Removing Virtualmin $vm_version repo configuration"
remove_virtualmin_release
virtualmin_license_file="/etc/virtualmin-license"
if [ -f "$virtualmin_license_file" ]; then
echo "Removing Virtualmin license"
rm "$virtualmin_license_file"
fi
echo "Removing Virtualmin helper command"
rm "/usr/sbin/virtualmin"
echo "Virtualmin uninstallation complete."
}
printf "${YELLOW}▣${NORMAL} Phase ${YELLOW}1${NORMAL} of ${GREEN}1${NORMAL}: Uninstall\\n"
run_ok "uninstall_packages" "Uninstalling Virtualmin $vm_version and all stack packages"
run_ok "uninstall_repos" "Uninstalling Virtualmin $vm_version release package"
exit 0
}
# Phase control
phase() {
phases_total="${phases_total:-4}"
phase_description="$1"
phase_number="$2"
# Print completed phases (green)
printf "${GREEN}"
for i in $(seq 1 $(( phase_number - 1 ))); do
printf "▣"
done
# Print current phase (yellow)
printf "${YELLOW}▣"
# Print remaining phases (cyan)
for i in $(seq $(( phase_number + 1 )) "$phases_total"); do
printf "${CYAN}◻"
done
log_debug "Phase ${phase_number} of ${phases_total}: ${phase_description}"
printf "${NORMAL} Phase ${YELLOW}${phase_number}${NORMAL} of ${GREEN}${phases_total}${NORMAL}: ${phase_description}\\n"
}
if [ "$mode" = "uninstall" ]; then
bind_hook "uninstall"
fi
# Calculate disk space requirements (this is a guess, for now)
if [ "$mode" = 'minimal' ]; then
disk_space_required=1
else
disk_space_required=2
fi
# Message to display in interactive mode
install_msg() {
supported=" ${CYANBG}${BLACK}${BOLD}Red Hat Enterprise Linux and derivatives${NORMAL}${CYAN}
- RHEL 8 and 9 on x86_64
- Alma and Rocky 8 and 9 on x86_64
- CentOS 7 on x86_64${NORMAL}
UNSTABLERHEL
${CYANBG}${BLACK}${BOLD}Debian Linux and derivatives${NORMAL}${CYAN}
- Debian 10, 11 and 12 on i386 and amd64
- Ubuntu 20.04 LTS, 22.04 LTS and 24.04 LTS on i386 and amd64${NORMAL}
UNSTABLEDEB"
cat <<EOF
Welcome to the Virtualmin ${GREEN}$PRODUCT${NORMAL} installer, version ${GREEN}$VER${NORMAL}
This script must be run on a freshly installed supported OS. It does not
perform updates or upgrades (use your system package manager) or license
changes (use the "virtualmin change-license" command).
The systems currently supported by the install script are:
EOF
supported_all=$supported
if [ -n "$unstable" ]; then
unstable_rhel="${YELLOW}- Fedora Server 40 and above on x86_64\\n \
- CentOS Stream 8 and 9 on x86_64\\n \
- Amazon Linux 2023 and above on x86_64\\n \
- Oracle Linux 8 and 9 on x86_64\\n \
- CloudLinux 8 and 9 on x86_64\\n \
- openEuler 24.03 and above on x86_64\\n \
${NORMAL}"
unstable_deb="${YELLOW}- Kali Linux Rolling 2023 and above on x86_64\\n \
${NORMAL}"
supported_all=$(echo "$supported_all" | sed "s/UNSTABLERHEL/$unstable_rhel/")
supported_all=$(echo "$supported_all" | sed "s/UNSTABLEDEB/$unstable_deb/")
else
supported_all=$(echo "$supported_all" | sed 's/UNSTABLERHEL//')
supported_all=$(echo "$supported_all" | sed 's/UNSTABLEDEB//')
fi
echo "$supported_all"
cat <<EOF
If your OS/version/arch is not listed, installation ${BOLD}${RED}will fail${NORMAL}. More
details about the systems supported by the script can be found here:
${UNDERLINE}https://www.virtualmin.com/os-support${NORMAL}
The selected package bundle is ${CYAN}${bundle}${NORMAL} and the size of install is
${CYAN}${mode}${NORMAL}. It will require up to ${CYAN}${disk_space_required} GB${NORMAL} of disk space.
EOF
if [ "$skipyesno" -ne 1 ]; then
cat <<EOF
Exit and re-run this script with ${CYAN}--help${NORMAL} flag to see available options.
EOF
fi
if [ "$skipyesno" -ne 1 ]; then
printf " Continue? (y/n) "
if ! yesno; then
exit
fi
fi
}
if [ -z "$setup_only" ] && [ -z "$skipbanner" ]; then
bind_hook "install_msg"
fi
os_unstable_pre_check() {
if [ -n "$unstable" ]; then
cat <<EOF
${YELLOWBG}${BLACK}${BOLD} INSTALLATION WARNING! ${NORMAL}
You are about to install Virtualmin $PRODUCT on a ${BOLD}Grade B${NORMAL} operating
system. Be advised that this OS version is not recommended for servers,
and may have bugs that could affect the performance and stability of
the system.
Certain features may not work as intended or might be unavailable on
this OS.
EOF
if [ "$skipyesno" -ne 1 ]; then
printf " Continue? (y/n) "
if ! yesno; then
exit
fi
fi
fi
}
preconfigured_system_msg() {
# Double check if installed, just in case above error ignored.
is_preconfigured_rs=$(is_preconfigured)
if [ -n "$is_preconfigured_rs" ]; then
cat <<EOF
${WHITEBG}${RED}${BOLD} ATTENTION! ${NORMAL}
Pre-installed software detected: $is_preconfigured_rs
It is highly advised ${BOLD}${RED}not to pre-install${NORMAL} any additional packages on your
OS. The installer expects a freshly installed OS, and anything you do
differently might cause conflicts or configuration errors. If you need
to enable third-party package repositories, do so after installation
of Virtualmin, and only with extreme caution.
EOF
if [ "$skipyesno" -ne 1 ]; then
printf " Continue? (y/n) "
if ! yesno; then
exit
fi
fi
fi
}
already_installed_msg() {
# Double check if installed, just in case above error ignored.
if is_installed; then
cat <<EOF
${WHITEBG}${RED}${BOLD} WARNING! ${NORMAL}
Virtualmin may already be installed. This can happen if an installation
failed, and can be ignored in that case.
However, if Virtualmin has already been successfully installed you
${BOLD}${RED}must not${NORMAL} run this script again! It will cause breakage to your
existing configuration.
Virtualmin repositories can be fixed using ${WHITEBG}${BLACK}${BOLD}$script_name --setup${NORMAL}
command.
License can be changed using ${WHITEBG}${BLACK}${BOLD}virtualmin change-license${NORMAL} command.
Changing the license never requires re-installation.
Updates and upgrades must be performed from within either Virtualmin or
using system package manager on the command line.
EOF
if [ "$skipyesno" -ne 1 ]; then
printf " Continue? (y/n) "
if ! yesno; then
exit
fi
fi
fi
}
post_install_message() {
log_success "Installation Complete!"
log_success "If there were no errors above, Virtualmin should be ready"
log_success "to configure at https://${hostname}:10000 (or https://${address}:10000)."
if [ -z "$ssl_host_success" ]; then
log_success "You may receive a security warning in your browser on your first visit."
fi
}
if [ -z "$setup_only" ] && [ -z "$skipbanner" ]; then
if grade_b_system; then
bind_hook "os_unstable_pre_check"
fi
bind_hook "preconfigured_system_msg"
bind_hook "already_installed_msg"
fi
# Check memory
if [ "$mode" = "full" ]; then
minimum_memory=1610613
else
# minimal mode probably needs less memory to succeed
minimum_memory=1048576
fi
if ! memory_ok "$minimum_memory" "$disk_space_required"; then
log_fatal "Too little memory, and unable to create a swap file. Consider adding swap"
log_fatal "or more RAM to your system."
exit 1
fi
# Check for localhost in /etc/hosts
if [ -z "$setup_only" ]; then
grep localhost /etc/hosts >/dev/null
if [ "$?" != 0 ]; then
log_warning "There is no localhost entry in /etc/hosts. This is required, so one will be added."
run_ok "echo 127.0.0.1 localhost >> /etc/hosts" "Editing /etc/hosts"
if [ "$?" -ne 0 ]; then
log_error "Failed to configure a localhost entry in /etc/hosts."
log_error "This may cause problems, but we'll try to continue."
fi
fi
fi
pre_check_system_time() {
# Check if current time
# is not older than
# Wed Dec 01 2022
printf "Syncing system time ..\\n" >>"$log"
TIMEBASE=1669888800
TIME=$(date +%s)
if [ "$TIME" -lt "$TIMEBASE" ]; then
# Try to sync time automatically first
if systemctl restart chronyd 1>/dev/null 2>&1; then
sleep 30
elif systemctl restart systemd-timesyncd 1>/dev/null 2>&1; then
sleep 30
fi
# Check again after all
TIME=$(date +%s)
if [ "$TIME" -lt "$TIMEBASE" ]; then
printf ".. failed to automatically sync system time; it should be corrected manually to continue\\n" >>"$log"
return 1;
fi
# Graceful sync
else
if systemctl restart chronyd 1>/dev/null 2>&1; then
sleep 10
elif systemctl restart systemd-timesyncd 1>/dev/null 2>&1; then
sleep 10
fi
fi
printf ".. done\\n" >>"$log"
return 0
}
pre_check_ca_certificates() {
printf "Checking for an update for a set of CA certificates ..\\n" >>"$log"
if [ -x /usr/bin/dnf ]; then
dnf -y update ca-certificates >>"$log" 2>&1
elif [ -x /usr/bin/yum ]; then
yum -y update ca-certificates >>"$log" 2>&1
elif [ -x /usr/bin/apt-get ]; then
apt-get -y install ca-certificates >>"$log" 2>&1
fi
res=$?
printf ".. done\\n" >>"$log"
return "$res"
}
pre_check_perl() {
printf "Checking for Perl .." >>"$log"
# loop until we've got a Perl or until we can't try any more
while true; do
perl="$(command -pv perl 2>/dev/null)"
if [ -z "$perl" ]; then
if [ -x /usr/bin/perl ]; then
perl=/usr/bin/perl
break
elif [ -x /usr/local/bin/perl ]; then
perl=/usr/local/bin/perl
break
elif [ -x /opt/csw/bin/perl ]; then
perl=/opt/csw/bin/perl
break
elif [ "$perl_attempted" = 1 ]; then
printf ".. Perl could not be installed. Cannot continue\\n" >>"$log"
return 1
fi
# couldn't find Perl, so we need to try to install it
if [ -x /usr/bin/dnf ]; then
dnf -y install perl >>"$log" 2>&1
elif [ -x /usr/bin/yum ]; then
yum -y install perl >>"$log" 2>&1
elif [ -x /usr/bin/apt-get ]; then
apt-get update >>"$log" 2>&1
apt-get -q -y install perl >>"$log" 2>&1
fi
perl_attempted=1
# Loop. Next loop should either break or exit.
else
break
fi
done
printf ".. found Perl at $perl\\n" >>"$log"
return 0
}
pre_check_gpg() {
if [ -x /usr/bin/apt-get ]; then
printf "Checking for GPG .." >>"$log"
if [ ! -x /usr/bin/gpg ]; then
printf " not found, attempting to install .." >>"$log"
apt-get update >>/dev/null
apt-get -y -q install gnupg >>"$log"
printf " finished : $?\\n" >>"$log"
else
printf " found GPG command\\n" >>"$log"
fi
fi
}
pre_check_all() {
if [ -z "$setup_only" ]; then
# Check system time
run_ok pre_check_system_time "Checking system time"
# Make sure Perl is installed
run_ok pre_check_perl "Checking Perl installation"
# Update CA certificates package
run_ok pre_check_ca_certificates "Checking CA certificates package"
else
# Make sure Perl is installed
run_ok pre_check_perl "Checking Perl installation"
fi
# Checking for HTTP client
run_ok pre_check_http_client "Checking HTTP client"
# Check for gpg, debian 10 doesn't install by default!?
run_ok pre_check_gpg "Checking GPG package"
}
# download()
# Use $download to download the provided filename or exit with an error.
download() {
# XXX Check this to make sure run_ok is doing the right thing.
# Especially make sure failure gets logged right.
# awk magic prints the filename, rather than whole URL
export download_file
download_file=$(echo "$1" | awk -F/ '{print $NF}')
run_ok "$download $1" "$2"
if [ $? -ne 0 ]; then
fatal "Failed to download Virtualmin release package. Cannot continue. Check your network connection and DNS settings, and verify that your system's time is accurately synchronized."
else
return 0
fi
}
# Only root can run this
if [ "$(id -u)" -ne 0 ]; then
uname -a | grep -i CYGWIN >/dev/null
if [ "$?" != "0" ]; then
fatal "${RED}Fatal:${NORMAL} The Virtualmin install script must be run as root"
fi
fi