Repository navigation
Expand file tree
/
Copy pathwebvirtcloud.sh
More file actions
executable file
·830 lines (713 loc) · 24.5 KB
/
Copy pathwebvirtcloud.sh
File metadata and controls
executable file
·830 lines (713 loc) · 24.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
#!/bin/bash
#/ Usage: webvirtcloud.sh [-vh]
#/
#/ Install Webvirtcloud virtualization web interface.
#/
#/ OPTIONS:
#/ -v | --verbose Enable verbose output.
#/ -h | --help Show this message.
########################################################
# Webvirtcloud Install Script #
# Script created by Mike Tucker(mtucker6784@gmail.com) #
# adapted by catborise #
# catborise@gmail.com #
# #
# Feel free to modify, but please give #
# credit where it's due. Thanks! #
########################################################
# Parse arguments
while true; do
case "$1" in
-h|--help)
show_help=true
shift
;;
-v|--verbose)
set -x
verbose=true
shift
;;
-*)
echo "Error: invalid argument: '$1'" 1>&2
exit 1
;;
*)
break
;;
esac
done
print_usage () {
grep '^#/' <"$0" | cut -c 4-
exit 1
}
if [ -n "$show_help" ]; then
print_usage
else
for x in "$@"; do
if [ "$x" = "--help" ] || [ "$x" = "-h" ]; then
print_usage
fi
done
fi
# ensure running as root
if [ "$(id -u)" != "0" ]; then
#Debian doesnt have sudo if root has a password.
if ! hash sudo 2>/dev/null; then
exec su -c "$0" "$@"
else
exec sudo "$0" "$@"
fi
fi
clear
readonly APP_USER="wvcuser"
readonly APP_REPO_URL="${APP_REPO_URL:-https://github.com/retspen/webvirtcloud.git}"
readonly APP_NAME="webvirtcloud"
readonly APP_PATH="/srv/$APP_NAME"
PYTHON="python3"
progress () {
spin[0]="-"
spin[1]="\\"
spin[2]="|"
spin[3]="/"
echo -n " "
while kill -0 "$pid" > /dev/null 2>&1; do
for i in "${spin[@]}"; do
echo -ne "\\b$i"
sleep .3
done
done
echo ""
}
# shellcheck disable=SC2294
log () {
if [ -n "$verbose" ]; then
eval "$@" |& tee -a /var/log/webvirtcloud-install.log
else
eval "$@" |& tee -a /var/log/webvirtcloud-install.log >/dev/null 2>&1
fi
}
get_timezone () {
if [ -f /etc/timezone ]; then
cat /etc/timezone
elif command -v timedatectl >/dev/null 2>&1 && timedatectl 2>/dev/null | grep -q "Time zone"; then
timedatectl | grep "Time zone" | awk '{print $3}'
elif [ -L /etc/localtime ]; then
readlink /etc/localtime | sed -n 's#.*/zoneinfo/##p'
else
echo "UTC"
fi
}
install_packages () {
case $distro in
ubuntu|debian)
for p in $PACKAGES; do
if dpkg -s "$p" >/dev/null 2>&1; then
echo " * $p already installed"
else
echo " * Installing $p"
log "DEBIAN_FRONTEND=noninteractive apt-get install -y $p"
fi
done;
;;
centos)
for p in $PACKAGES; do
if yum list installed "$p" >/dev/null 2>&1; then
echo " * $p already installed"
else
echo " * Installing $p"
log "yum -y install $p"
fi
done;
;;
fedora|openEuler)
for p in $PACKAGES; do
if dnf list installed "$p" >/dev/null 2>&1; then
echo " * $p already installed"
else
echo " * Installing $p"
log "dnf -y install $p"
fi
done;
;;
uos)
if test "${codename}" == "eagle"; then
check_package_cmd=("dpkg" "-s")
install_package_cmd="apt-get install -y"
else
check_package_cmd=("dnf" "list" "installed")
install_package_cmd="dnf -y install"
fi
for p in $PACKAGES; do
# shellcheck disable=SC2048
if ${check_package_cmd[*]} "$p" >/dev/null 2>&1; then
echo " * $p already installed"
else
echo " * Installing $p"
log "${install_package_cmd} $p"
fi
done
;;
suse)
for p in $PACKAGES; do
if rpm -q "$p" >/dev/null 2>&1; then
echo " * $p already installed"
else
echo " * Installing $p"
log "zypper --non-interactive install -y $p"
fi
done
;;
esac
}
configure_nginx () {
# Remove default configuration
rm /etc/nginx/nginx.conf
if [ -f /etc/nginx/sites-enabled/default ]; then
rm /etc/nginx/sites-enabled/default
fi
chown -R "$nginx_group":"$nginx_group" /var/lib/nginx
# Copy new configuration and webvirtcloud.conf
echo " * Copying Nginx configuration"
local nginx_template_conf
nginx_template_conf="${APP_PATH}/conf/nginx/${distro}_${codename}_nginx.conf"
if ! test -f "${nginx_template_conf}"; then
nginx_template_conf="${APP_PATH}/conf/nginx/${distro}_nginx.conf"
fi
cp "${nginx_template_conf}" /etc/nginx/nginx.conf
cp "$APP_PATH"/conf/nginx/webvirtcloud.conf /etc/nginx/conf.d/
if [ -n "$fqdn" ]; then
fqdn_escape="$(echo -n "$fqdn"|sed -e 's/[](){}<>=:\!\?\+\|\/\&$*.^[]/\\&/g')"
sed -i "s|\\(#server_name\\).*|server_name $fqdn_escape;|" "$nginxfile"
fi
novncd_port_escape="$(echo -n "$novncd_port"|sed -e 's/[](){}<>=:\!\?\+\|\/\&$*.^[]/\\&/g')"
sed -i "s|server 127.0.0.1:6080;|server 127.0.0.1:$novncd_port_escape;|" "$nginxfile"
}
configure_supervisor () {
# Copy template supervisor service for gunicorn and novnc
echo " * Copying supervisor configuration"
mkdir -p "$supervisor_conf_path" > /dev/null 2>&1
cp "$APP_PATH"/conf/supervisor/webvirtcloud.conf "$supervisor_conf_path"/"$supervisor_file_name"
nginx_group_escape="$(echo -n "$nginx_group"|sed -e 's/[](){}<>=:\!\?\+\|\/\&$*.^[]/\\&/g')"
sed -i "s|^\\(user=\\).*|\\1$nginx_group_escape|" "$supervisor_conf_path/$supervisor_file_name"
}
create_user () {
echo "* Creating webvirtcloud user."
if [ "$distro" == "ubuntu" ] || [ "$distro" == "debian" ] ||
[[ "$distro" == "uos" && "$codename" == "eagle" ]]; then
adduser --quiet --disabled-password --gecos '""' "$APP_USER"
elif [ "$distro" == "suse" ]; then
useradd -m -s /bin/bash "$APP_USER" 2>/dev/null || adduser "$APP_USER"
else
useradd -m -s /bin/bash "$APP_USER" 2>/dev/null || adduser "$APP_USER"
fi
usermod -a -G "$nginx_group" "$APP_USER" 2>/dev/null || true
usermod -a -G libvirt "$nginx_group" 2>/dev/null || true
usermod -a -G kvm "$nginx_group" 2>/dev/null || true
usermod -a -G libvirt "$APP_USER" 2>/dev/null || true
usermod -a -G kvm "$APP_USER" 2>/dev/null || true
}
run_as_app_user () {
if ! hash sudo 2>/dev/null; then
su -c "$@" "$APP_USER"
else
sudo -i -u "$APP_USER" "$@"
fi
}
check_python () {
# dynamically find python >= 3.10 if default python3 is older
for py_bin in python3.11 python3.12 python3.13 python3.10 python3; do
if command -v "$py_bin" >/dev/null 2>&1; then
if "$py_bin" -c 'import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)' >/dev/null 2>&1; then
PYTHON="$py_bin"
break
fi
fi
done
# check if python3 is installed.
if ! hash "$PYTHON" 2>/dev/null; then
echo "Python3 is not installed. Please install Python3 and try again."
exit 1
fi
# check if python3 version is greater than 3.10
if ! "$PYTHON" -c 'import sys; assert sys.version_info >= (3, 10)' >/dev/null 2>&1; then
echo "Your Python version is less than 3.10. This script requires Python 3.10 or greater."
echo "Please install Python 3.10 or greater (such as python311) and try again."
exit 1
fi
}
activate_python_environment () {
cd "$APP_PATH" || exit
echo "* Creating virtual environment in $APP_PATH/venv"
if "$PYTHON" -m venv --help >/dev/null 2>&1; then
"$PYTHON" -m venv --system-site-packages venv
elif command -v virtualenv >/dev/null 2>&1; then
virtualenv -p "$PYTHON" --system-site-packages venv
else
echo "Neither python3 -m venv nor virtualenv is installed. Please install python3-venv or virtualenv."
exit 1
fi
# shellcheck disable=SC1091
source venv/bin/activate
}
generate_secret_key() {
"$PYTHON" -c 'import secrets; print(secrets.token_urlsafe(50))'
}
install_webvirtcloud () {
create_user
if [ ! -d "$APP_PATH/.git" ]; then
echo "* Cloning $APP_NAME from github to the web directory."
log "git clone $APP_REPO_URL $APP_PATH"
else
echo "* $APP_NAME already present in $APP_PATH."
fi
echo "* Configuring settings.py file."
cp "$APP_PATH/webvirtcloud/settings.py.template" "$APP_PATH/webvirtcloud/settings.py"
secret_key=$(generate_secret_key)
echo "* Secret for Django generated: $secret_key"
tzone_escape="$(echo -n "$tzone"|sed -e 's/[](){}<>=:\!\?\+\|\/\&$*.^[]/\\&/g')"
secret_key_escape="$(echo -n "$secret_key"|sed -e 's/[](){}<>=:\!\?\+\|\/\&$*.^[]/\\&/g')"
novncd_port_escape="$(echo -n "$novncd_port"|sed -e 's/[](){}<>=:\!\?\+\|\/\&$*.^[]/\\&/g')"
novncd_public_port_escape="$(echo -n "$novncd_public_port"|sed -e 's/[](){}<>=:\!\?\+\|\/\&$*.^[]/\\&/g')"
novncd_host_escape="$(echo -n "$novncd_host"|sed -e 's/[](){}<>=:\!\?\+\|\/\&$*.^[]/\\&/g')"
#TODO escape SED delimiter in variables
sed -i "s|^\\(TIME_ZONE = \\).*|\\1$tzone_escape|" "$APP_PATH/webvirtcloud/settings.py"
sed -i "s|^\\(SECRET_KEY = \\).*|\\1\'$secret_key_escape\'|" "$APP_PATH/webvirtcloud/settings.py"
sed -i "s|^\\(WS_PORT = \\).*|\\1$novncd_port_escape|" "$APP_PATH/webvirtcloud/settings.py"
sed -i "s|^\\(WS_PUBLIC_PORT = \\).*|\\1$novncd_public_port_escape|" "$APP_PATH/webvirtcloud/settings.py"
sed -i "s|^\\(WS_HOST = \\).*|\\1\'$novncd_host_escape\'|" "$APP_PATH/webvirtcloud/settings.py"
# set CSRF TRUSTED ORIGINS
host_ip="'http://127.0.0.1', "
if command -v hostname >/dev/null 2>&1; then
for i in $(hostname -I 2>/dev/null); do
host_ip+="'http://$i', "
done
fi
sed -i "s|^\\(CSRF_TRUSTED_ORIGINS = \\).*|\\1\[ \'http://$fqdn\', $host_ip ]|" "$APP_PATH/webvirtcloud/settings.py"
echo "* Checking up Python3 version."
check_python
echo "* Activate virtual environment."
activate_python_environment
echo "* Install App's Python requirements."
pip3 install -U pip
pip3 install -r conf/requirements.txt -q
chown -R "$nginx_group":"$nginx_group" "$APP_PATH"
echo "* Django Migrate."
log "$PYTHON $APP_PATH/manage.py migrate"
echo "* Django Collect Static"
log "$PYTHON $APP_PATH/manage.py collectstatic --noinput"
chown -R "$nginx_group":"$nginx_group" "$APP_PATH"
}
set_firewall () {
if test -n "$(command -v firewall-cmd)" && test "$(firewall-cmd --state)" == "running"; then
echo "* Configuring firewall to allow HTTP & novnc traffic."
log "firewall-cmd --zone=public --add-port=http/tcp --permanent"
log "firewall-cmd --zone=public --add-port=$novncd_port/tcp --permanent"
#firewall-cmd --zone=public --add-port=$novncd_port/tcp --permanent
log "firewall-cmd --zone=public --add-port=$novncd_public_port/tcp --permanent"
#firewall-cmd --zone=public --add-port=$novncd_public_port/tcp --permanent
log "firewall-cmd --reload"
#firewall-cmd --reload
fi
}
set_selinux () {
#Check if SELinux is enforcing
if [ "$(getenforce)" == "Enforcing" ]; then
echo "* Configuring SELinux."
#Sets SELinux context type so that scripts running in the web server process are allowed read/write access
chcon -R -h -t httpd_sys_rw_content_t "$APP_PATH/"
setsebool -P httpd_can_network_connect 1
fi
}
set_hosts () {
echo "* Setting up hosts file."
local hname
hname="$(hostname 2>/dev/null || uname -n)"
if ! grep -q "$fqdn" /etc/hosts 2>/dev/null; then
echo >> /etc/hosts "127.0.0.1 $hname $fqdn"
fi
}
restart_supervisor () {
echo "* Setting Supervisor to start on boot and restart."
log "systemctl enable $supervisor_service"
#systemctl enable $supervisor_service
log "systemctl restart $supervisor_service"
#systemctl restart $supervisor_service
}
restart_nginx () {
echo "* Setting Nginx to start on boot and starting Nginx."
log "systemctl enable nginx.service"
#systemctl enable nginx.service
log "systemctl restart nginx.service"
#systemctl restart nginx.service
}
if [ -f /etc/os-release ]; then
# shellcheck disable=SC1091
distro="$(source /etc/os-release && echo "$ID")"
# shellcheck disable=SC1091
version="$(source /etc/os-release && echo "$VERSION_ID")"
# shellcheck disable=SC1091
codename="$(source /etc/os-release && echo "${VERSION_CODENAME:-$UBUNTU_CODENAME}")"
# shellcheck disable=SC1091
id_like="$(source /etc/os-release && echo "${ID_LIKE:-}")"
elif [[ -f /etc/lsb-release || -f /etc/debian_version ]]; then
if command -v lsb_release >/dev/null 2>&1; then
distro="$(lsb_release -is)"
version="$(lsb_release -rs)"
codename="$(lsb_release -cs)"
elif [ -f /etc/debian_version ]; then
distro="debian"
version="$(cat /etc/debian_version)"
codename=""
fi
elif [ -f /etc/centos-release ]; then
distro="centos"
version="8"
elif [ -f /etc/SuSE-release ]; then
distro="suse"
version="15"
codename=""
id_like="suse"
else
distro="unsupported"
fi
echo '
WEBVIRTCLOUD
'
echo ""
echo " Welcome to Webvirtcloud Installer for RHEL Based OSes, Debian, Ubuntu, and SUSE!"
echo ""
shopt -s nocasematch
case $distro in
*ubuntu*)
echo " The installer has detected $distro version $version codename $codename."
distro=ubuntu
nginx_group=www-data
nginxfile=/etc/nginx/conf.d/$APP_NAME.conf
supervisor_service=supervisor
supervisor_conf_path=/etc/supervisor/conf.d
supervisor_file_name=webvirtcloud.conf
;;
*debian*)
echo " The installer has detected $distro version $version codename $codename."
distro=debian
nginx_group=www-data
nginxfile=/etc/nginx/conf.d/$APP_NAME.conf
supervisor_service=supervisor
supervisor_conf_path=/etc/supervisor/conf.d
supervisor_file_name=webvirtcloud.conf
;;
*centos*|*redhat*|*ol*|*rhel*|*rocky*|*Rocky*|*alma*)
echo " The installer has detected $distro version $version."
distro=centos
nginx_group=nginx
nginxfile=/etc/nginx/conf.d/$APP_NAME.conf
supervisor_service=supervisord
supervisor_conf_path=/etc/supervisord.d
supervisor_file_name=webvirtcloud.ini
;;
*opensuse*|*sles*|*sled*|*suse*)
echo " The installer has detected $distro version $version."
distro=suse
nginx_group=nginx
nginxfile=/etc/nginx/conf.d/$APP_NAME.conf
supervisor_service=supervisord
supervisor_conf_path=/etc/supervisord.d
supervisor_file_name=webvirtcloud.ini
;;
*Uos*|*uos*)
# codename may be fuyu, kongzi, eagle or empty string.
output_expand=""
if test -n "${codename}"; then
output_expand=" codename ${codename}"
fi
echo " The installer has detected $distro version $version${output_expand}."
distro=uos
nginxfile=/etc/nginx/conf.d/$APP_NAME.conf
if test "${codename}" == "eagle"; then
nginx_group=www-data
supervisor_service=supervisor
supervisor_conf_path=/etc/supervisor/conf.d
supervisor_file_name=webvirtcloud.conf
else
nginx_group=nginx
supervisor_service=supervisord
supervisor_conf_path=/etc/supervisord.d
supervisor_file_name=webvirtcloud.ini
fi
;;
*OpenEuler*|*openEuler*)
echo " The installer has detected $distro version $version."
distro=openEuler
nginx_group=nginx
nginxfile=/etc/nginx/conf.d/$APP_NAME.conf
supervisor_service=supervisord
supervisor_conf_path=/etc/supervisord.d
supervisor_file_name=webvirtcloud.ini
;;
*)
if [[ "$id_like" =~ suse ]]; then
echo " The installer has detected $distro (SUSE family) version $version."
distro=suse
nginx_group=nginx
nginxfile=/etc/nginx/conf.d/$APP_NAME.conf
supervisor_service=supervisord
supervisor_conf_path=/etc/supervisord.d
supervisor_file_name=webvirtcloud.ini
else
echo " The installer was unable to determine your OS. Exiting for safety."
exit 1
fi
;;
esac
fqdn="localhost"
setupfqdn=default
until [[ $setupfqdn == "yes" ]] || [[ $setupfqdn == "no" ]]; do
echo -n " Q. Do you want to configure fqdn for Nginx? (y/n) "
read -r setupfqdn
case $setupfqdn in
[yY] | [yY][Ee][Ss] )
fqdn=$(hostname --fqdn)
echo -n " Q. What is the FQDN of your server? ($fqdn): "
read -r fqdn_from_user
setupfqdn="yes"
if [ -n "$fqdn_from_user" ]; then
fqdn=$fqdn_from_user
fi
echo " Setting to $fqdn"
echo ""
;;
[nN] | [n|N][O|o] )
setupfqdn="no"
;;
*) echo " Invalid answer. Please type y or n"
;;
esac
done
echo -n " Q. NOVNC service port number?(Default: 6080) "
read -r novncd_port
if [ -z "$novncd_port" ]; then
readonly novncd_port=6080
fi
echo " Setting novnc service port $novncd_port"
echo ""
echo -n " Q. NOVNC public port number for reverse proxy(e.g: 80 or 443)?(Default: 6080) "
read -r novncd_public_port
if [ -z "$novncd_public_port" ]; then
readonly novncd_public_port=6080
fi
echo " Setting novnc public port $novncd_public_port"
echo ""
echo -n " Q. NOVNC host listen ip?(Default: 0.0.0.0) "
read -r novncd_host
if [ -z "$novncd_host" ]; then
readonly novncd_host="0.0.0.0"
fi
echo " Setting novnc host ip $novncd_host"
echo ""
echo "========="
echo "distro: ${distro}"
echo "========="
case $distro in
debian)
debian_major="${version%%.*}"
if [[ -n "$debian_major" && "$debian_major" -ge 9 ]]; then
# Install for Debian 9.x / 10.x / 11.x / 12.x
tzone=\'$(get_timezone)\'
echo -n "* Updating installed packages."
log "apt-get update && apt-get -y upgrade" & pid=$!
progress
echo "* Installing OS requirements."
PACKAGES="git python3-venv python3-virtualenv python3-pip python3-dev python3-lxml libvirt-dev zlib1g-dev libxslt1-dev libsasl2-dev libldap2-dev nginx supervisor smbios-utils libsasl2-modules gcc pkg-config python3-guestfs uuid"
install_packages
set_hosts
install_webvirtcloud
echo "* Configuring Nginx."
configure_nginx
echo "* Configuring Supervisor."
configure_supervisor
restart_supervisor
restart_nginx
else
echo "Unsupported Debian version. Version found: $version"
exit 1
fi
;;
ubuntu)
if [[ "$version" =~ ^(18|20|22|24) ]]; then
# Install for Ubuntu 18 / 20 / 22 / 24
tzone=\'$(get_timezone)\'
echo -n "* Updating installed packages."
log "apt-get update && apt-get -y upgrade" & pid=$!
progress
echo "* Installing OS requirements."
PACKAGES="git python3-venv python3-virtualenv python3-pip python3-dev python3-lxml libvirt-dev zlib1g-dev libxslt1-dev libsasl2-dev libldap2-dev nginx supervisor libsasl2-modules gcc pkg-config python3-guestfs"
install_packages
set_hosts
install_webvirtcloud
echo "* Configuring Nginx."
configure_nginx
echo "* Configuring Supervisor."
configure_supervisor
restart_supervisor
restart_nginx
else
echo "Unsupported Ubuntu version. Version found: $version"
exit 1
fi
;;
centos)
if [[ "$version" =~ ^10 ]]; then
# Install for CentOS/Redhat 10
tzone=\'$(timedatectl|grep "Time zone"| awk '{print $3}')\'
if command -v "crb" >/dev/null 2>&1; then
echo "* CRB Repo is found, enabling it."
log "crb enable > /dev/null 2>&1"
else
echo "* Enabling CRB repository."
log "dnf config-manager --set-enabled crb"
fi
echo "* Adding wget & epel-release & supervisor repository."
log "yum -y install wget epel-release supervisor"
echo "* Installing OS requirements."
PACKAGES="git python3-virtualenv python3-devel libvirt-devel python3-libvirt python3-ldap glibc gcc nginx python3-lxml python3-libguestfs iproute-tc cyrus-sasl-md5 openldap-devel cyrus-sasl-devel openssl-devel"
install_packages
set_hosts
echo "* Configuring virtualenv."
log "pip3 install virtualenv"
install_webvirtcloud
echo "* Configuring Nginx."
configure_nginx
echo "* Configuring Supervisor."
log "pip3 install supervisor "
configure_supervisor
set_firewall
set_selinux
restart_supervisor
restart_nginx
else
echo "Unsupported RHEL Based OS($distro) version. Version found: $version"
exit 1
fi
;;
uos)
if [[ "$version" == "20" ]]; then
# Install for uos 20
tzone=\'$(timedatectl|grep "Time zone"| awk '{print $3}')\'
echo "* Installing OS requirements."
if test "${codename}" == "eagle"; then
PACKAGES="git virtualenv python3-virtualenv python3-dev python3-lxml libvirt-dev zlib1g-dev libxslt1-dev nginx libsasl2-modules gcc pkg-config python3-guestfs uuid"
else
PACKAGES="git python3-virtualenv python3-devel python3-pip libvirt-devel glibc gcc nginx python3-lxml python3-libguestfs iproute-tc cyrus-sasl-md5"
fi
install_packages
set_hosts
install_webvirtcloud
echo "* Configuring Nginx."
configure_nginx
echo "* Configuring Supervisor."
log "pip install supervisor "
configure_supervisor
set_firewall
set_selinux
restart_supervisor
restart_nginx
fi
;;
openEuler)
if [[ "$version" == "20.03" ]]; then
# Install for openEuler 20.03
tzone=\'$(timedatectl|grep "Time zone"| awk '{print $3}')\'
echo "* Installing OS requirements."
PACKAGES="git python3-virtualenv python3-devel python3-pip libvirt-devel glibc gcc nginx python3-lxml python3-libguestfs iproute-tc cyrus-sasl-md5"
install_packages
set_hosts
install_webvirtcloud
echo "* Configuring Nginx."
configure_nginx
echo "* Configuring Supervisor."
log "pip install supervisor "
configure_supervisor
set_firewall
set_selinux
restart_supervisor
restart_nginx
fi
;;
suse)
# Install for openSUSE Leap 15.x / Tumbleweed / SLES 15
tzone=\'$(get_timezone)\'
echo -n "* Updating installed packages."
log "zypper --non-interactive refresh" & pid=$!
progress
echo "* Installing OS requirements."
# On SUSE, install Python 3.11 stack to satisfy Python >= 3.10 requirement along with native libvirt and ldap bindings
if zypper se -s python311-devel >/dev/null 2>&1; then
PACKAGES="git hostname python311 python311-base python311-devel python311-pip python311-libvirt-python python311-lxml python311-ldap libvirt-devel cyrus-sasl-devel libopenssl-devel gcc pkg-config nginx"
else
PACKAGES="git hostname python3-devel python3-pip python3-virtualenv libvirt-devel python3-libvirt python3-lxml openldap2-devel cyrus-sasl-devel libopenssl-devel gcc pkg-config nginx"
fi
install_packages
set_hosts
# Supervisor on SUSE (available as python3-supervisor, supervisor, or via pip)
if ! command -v supervisord >/dev/null 2>&1; then
if zypper --non-interactive install -y python3-supervisor >/dev/null 2>&1; then
echo " * python3-supervisor installed via zypper"
elif zypper --non-interactive install -y supervisor >/dev/null 2>&1; then
echo " * supervisor installed via zypper"
else
echo " * Installing supervisor via pip3"
log "pip3 install supervisor"
fi
fi
# Ensure /etc/supervisord.d directory exists and is included in supervisord.conf
mkdir -p /etc/supervisord.d
if [ ! -f /etc/supervisord.conf ] && [ ! -f /etc/supervisor/supervisord.conf ]; then
if command -v echo_supervisord_conf >/dev/null 2>&1; then
echo_supervisord_conf > /etc/supervisord.conf
echo -e "\n[include]\nfiles = /etc/supervisord.d/*.ini\n" >> /etc/supervisord.conf
fi
elif [ -f /etc/supervisord.conf ] && ! grep -q "/etc/supervisord.d" /etc/supervisord.conf; then
echo -e "\n[include]\nfiles = /etc/supervisord.d/*.ini\n" >> /etc/supervisord.conf
fi
# Ensure systemd service for supervisord exists if installed via pip
if [ ! -f /usr/lib/systemd/system/supervisord.service ] && [ ! -f /etc/systemd/system/supervisord.service ]; then
supervisord_bin="$(command -v supervisord 2>/dev/null || echo "/usr/local/bin/supervisord")"
supervisorctl_bin="$(command -v supervisorctl 2>/dev/null || echo "/usr/local/bin/supervisorctl")"
cat > /etc/systemd/system/supervisord.service <<SVCEOF
[Unit]
Description=Process Monitoring and Control Daemon
After=network.target
[Service]
Type=forking
ExecStart=${supervisord_bin} -c /etc/supervisord.conf
ExecStop=${supervisorctl_bin} shutdown
ExecReload=${supervisorctl_bin} reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
SVCEOF
systemctl daemon-reload >/dev/null 2>&1 || true
fi
install_webvirtcloud
echo "* Configuring Nginx."
configure_nginx
echo "* Configuring Supervisor."
configure_supervisor
set_firewall
restart_supervisor
restart_nginx
;;
esac
echo ""
echo " ***Open http://$fqdn to login to webvirtcloud.***"
echo ""
echo ""
echo "* Cleaning up..."
if [ ! -d .git ]; then
rm -f webvirtcloud.sh
rm -f install.sh
fi
echo "* Finished!"
sleep 1