-
Notifications
You must be signed in to change notification settings - Fork 192
/
xo-install.sh
executable file
·1621 lines (1372 loc) · 60.5 KB
/
xo-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/bash
# shellcheck disable=SC2155,SC2207,SC2015
#########################################################################
# Title: XenOrchestraInstallerUpdater #
# Author: Roni Väyrynen #
# Repository: https://github.com/ronivay/XenOrchestraInstallerUpdater #
#########################################################################
SCRIPT_DIR="$(dirname "$0")"
SAMPLE_CONFIG_FILE="$SCRIPT_DIR/sample.xo-install.cfg"
CONFIG_FILE="$SCRIPT_DIR/xo-install.cfg"
# Deploy default configuration file if the user doesn't have their own yet.
if [[ ! -s "$CONFIG_FILE" ]]; then
cp "$SAMPLE_CONFIG_FILE" "$CONFIG_FILE"
fi
# See this file for all script configuration variables.
# shellcheck disable=SC1090
source "$CONFIG_FILE"
# Set some default variables if sourcing config file fails for some reason
SELFUPGRADE=${SELFUPGRADE:-"true"}
PORT=${PORT:-80}
INSTALLDIR=${INSTALLDIR:-"/opt/xo"}
BRANCH=${BRANCH:-"master"}
INCLUDE_V6=${INCLUDE_V6:-"true"}
LOGPATH=${LOGPATH:-$(dirname "$(realpath "$0")")/logs}
AUTOUPDATE=${AUTOUPDATE:-"true"}
PRESERVE=${PRESERVE:-"3"}
XOUSER=${XOUSER:-"root"}
CONFIGPATH=$(getent passwd "$XOUSER" | cut -d: -f6)
CONFIGPATH_PROXY=$(getent passwd root | cut -d: -f6)
CONFIGUPDATE=${CONFIGUPDATE:-"true"}
PLUGINS="${PLUGINS:-"all"}"
ADDITIONAL_PLUGINS="${ADDITIONAL_PLUGINS:-"none"}"
REPOSITORY="${REPOSITORY:-"https://github.com/vatesfr/xen-orchestra"}"
OS_CHECK="${OS_CHECK:-"true"}"
ARCH_CHECK="${ARCH_CHECK:-"true"}"
PATH_TO_HTTPS_CERT="${PATH_TO_HTTPS_CERT:-""}"
PATH_TO_HTTPS_KEY="${PATH_TO_HTTPS_KEY:-""}"
PATH_TO_HOST_CA="${PATH_TO_HOST_CA:-""}"
AUTOCERT="${AUTOCERT:-"false"}"
ACME="${ACME:-"false"}"
ACME_EMAIL="${ACME_EMAIL:-""}"
ACME_CA="${ACME_CA:-"letsencrypt/production"}"
USESUDO="${USESUDO:-"false"}"
GENSUDO="${GENSUDO:-"false"}"
INSTALL_REPOS="${INSTALL_REPOS:-"true"}"
SYSLOG_TARGET="${SYSLOG_TARGET:-""}"
YARN_CACHE_CLEANUP="${YARN_CACHE_CLEANUP:-"false"}"
YARN_NETWORK_TIMEOUT="${YARN_NETWORK_TIMEOUT:-"300000"}"
# set variables not changeable in configfile
TIME=$(date +%Y%m%d%H%M)
LOGTIME=$(date "+%Y-%m-%d %H:%M:%S")
LOGFILE="${LOGPATH}/xo-install.log-$TIME"
NODEVERSION="20"
FORCE="false"
INTERACTIVE="false"
SUDOERSFILE="/etc/sudoers.d/xo-server-$XOUSER"
# Set path where new source is cloned/pulled
XO_SRC_DIR="$INSTALLDIR/xo-src/xen-orchestra"
# Set variables for stdout print
COLOR_N='\e[0m'
COLOR_GREEN='\e[1;32m'
COLOR_RED='\e[1;31m'
COLOR_BLUE='\e[1;34m'
COLOR_WHITE='\e[1;97m'
OK="[${COLOR_GREEN}ok${COLOR_N}]"
FAIL="[${COLOR_RED}fail${COLOR_N}]"
INFO="[${COLOR_BLUE}info${COLOR_N}]"
PROGRESS="[${COLOR_BLUE}..${COLOR_N}]"
# create logpath if doesn't exist
if [[ ! -d "$LOGPATH" ]]; then
mkdir -p "$LOGPATH"
fi
function CheckUser {
# Make sure the script is ran as root
if [[ ! $(runcmd_stdout "id -u") == "0" ]]; then
printfail "This script needs to be ran as root"
exit 1
fi
}
# script self upgrade
function SelfUpgrade {
set -o pipefail
if [[ "$SELFUPGRADE" != "true" ]]; then
return 0
fi
if [[ -d "$SCRIPT_DIR/.git" ]] && [[ -n $(runcmd_stdout "command -v git") ]]; then
local REMOTE="$(runcmd_stdout "cd $SCRIPT_DIR && git config --get remote.origin.url")"
if [[ "$REMOTE" == *"ronivay/XenOrchestraInstallerUpdater"* ]]; then
if [[ -n $(runcmd_stdout "cd $SCRIPT_DIR && git status --porcelain") ]]; then
printfail "Local changes in this script directory. Not attempting to self upgrade"
return 0
fi
runcmd "cd $SCRIPT_DIR && git fetch"
local OLD_SCRIPT_VERSION="$(runcmd_stdout "cd $SCRIPT_DIR && git rev-parse --short HEAD")"
local NEW_SCRIPT_VERSION="$(runcmd_stdout "cd $SCRIPT_DIR && git rev-parse --short FETCH_HEAD")"
if [[ $(runcmd_stdout "cd $SCRIPT_DIR && git diff --name-only @{upstream}| grep xo-install.sh") ]]; then
printinfo "Newer version of script available, attempting to self upgrade from '$OLD_SCRIPT_VERSION' to '$NEW_SCRIPT_VERSION'"
runcmd "cd $SCRIPT_DIR && git pull --ff-only" &&
{
printok "Self upgrade done"
exec "$SCRIPT_DIR/xo-install.sh" "$@"
} ||
printfail "Failed to self upgrade. Check $LOGFILE for more details. Continuing with current version"
fi
fi
fi
}
# log script version (git commit) and configuration variables to logfile
function ScriptInfo {
set -o pipefail
local SCRIPTVERSION=$(cd "$SCRIPT_DIR" 2>/dev/null && git rev-parse --short HEAD 2>/dev/null)
[ -z "$SCRIPTVERSION" ] && SCRIPTVERSION="undefined"
echo "Running script version $SCRIPTVERSION with config:" >>"$LOGFILE"
echo >>"$LOGFILE"
[ -s "$CONFIG_FILE" ] && grep -Eo '^[A-Z_]+.*' "$CONFIG_FILE" >>"$LOGFILE" || echo "No config file found" >>"$LOGFILE"
echo >>"$LOGFILE"
}
# log actual command and it's stderr/stdout to logfile in one go
function runcmd {
echo "+ $1" >>"$LOGFILE"
bash -c -o pipefail "$1" >>"$LOGFILE" 2>&1 || return 1
}
# log actual command and it's stderr to logfile in one go
function runcmd_stdout {
echo "+ $1" >>"$LOGFILE"
# shellcheck disable=SC2094
bash -c -o pipefail "$1" 2>>"$LOGFILE" | tee -a "$LOGFILE" || return 1
}
# make output we print pretty
function printprog {
echo -ne "${PROGRESS} $*"
}
function printok {
# shellcheck disable=SC1117
echo -e "\r${OK} $*"
}
function printfail {
echo -e "${FAIL} $*"
}
function printinfo {
echo -e "${INFO} $*"
}
# if script fails at a stage where installation is not complete, we don't want to keep the install specific directory and content
# this is called by trap inside different functions
function ErrorHandling {
echo
echo
printfail "Something went wrong, exiting. Check $LOGFILE for more details and use rollback feature if needed"
if [[ -d "$INSTALLDIR/xo-builds/xen-orchestra-$TIME" ]]; then
echo
printfail "Removing $INSTALLDIR/xo-builds/xen-orchestra-$TIME because of failed installation."
runcmd "rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
echo
fi
exit 1
}
# install package dependencies to rpm distros, based on: https://xen-orchestra.com/docs/from_the_sources.html
function InstallDependenciesRPM {
set -euo pipefail
trap ErrorHandling ERR INT
# Install necessary dependencies for XO build
# only install epel-release if doesn't exist and user allows it to be installed
if [[ -z $(runcmd_stdout "rpm -qa epel-release") ]] && [[ "$INSTALL_REPOS" == "true" ]]; then
echo
printprog "Installing epel-repo"
runcmd "dnf -y install epel-release"
printok "Installing epel-repo"
fi
# install packages
echo
printprog "Installing build dependencies, redis server, python3, git, nfs-utils, cifs-utils, lvm2, ntfs-3g, dmidecode patch"
runcmd "dnf -y install gcc gcc-c++ make openssl-devel redis libpng-devel python3 git nfs-utils cifs-utils lvm2 ntfs-3g dmidecode patch"
printok "Installing build dependencies, redis server, python3, git, nfs-utils, cifs-utils, lvm2, ntfs-3g, dmidecode patch"
# only run automated node install if executable not found
if [[ -z $(runcmd_stdout "command -v node") ]]; then
echo
printprog "Installing node.js"
# only install nodejs repo if user allows it to be installed
if [[ "$INSTALL_REPOS" == "true" ]]; then
runcmd "curl -s -L https://rpm.nodesource.com/setup_${NODEVERSION}.x | bash -"
fi
runcmd "dnf install -y nodejs"
printok "Installing node.js"
else
UpdateNodeYarn
fi
# only install yarn repo and package if not found
if [[ -z $(runcmd_stdout "command -v yarn") ]]; then
echo
printprog "Installing yarn"
# only install yarn repo if user allows it to be installed
if [[ "$INSTALL_REPOS" == "true" ]]; then
runcmd "curl -s -o /etc/yum.repos.d/yarn.repo https://dl.yarnpkg.com/rpm/yarn.repo"
fi
runcmd "dnf -y install yarn"
printok "Installing yarn"
fi
# Disabled for now due to forensics.cert.org going away
# only install libvhdi-tools if vhdimount is not present
# if [[ -z $(runcmd_stdout "command -v vhdimount") ]]; then
# echo
# printprog "Installing libvhdi-tools"
# if [[ "$INSTALL_REPOS" == "true" ]]; then
# runcmd "rpm -ivh https://forensics.cert.org/cert-forensics-tools-release-el${OSVERSION}.rpm"
# runcmd "sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/cert-forensics-tools.repo"
# runcmd "dnf --enablerepo=forensics install -y libvhdi-tools"
# else
# runcmd "dnf install -y libvhdi-tools"
# fi
# printok "Installing libvhdi-tools"
# fi
echo
printprog "Enabling and starting redis service"
runcmd "/bin/systemctl enable redis && /bin/systemctl start redis"
printok "Enabling and starting redis service"
echo
printprog "Enabling and starting rpcbind service"
runcmd "/bin/systemctl enable rpcbind && /bin/systemctl start rpcbind"
printok "Enabling and starting rpcbind service"
}
# install package dependencies to deb distros, based on: https://xen-orchestra.com/docs/from_the_sources.html
function InstallDependenciesDeb {
set -euo pipefail
trap ErrorHandling ERR INT
# Install necessary dependencies for XO build
if [[ "$OSNAME" == "Ubuntu" ]] && [[ "$INSTALL_REPOS" == "true" ]]; then
echo
printprog "OS Ubuntu so making sure universe repository is enabled"
runcmd "apt-get install -y software-properties-common"
runcmd "add-apt-repository -y universe"
printok "OS Ubuntu so making sure universe repository is enabled"
fi
echo
printprog "Running apt-get update"
runcmd "apt-get update"
printok "Running apt-get update"
# install packages
echo
printprog "Installing build dependencies, redis server, python3-minimal, git, libvhdi-utils, lvm2, nfs-common, cifs-utils, curl, ntfs-3g, dmidecode patch"
runcmd "apt-get install -y build-essential redis-server libpng-dev git libvhdi-utils python3-minimal lvm2 nfs-common cifs-utils curl ntfs-3g dmidecode patch"
printok "Installing build dependencies, redis server, python3-minimal, git, libvhdi-utils, lvm2, nfs-common, cifs-utils, curl, ntfs-3g, dmidecode patch"
# Install apt-transport-https and ca-certificates because of yarn https repo url
echo
printprog "Installing apt-transport-https and ca-certificates packages to support https repos"
runcmd "apt-get install -y apt-transport-https ca-certificates"
printok "Installing apt-transport-https and ca-certificates packages to support https repos"
if [[ "$OSNAME" == "Debian" ]] && [[ "$OSVERSION" =~ ^(10|11|12)$ ]]; then
echo
printprog "Debian 10/11/12, so installing gnupg also"
runcmd "apt-get install gnupg -y"
printok "Debian 10/11/12, so installing gnupg also"
fi
# install setcap for non-root port binding if missing
if [[ -z $(runcmd_stdout "command -v setcap") ]]; then
echo
printprog "Installing setcap"
runcmd "apt-get install -y libcap2-bin"
printok "Installing setcap"
fi
# only run automated node install if executable not found
if [[ -z $(runcmd_stdout "command -v node") ]] || [[ -z $(runcmd_stdout "command -v npm") ]]; then
echo
printprog "Installing node.js"
# only install nodejs repo if user allows it to be installed
if [[ "$INSTALL_REPOS" == "true" ]]; then
runcmd "curl -sL https://deb.nodesource.com/setup_${NODEVERSION}.x | bash -"
fi
runcmd "apt-get install -y nodejs"
printok "Installing node.js"
else
UpdateNodeYarn
fi
# only install yarn repo and package if not found
if [[ -z $(runcmd_stdout "command -v yarn") ]]; then
echo
printprog "Installing yarn"
# only install yarn repo if user allows it to be installed
if [[ "$INSTALL_REPOS" == "true" ]]; then
runcmd "curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -"
runcmd "echo \"deb https://dl.yarnpkg.com/debian/ stable main\" | tee /etc/apt/sources.list.d/yarn.list"
fi
runcmd "apt-get update"
runcmd "apt-get install -y yarn"
printok "Installing yarn"
fi
echo
printprog "Enabling and starting redis service"
runcmd "/bin/systemctl enable redis-server && /bin/systemctl start redis-server"
printok "Enabling and starting redis service"
echo
printprog "Enabling and starting rpcbind service"
runcmd "/bin/systemctl enable rpcbind && /bin/systemctl start rpcbind"
printok "Enabling and starting rpcbind service"
}
# keep node.js and yarn up to date
function UpdateNodeYarn {
set -euo pipefail
trap ErrorHandling ERR INT
# user has an option to disable this behaviour in xo-install.cfg
if [[ "$AUTOUPDATE" != "true" ]]; then
return 0
fi
echo
printinfo "Checking current node.js version"
local NODEV=$(runcmd_stdout "node -v 2>/dev/null| grep -Eo '[0-9.]+' | cut -d'.' -f1")
if [ "$PKG_FORMAT" == "rpm" ]; then
# update node version if needed.
# skip update if repository install is disabled as we can't quarantee this actually updates anything
if [[ "${NODEV:-0}" -lt "${NODEVERSION}" ]] && [[ "$INSTALL_REPOS" == "true" ]]; then
echo
printprog "node.js version is ${NODEV:-"not installed"}, upgrading to ${NODEVERSION}.x"
runcmd "curl -sL https://rpm.nodesource.com/setup_${NODEVERSION}.x | bash -"
runcmd "dnf clean all"
runcmd "dnf install -y nodejs"
printok "node.js version is ${NODEV:-"not installed"}, upgrading to ${NODEVERSION}.x"
else
if [[ -z "$NODEV" ]]; then
echo
printfail "node.js not installed and INSTALL_REPOS set to false, can't continue"
exit 1
fi
if [[ "$TASK" == "Update" ]]; then
echo
printprog "node.js version already on $NODEV, checking updates"
runcmd "dnf update -y nodejs yarn"
printok "node.js version already on $NODEV, checking updates"
elif [[ "$TASK" == "Installation" ]]; then
echo
printinfo "node.js version already on $NODEV"
fi
fi
fi
if [ "$PKG_FORMAT" == "deb" ]; then
if [[ "${NODEV:-0}" -lt "${NODEVERSION}" ]] && [[ "$INSTALL_REPOS" == "true" ]]; then
echo
printprog "node.js version is ${NODEV:-"not installed"}, upgrading to ${NODEVERSION}.x"
runcmd "curl -sL https://deb.nodesource.com/setup_${NODEVERSION}.x | bash -"
runcmd "apt-get install -y nodejs"
printok "node.js version is ${NODEV:-"not installed"}, upgrading to ${NODEVERSION}.x"
else
if [[ -z "$NODEV" ]]; then
echo
printfail "node.js not installed and INSTALL_REPOS set to false, can't continue"
exit 1
fi
if [[ "$TASK" == "Update" ]]; then
echo
printprog "node.js version already on $NODEV, checking updates"
runcmd "apt-get update"
runcmd "apt-get install -y --only-upgrade nodejs yarn"
printok "node.js version already on $NODEV, checking updates"
elif [[ "$TASK" == "Installation" ]]; then
echo
printinfo "node.js version already on $NODEV"
fi
fi
fi
}
# get source code for 3rd party plugins if any configured in xo-install.cfg
function InstallAdditionalXOPlugins {
set -euo pipefail
trap ErrorHandling ERR INT
if [[ -z "$ADDITIONAL_PLUGINS" ]] || [[ "$ADDITIONAL_PLUGINS" == "none" ]]; then
echo
printinfo "No 3rd party plugins to install"
return 0
fi
echo
printprog "Fetching 3rd party plugin(s) source code"
# shellcheck disable=SC1117
local ADDITIONAL_PLUGIN_REGEX="^https?:\/\/.*.git$"
local ADDITIONAL_PLUGIN
IFS=',' read -ra ADDITIONAL_PLUGIN <<<"$ADDITIONAL_PLUGINS"
for x in "${ADDITIONAL_PLUGIN[@]}"; do
if ! [[ $x =~ $ADDITIONAL_PLUGIN_REGEX ]]; then
echo
printfail "$x format is not correct for 3rd party plugin, skipping.."
continue
fi
local PLUGIN_NAME=$(runcmd_stdout "basename '$x' | rev | cut -c 5- | rev")
local PLUGIN_SRC_DIR=$(runcmd_stdout "realpath -m '$XO_SRC_DIR/../$PLUGIN_NAME'")
if [[ ! -d "$PLUGIN_SRC_DIR" ]]; then
runcmd "mkdir -p \"$PLUGIN_SRC_DIR\""
runcmd "git clone \"${x}\" \"$PLUGIN_SRC_DIR\""
else
runcmd "cd \"$PLUGIN_SRC_DIR\" && git pull --ff-only"
runcmd "cd $SCRIPT_DIR"
fi
runcmd "cp -r $PLUGIN_SRC_DIR $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/"
done
printok "Fetching 3rd party plugin(s) source code"
}
# symlink plugins in place based on what is set in xo-install.cfg
function InstallXOPlugins {
set -euo pipefail
trap ErrorHandling ERR INT
if [[ -z "$PLUGINS" ]] || [[ "$PLUGINS" == "none" ]]; then
echo
printinfo "No plugins to install"
return 0
fi
echo
printprog "Installing plugins"
if [[ "$PLUGINS" == "all" ]]; then
# shellcheck disable=SC1117
runcmd "find \"$INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/\" -maxdepth 1 -mindepth 1 -not -name \"xo-server\" -not -name \"xo-web\" -not -name \"xo-server-cloud\" -not -name \"xo-server-test*\" -exec ln -sn {} \"$INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/node_modules/\" \;"
else
local PLUGIN
IFS=',' read -ra PLUGIN <<<"$PLUGINS"
for x in "${PLUGIN[@]}"; do
if [[ $(runcmd_stdout "find $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages -type d -name '$x'") ]]; then
runcmd "ln -sn $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/$x $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/node_modules/"
fi
done
fi
printok "Installing plugins"
}
# install sudo package and generate config if defined in configuration
function InstallSudo {
set -euo pipefail
trap ErrorHandling ERR INT
if [[ -z $(runcmd_stdout "command -v sudo") ]]; then
if [[ "$PKG_FORMAT" == "deb" ]]; then
echo
printprog "Installing sudo"
runcmd "apt-get install -y sudo"
printok "Installing sudo"
elif [[ "$PKG_FORMAT" == "rpm" ]]; then
printprog "Installing sudo"
runcmd "dnf install -y sudo"
printok "Installing sudo"
fi
fi
if [[ "$GENSUDO" == "true" ]] && [[ ! -f "$SUDOERSFILE" ]]; then
echo
printinfo "Generating sudoers configuration to $SUDOERSFILE"
TMPSUDOERS="$(mktemp /tmp/xo-sudoers.XXXXXX)"
runcmd "echo '$XOUSER ALL=(root) NOPASSWD: /bin/mount, /bin/umount, /bin/findmnt' > '$TMPSUDOERS'"
if runcmd "visudo -cf $TMPSUDOERS"; then
runcmd "mv $TMPSUDOERS $SUDOERSFILE"
else
printfail "sudoers syntax check failed, not activating $SUDOERSFILE"
runcmd "rm -f $TMPSUDOERS"
fi
fi
}
function PrepInstall {
set -euo pipefail
trap ErrorHandling ERR INT
if [[ "$XO_SVC" == "xo-server" ]]; then
local XO_SVC_DESC="Xen Orchestra"
fi
if [[ "$XO_SVC" == "xo-proxy" ]]; then
local XO_SVC_DESC="Xen Orchestra Proxy"
fi
# Create installation directory if doesn't exist already
if [[ ! -d "$INSTALLDIR" ]]; then
echo
printinfo "Creating missing basedir to $INSTALLDIR"
runcmd "mkdir -p \"$INSTALLDIR\""
fi
# Create missing xo-builds directory if doesn't exist already
if [[ ! -d "$INSTALLDIR/xo-builds" ]]; then
echo
printinfo "Creating missing xo-builds directory to $INSTALLDIR/xo-builds"
runcmd "mkdir \"$INSTALLDIR/xo-builds\""
fi
echo
# keep the actual source code in one directory and either clone or git fetch depending on if directory exists already
printinfo "Fetching $XO_SVC_DESC source code"
if [[ ! -d "$XO_SRC_DIR" ]]; then
runcmd "mkdir -p \"$XO_SRC_DIR\""
runcmd "git clone \"${REPOSITORY}\" \"$XO_SRC_DIR\""
else
runcmd "cd \"$XO_SRC_DIR\" && git remote set-url origin \"${REPOSITORY}\" && \
git fetch --prune && \
git reset --hard origin/master && \
git clean -xdff"
fi
# Deploy the latest xen-orchestra source to the new install directory.
echo
printinfo "Creating install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
runcmd "rm -rf \"$INSTALLDIR/xo-builds/xen-orchestra-$TIME\""
runcmd "cp -r \"$XO_SRC_DIR\" \"$INSTALLDIR/xo-builds/xen-orchestra-$TIME\""
# checkout configured branch if not set as master
if [[ "$BRANCH" != "master" ]]; then
echo
printinfo "Checking out source code from branch/commit '$BRANCH'"
runcmd "cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME && git checkout $BRANCH"
runcmd "cd $SCRIPT_DIR"
fi
# Check if the new repo is any different from the currently-installed
# one. If not, then skip the build and delete the repo we just cloned.
# Get the commit ID of the to-be-installed xen-orchestra.
local NEW_REPO_HASH=$(runcmd_stdout "cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME && git rev-parse HEAD")
local NEW_REPO_HASH_SHORT=$(runcmd_stdout "cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME && git rev-parse --short HEAD")
runcmd "cd $SCRIPT_DIR"
# Get the commit ID of the currently-installed xen-orchestra (if one
# exists).
if [[ -L "$INSTALLDIR/$XO_SVC" ]] && [[ -n $(runcmd_stdout "readlink -e $INSTALLDIR/$XO_SVC") ]]; then
local OLD_REPO_HASH=$(runcmd_stdout "cd $INSTALLDIR/$XO_SVC && git rev-parse HEAD")
local OLD_REPO_HASH_SHORT=$(runcmd_stdout "cd $INSTALLDIR/$XO_SVC && git rev-parse --short HEAD")
runcmd "cd $SCRIPT_DIR"
else
# If there's no existing installation, then we definitely want
# to proceed with the bulid.
local OLD_REPO_HASH=""
local OLD_REPO_HASH_SHORT=""
fi
# If the new install is no different from the existing install, then don't
# proceed with the build.
if [[ "$NEW_REPO_HASH" == "$OLD_REPO_HASH" ]] && [[ "$FORCE" != "true" ]]; then
echo
# if any non interactive arguments used in script startup, we don't want to show any prompts
if [[ "$INTERACTIVE" == "true" ]]; then
printinfo "No changes to $XO_SVC_DESC since previous install. Run update anyway?"
read -r -p "[y/N]: " answer
case "$answer" in
y)
:
;;
*)
printinfo "Cleaning up install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
runcmd "rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
exit 0
;;
esac
else
printinfo "No changes to $XO_SVC_DESC since previous install. Skipping build. Use the --force to update anyway."
printinfo "Cleaning up install directory: $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
runcmd "rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
exit 0
fi
fi
# If this isn't a fresh install, then list the upgrade the user is making.
if [[ -n "$OLD_REPO_HASH" ]]; then
echo
if [[ "$FORCE" != "true" ]]; then
printinfo "Updating $XO_SVC_DESC from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'"
echo "Updating $XO_SVC_DESC from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'" >>"$LOGFILE"
else
printinfo "Updating $XO_SVC_DESC (forced) from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'"
echo "Updating $XO_SVC_DESC (forced) from '$OLD_REPO_HASH_SHORT' to '$NEW_REPO_HASH_SHORT'" >>"$LOGFILE"
fi
else
echo
printinfo "Installing $XO_SVC_DESC from branch: $BRANCH - commit: $NEW_REPO_HASH_SHORT"
echo "Installing $XO_SVC_DESC from branch: $BRANCH - commit: $NEW_REPO_HASH_SHORT" >>"$LOGFILE"
TASK="Installation"
fi
}
# run actual xen orchestra installation. procedure is the same for new installation and update. we always build it from scratch.
function InstallXO {
set -euo pipefail
trap ErrorHandling ERR INT
# Create user if doesn't exist (if defined)
if [[ "$XOUSER" != "root" ]]; then
if [[ -z $(runcmd_stdout "getent passwd $XOUSER") ]]; then
echo
printprog "Creating missing $XOUSER user"
runcmd "useradd -s /sbin/nologin $XOUSER -m"
printok "Creating missing $XOUSER user"
CONFIGPATH=$(getent passwd "$XOUSER" | cut -d: -f6)
fi
if [[ "$USESUDO" == "true" ]]; then
InstallSudo
fi
fi
PrepInstall
# Fetch 3rd party plugins source code
InstallAdditionalXOPlugins
echo
printinfo "xo-server and xo-web build takes quite a while. Grab a cup of coffee and lay back"
echo
printprog "Running installation"
runcmd "cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME && yarn --network-timeout ${YARN_NETWORK_TIMEOUT} && yarn --network-timeout ${YARN_NETWORK_TIMEOUT} build"
[ "$INCLUDE_V6" == "true" ] && runcmd "cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME && yarn --network-timeout ${YARN_NETWORK_TIMEOUT} run turbo run build --filter @xen-orchestra/web"
printok "Running installation"
# Install plugins (takes care of 3rd party plugins as well)
InstallXOPlugins
# shutdown possibly running xo-server
if [[ $(runcmd_stdout "pgrep -f '^([a-zA-Z0-9_\/-]+?)node.*xo-server'") ]]; then
echo
printprog "Shutting down running xo-server"
runcmd "/bin/systemctl stop xo-server" || {
printfail "failed to stop service, exiting..."
exit 1
}
printok "Shutting down running xo-server"
sleep 3
fi
echo
printinfo "Fixing binary path in systemd service configuration file"
# shellcheck disable=SC1117
runcmd "sed -i \"s#ExecStart=.*#ExecStart=$INSTALLDIR\/xo-server\/dist\/cli.mjs#\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service"
printinfo "Adding WorkingDirectory parameter to systemd service configuration file"
# shellcheck disable=SC1117
runcmd "sed -i \"/ExecStart=.*/a WorkingDirectory=$INSTALLDIR/xo-server\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service"
if [[ -n "$PATH_TO_HOST_CA" ]]; then
printinfo "Adding custom CA environment variable to systemd service configuration file"
runcmd "sed -i \"/Environment=.*/a Environment=NODE_EXTRA_CA_CERTS=$PATH_TO_HOST_CA\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service"
fi
# if service not running as root, we need to deal with the fact that port binding might not be allowed
if [[ "$XOUSER" != "root" ]]; then
printinfo "Adding user to systemd config"
# shellcheck disable=SC1117
runcmd "sed -i \"/SyslogIdentifier=.*/a User=$XOUSER\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service"
if [ "$PORT" -le "1024" ]; then
local NODEBINARY=$(runcmd_stdout "command -v node")
if [[ -L "$NODEBINARY" ]]; then
local NODEBINARY=$(runcmd_stdout "readlink -e $NODEBINARY")
fi
if [[ -n "$NODEBINARY" ]]; then
printprog "Attempting to set cap_net_bind_service permission for $NODEBINARY"
runcmd "setcap 'cap_net_bind_service=+ep' $NODEBINARY" && printok "Attempting to set cap_net_bind_service permission for $NODEBINARY" ||
{
printfail "Attempting to set cap_net_bind_service permission for $NODEBINARY"
echo " Non-privileged user might not be able to bind to <1024 port. xo-server won't start most likely"
}
else
printfail "Can't find node executable, or it's a symlink to non existing file. Not trying to setcap. xo-server won't start most likely"
fi
fi
fi
# fix to prevent older installations to not update because systemd service is not symlinked anymore
if [[ $(runcmd_stdout "find /etc/systemd/system -maxdepth 1 -type l -name 'xo-server.service'") ]]; then
runcmd "rm -f /etc/systemd/system/xo-server.service"
fi
printinfo "Replacing systemd service configuration file"
# always replace systemd service configuration if it changes in future updates
runcmd "/bin/cp -f $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/xo-server.service /etc/systemd/system/xo-server.service"
sleep 2
printinfo "Reloading systemd configuration"
runcmd "/bin/systemctl daemon-reload"
sleep 2
# if xen orchestra configuration file doesn't exist or configuration update is not disabled in xo-install.cfg, we create it
if [[ ! -f "$CONFIGPATH/.config/xo-server/config.toml" ]] || [[ "$CONFIGUPDATE" == "true" ]]; then
echo
printinfo "Fixing relative path to xo-web installation in xo-server configuration file"
# shellcheck disable=SC1117
runcmd "sed -i \"s%#'/any/url' = '/path/to/directory'%'/' = '$INSTALLDIR/xo-web/dist/'%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
printinfo "Changing redis connection address in xo-server configuration file"
runcmd "sed -i \"s%#uri = 'redis://redis.company.lan/42'%uri = 'redis://127.0.0.1:6379/0'%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
if [[ "$PORT" != "80" ]]; then
printinfo "Changing port in xo-server configuration file"
# shellcheck disable=SC1117
runcmd "sed -i \"s/port = 80/port = $PORT/\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
sleep 2
fi
if [[ "$HTTPS" == "true" ]]; then
printinfo "Enabling HTTPS in xo-server configuration file"
# shellcheck disable=SC1117
runcmd "sed -i \"s%# cert = '.\/certificate.pem'%cert = '$PATH_TO_HTTPS_CERT'%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
# shellcheck disable=SC1117
runcmd "sed -i \"s%# key = '.\/key.pem'%key = '$PATH_TO_HTTPS_KEY'%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
if [[ "$AUTOCERT" == "true" ]]; then
# shellcheck disable=SC1117
runcmd "sed -i \"s%# autoCert = false%autoCert = true%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
fi
if [[ "$ACME" == "true" ]]; then
runcmd "sed -i \"s%# \[\[http.listen\]\]%\[\[http.listen\]\]%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
runcmd "sed -i \"s%# port = 443%port = 443%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
runcmd "sed -i \"s%^# redirectToHttps = true%redirectToHttps = true%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
runcmd "sed -i \"/^autoCert =.*/a acmeCa = '$ACME_CA'\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
runcmd "sed -i \"/^autoCert = .*/a acmeDomain = '$ACME_DOMAIN'\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
if [[ -n "$ACME_EMAIL" ]]; then
runcmd "sed -i \"/^autoCert =.*/a acmeEmail = '$ACME_EMAIL'\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
fi
fi
sleep 2
fi
if [[ "$USESUDO" == "true" ]] && [[ "$XOUSER" != "root" ]]; then
printinfo "Enabling useSudo in xo-server configuration file"
runcmd "sed -i \"s/#useSudo = false/useSudo = true/\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
printinfo "Changing default mountsDir in xo-server configuration file"
runcmd "sed -i \"s%#mountsDir.*%mountsDir = '$INSTALLDIR/mounts'%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
runcmd "mkdir -p $INSTALLDIR/mounts"
runcmd "chown $XOUSER:$XOUSER $INSTALLDIR/mounts"
fi
if [[ -n "$SYSLOG_TARGET" ]]; then
printinfo "Enabling remote syslog in xo-server configuration file"
runcmd "sed -i \"s%#\[logs.transport.syslog\]%\[logs.transport.syslog\]%\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
runcmd "sed -i \"/^\[logs.transport.syslog.*/a target = '$SYSLOG_TARGET'\" $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml"
fi
printinfo "Activating modified configuration file"
if ! [[ -d $CONFIGPATH/.config ]]; then
# create generic .config directory only if it doesn't exist as we set permissions to it
# this directory could potentially exist already and we don't want to override anything
runcmd "install -o $XOUSER -g $XOUSER -m 770 -d $CONFIGPATH/.config"
fi
runcmd "mkdir -p $CONFIGPATH/.config/xo-server"
runcmd "mv -f $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server/sample.config.toml $CONFIGPATH/.config/xo-server/config.toml"
fi
echo
# install/update is the same procedure so always symlink to most recent installation
printinfo "Symlinking fresh xo-server install/update to $INSTALLDIR/xo-server"
runcmd "ln -sfn $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-server $INSTALLDIR/xo-server"
sleep 2
printinfo "Symlinking fresh xo-web install/update to $INSTALLDIR/xo-web"
runcmd "ln -sfn $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-web $INSTALLDIR/xo-web"
sleep 2
printinfo "Symlinking fresh xo-cli install/update to $INSTALLDIR/xo-cli"
runcmd "ln -sfn $INSTALLDIR/xo-builds/xen-orchestra-$TIME/packages/xo-cli $INSTALLDIR/xo-cli"
printinfo "Symlinking xo-cli script to /usr/local/bin/xo-cli"
runcmd "ln -sfn $INSTALLDIR/xo-cli/index.mjs /usr/local/bin/xo-cli"
# if not running as root, xen orchestra startup might not be able to create data directory so we create it here just in case
if [[ "$XOUSER" != "root" ]]; then
runcmd "chown -R $XOUSER:$XOUSER $INSTALLDIR/xo-builds/xen-orchestra-$TIME"
if [ ! -d /var/lib/xo-server ]; then
runcmd "mkdir /var/lib/xo-server"
fi
runcmd "chown -R $XOUSER:$XOUSER /var/lib/xo-server"
runcmd "chown -R $XOUSER:$XOUSER $CONFIGPATH/.config/xo-server"
fi
echo
printinfo "Starting xo-server..."
runcmd "/bin/systemctl start xo-server"
# no need to exit/trap on errors anymore
set +eo pipefail
trap - ERR INT
VerifyServiceStart
}
function VerifyServiceStart {
set -u
if [[ "$XO_SVC" == "xo-proxy" ]]; then
local PORT="443"
fi
PROXY_CONFIG_UPDATED=${PROXY_CONFIG_UPDATED:-"false"}
# loop service logs for 60 seconds and look for line that indicates service was started. we only care about lines generated after script was started (LOGTIME)
local count=0
local limit=6
# shellcheck disable=SC1117
local servicestatus="$(runcmd_stdout "journalctl --since '$LOGTIME' -u $XO_SVC | grep 'Web server listening on https\{0,1\}:\/\/.*:$PORT'")"
while [[ -z "$servicestatus" ]] && [[ "$count" -lt "$limit" ]]; do
echo " waiting for port to be open"
sleep 10
# shellcheck disable=SC1117
local servicestatus="$(runcmd_stdout "journalctl --since '$LOGTIME' -u $XO_SVC | grep 'Web server listening on https\{0,1\}:\/\/.*:$PORT'")"
((count++))
done
# if it looks like service started successfully based on logs..
if [[ -n "$servicestatus" ]]; then
echo
if [[ "$XO_SVC" == "xo-server" ]]; then
echo -e " ${COLOR_GREEN}WebUI started in port $PORT. Make sure you have firewall rules in place to allow access.${COLOR_N}"
# print username and password only when install was ran and skip while updating
if [[ "$TASK" == "Installation" ]]; then
echo -e " ${COLOR_GREEN}Default username: [email protected] password: admin${COLOR_N}"
fi
fi
if [[ "$XO_SVC" == "xo-proxy" ]]; then
echo -e " ${COLOR_GREEN}Proxy started in port $PORT. Make sure you have firewall rules in place to allow access from xen orchestra.${COLOR_N}"
# print json config only if config file was generated
if [[ "$PROXY_CONFIG_UPDATED" == "true" ]]; then
echo -e " ${COLOR_GREEN}Save following line as json file and use config import in Xen Orchestra to add proxy${COLOR_N}"
echo
echo "{\"proxies\":[{\"authenticationToken\":\"${PROXY_TOKEN}\",\"name\":\"${PROXY_NAME}\",\"vmUuid\":\"${PROXY_VM_UUID}\",\"id\":\"${PROXY_RANDOM_UUID}\"}]}"
fi
fi
echo
printinfo "$TASK successful. Enabling $XO_SVC service to start on reboot"
echo "" >>"$LOGFILE"
echo "$TASK succesful" >>"$LOGFILE"
runcmd "/bin/systemctl enable $XO_SVC"
echo
# if service startup failed...
else
echo
printfail "$TASK completed, but looks like there was a problem when starting $XO_SVC. Check $LOGFILE for more details"
# shellcheck disable=SC2129
echo "" >>"$LOGFILE"
echo "$TASK failed" >>"$LOGFILE"
echo "$XO_SVC service log:" >>"$LOGFILE"
echo "" >>"$LOGFILE"
runcmd "journalctl --since '$LOGTIME' -u $XO_SVC >> $LOGFILE"
echo
echo "Control $XO_SVC service with systemctl for stop/start/restart etc."
exit 1
fi
}
# run xen orchestra installation but also cleanup old installations based on value in xo-install.cfg
function UpdateXO {
if [[ "$XO_SVC" == "xo-server" ]]; then
InstallXO
fi
if [[ "$XO_SVC" == "xo-proxy" ]]; then
InstallXOProxy
fi
set -uo pipefail
if [[ "$PRESERVE" == "0" ]]; then
printinfo "PRESERVE variable is set to 0. This needs to be at least 1. Not doing a cleanup"
return 0
fi
# remove old builds. leave as many as defined in PRESERVE variable
printprog "Removing old inactive installations after update. Leaving $PRESERVE latest"
local INSTALLATIONS="$(runcmd_stdout "find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name \"xen-orchestra*\" -printf \"%T@ %p\\n\" | sort -n | cut -d' ' -f2- | head -n -$PRESERVE")"
local XO_SERVER_ACTIVE="$(runcmd_stdout "readlink -e $INSTALLDIR/xo-server")"
local XO_WEB_ACTIVE="$(runcmd_stdout "readlink -e $INSTALLDIR/xo-web")"
local XO_PROXY_ACTIVE="$(runcmd_stdout "readlink -e $INSTALLDIR/xo-proxy")"
for DELETABLE in $INSTALLATIONS; do
if [[ "$XO_SERVER_ACTIVE" != "${DELETABLE}"* ]] && [[ "$XO_WEB_ACTIVE" != "${DELETABLE}"* ]] && [[ "$XO_PROXY_ACTIVE" != "${DELETABLE}"* ]]; then
runcmd "rm -rf $DELETABLE"
fi
done
printok "Removing old inactive installations after update. Leaving $PRESERVE latest"
echo
# clear yarn cache if defined in configuration
if [[ "$YARN_CACHE_CLEANUP" == "true" ]]; then
printprog "Cleaning yarn cache"
runcmd "yarn cache clean"
printok "Cleaning yarn cache"
echo
fi
}
function InstallXOProxy {
set -euo pipefail
PrepInstall
echo
printinfo "xo-proxy build takes quite a while. Grab a cup of coffee and lay back"
echo
printprog "Running installation"
runcmd "cd $INSTALLDIR/xo-builds/xen-orchestra-$TIME && yarn --network-timeout ${YARN_NETWORK_TIMEOUT} && yarn --network-timeout ${YARN_NETWORK_TIMEOUT} build"
printok "Running installation"
# shutdown possibly running xo-server
if [[ $(runcmd_stdout "pgrep -f '^([a-zA-Z0-9_\/-]+?)node.*xo-proxy'") ]]; then
echo
printprog "Shutting down running xo-proxy"
runcmd "/bin/systemctl stop xo-proxy" || {