forked from proycon/LaMachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·1701 lines (1629 loc) · 80.9 KB
/
bootstrap.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
#======================================
# LaMachine v2
# by Maarten van Gompel
# Centre for Language Studies
# Radboud University Nijmegen
#
# https://proycon.github.io/LaMachine
# Licensed under GPLv3
#=====================================
export LC_ALL=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export ANSIBLE_FORCE_COLOR=true
bold=$(tput bold)
boldred=${bold}$(tput setaf 1) # red
boldgreen=${bold}$(tput setaf 2) # green
green=${normal}$(tput setaf 2) # green
yellow=${normal}$(tput setaf 3) # yellow
blue=${normal}$(tput setaf 4) # blue
boldblue=${bold}$(tput setaf 4) # blue
normal=$(tput sgr0)
export LM_VERSION="v2.9.1" #NOTE FOR DEVELOPER: also change version number in codemeta.json *AND* roles/lamachine-core/defaults/main.yml -> lamachine_version!
echo "${bold}=====================================================================${normal}"
echo " , ${bold}LaMachine $LM_VERSION${normal} - NLP Software distribution"
echo " ~) (http://proycon.github.io/LaMachine)"
echo " (----í Language Machines research group"
echo " /| |\ Centre of Language and Speech Technology"
echo " / / /| Radboud University Nijmegen "
echo "${bold}=====================================================================${normal}"
echo
usage () {
echo "bootstrap.sh [options]"
echo " ${bold}--flavour${normal} [vagrant|docker|local|global|remote] - Determines the type of LaMachine installation"
echo " vagrant = in a Virtual Machine"
echo " complete separation from the host OS"
echo " (uses Vagrant and VirtualBox)"
echo " docker = in a Docker container"
echo " (uses Docker and Ansible)"
echo " lxc = in an LXC container"
echo " (uses LXD, LXC and Ansible)"
echo " singularity = in a Singularity container (EXPERIMENTAL!)"
echo " (uses Singularity and Ansible)"
echo " local = in a local user environment"
echo " installs as much as possible in a separate directory"
echo " for a particular user, can exists alongside existing"
echo " installations, allows multiple parallel installations."
echo " (uses virtualenv)"
echo " global = Globally on this machine"
echo " modifies the existing system and may"
echo " interact with existing packages"
echo " can only be used once per machine"
echo " remote = On a remote server"
echo " modifies the existing remote system and"
echo " interacts with existing packages"
echo " can only be used once per remote machine"
echo " (uses ansible)"
echo " ${bold}--version${normal} [stable|development|custom] - Determines the version of software installed"
echo " stable = you get the latest releases deemed stable (recommended)"
echo " development = you get the very latest development versions for testing, this may not always work as expected!"
echo " custom = you decide explicitly what exact versions you want (for reproducibility)."
echo " this expects you to provide a LaMachine version file (customversions.yml) with exact version numbers."
echo " ${bold}--prebuilt${normal} - Download a pre-built image rather than building a new one from scratch (for Docker or Vagrant)"
echo " ${bold}--name${normal} - A name for your LaMachine installation, will be reflected in hostnames and directory names"
#echo " ${bold}--env${normal} [virtualenv] - Local user environment type"
#echo " virtualenv = A simple virtual environment"
echo " ${bold}--private${normal} - Do not transmit anonymous analytics on this LaMachine build"
echo " ${bold}--minimal${normal} - Attempt to install less than normal, leaving out extra options. This may break things."
echo " ${bold}--prefer_distro${normal} - Prefer distribution packages over other channels (such as pip). This generally installs more conserative versions, and less, but might break things."
echo " ${bold}--dockerrepo${normal} - Docker repository name (default: proycon/lamachine)"
echo " ${bold}--install${normal} - Provide an explicit comma separated list of LaMachine roles to install (instead of querying interactively or just taking the default)"
echo " ${bold}--vmmem${normal} - Memory to reserve for virtual machine"
echo " ${bold}--external${normal} - Use an external/shared/remote controller for updating LaMachine. This is useful for development/testing purposes and remote production environment"
echo " ${bold}--hostname${normal} - Hostname (or fully qualified domain name) for the target system"
echo " ${bold}--username${normal} - Username (or fully qualified domain name) for the target system"
echo " ${bold}--targetdir${normal} - Set a target directory for local environment creation, this should be an existing path and the local environment will be created under it. Defaults to current working directory."
echo " ${bold}--services${normal} - Preset enabled services (comma seperated list). Default: all"
echo " ${bold}--force${normal} - Preset a default force parameter (set to 1 or 2). Note that this will take effect on ANY subsequent update!"
echo " ${bold}--disksize${normal} - Sets extra disksize for VMs; you'll want to use this if you plan to include particularly large software and exceed the default 8GB"
}
USER_SET=0 #explicitly set?
USERNAME=$(whoami)
GROUP=$(id -gn $USERNAME)
HOSTNAME=""
fatalerror () {
echo "${bold}================ FATAL ERROR ==============${normal}" >&2
echo "An error occurred during installation!!" >&2
echo "${boldred}$1${normal}" >&2
echo "${bold}===========================================${normal}" >&2
echo "$1" > error
exit 2
}
#The base directory is the directory where the bootstrap is downloaded/executed
#It will be the default directory for data sharing, will host some configuration files
#and will contain a lamachine-controller environment
BASEDIR=$(pwd)
cd $BASEDIR
if [ -d .git ] && [ -e bootstrap.sh ]; then
#we are in a LaMachine git repository already
SOURCEDIR=$BASEDIR
fi
if [ ! -z "$LM_NAME" ]; then
fatalerror "Inception error: Do not run the LaMachine bootstrap from within an existing LaMachine! (deactivate first!)"
fi
if [ ! -z "$VIRTUAL_ENV" ]; then
fatalerror "Inception error: Do not run the LaMachine bootstrap from within an existing Python Virtual Environment! (deactivate first!)"
fi
if [ ! -z "$CONDA_PREFIX" ]; then
fatalerror "Inception error: Do not run the LaMachine bootstrap when you are inside an Anaconda environment (run 'source deactivate' first)"
fi
####################################################
# Platform Detection
####################################################
NEED=() #list of needed packages
if [ "${OSTYPE//[0-9.]/}" = "darwin" ]; then
OS="mac"
if which xcode-select; then
if xcode-select --install; then
echo "${bold}LaMachine requires the XCode Command Line Tools, please follow the instructions in the pop-up dialog and press ENTER here when that installation is completed${normal}"
read choice
fi
fi
else
OS="unknown"
fi
DISTRIB_ID="unknown"
DISTRIB_RELEASE="unknown"
if [ -e /etc/os-release ]; then
. /etc/os-release
DISTRIB_ID="$ID"
DISTRIB_RELEASE="$VERSION_ID"
elif [ -e /etc/lsb-release ]; then
. /etc/lsb-release
fi
DISTRIB_ID=$(echo "$DISTRIB_ID" | tr '[:upper:]' '[:lower:]')
if [ "$OS" = "unknown" ]; then
if [ "$DISTRIB_ID" = "arch" ] || [ "$DISTRIB_ID" = "debian" ] || [ "$DISTRIB_ID" = "redhat" ]; then #first class
OS=$DISTRIB_ID
elif [ "$DISTRIB_ID" = "ubuntu" ] || [ "$DISTRIB_ID" = "linuxmint" ]; then
OS="debian"
elif [ "$DISTRIB_ID" = "centos" ] || [ "$DISTRIB_ID" = "fedora" ] || [ "$DISTRIB_ID" = "rhel" ]; then
OS="redhat"
elif [ "$DISTRIB_ID" = "manjaro" ]; then
OS="arch"
fi
fi
if grep -q Microsoft /proc/version 2> /dev/null; then
echo "(Windows Linux Subsystem detected)">&2
WINDOWS=1 #we are running in the Windows Linux Subsystem
else
WINDOWS=0
fi
if [ "$OS" = "unknown" ]; then
echo "(Fallback: Detecting OS by finding installed package manager...)">&2
ARCH=$(which pacman 2> /dev/null)
DEBIAN=$(which apt-get 2> /dev/null)
REDHAT=$(which yum 2> /dev/null)
if [ -e "$ARCH" ]; then
OS='arch'
elif [ -e "$DEBIAN" ]; then
OS='debian' #ubuntu too
elif [ -e "$REDHAT" ]; then
OS='redhat'
else
echo "Unable to detect a supported OS! Perhaps your distribution is not yet supported by LaMachine? Please contact us!">&2
exit 2
fi
fi
SERVICES="all"
VERSION="undefined" # we set this because it might have been overriden by the distro
INTERACTIVE=1
LOCALITY=""
PRIVATE=0
ANSIBLE_OPTIONS="-v"
MINIMAL=0
FORCE=0
PREFER_DISTRO=0
NOSYSUPDATE=0
VMMEM=4096
DISKSIZE=0 #for extra disk in VM (in GB)
VAGRANTBOX="debian/contrib-stretch64" #base distribution for VM
DOCKERREPO="proycon/lamachine"
CONTROLLER="internal"
BUILD=1
if which python; then
echo "Checking sanity of your Python installation..."
python -c "from __future__ import print_function; import sys; print(sys.version)" | grep -i anaconda
if [ $? -eq 0 ]; then
fatalerror "Conflict error: The default Python on this system is managed by Anaconda, this is incompatible with LaMachine. Ensure the Python found in your \$PATH corresponds to a regular version as supplied with your OS, editing the order of your \$PATH in ~/.bashrc or ~/.bash_profile should be sufficient to solve this without completely uninstalling anaconda. See also https://stackoverflow.com/a/37377981/3311445"
fi
else
if [ "$OS" != "debian" ]; then #newest ubuntu/debian doesn't always install python2.7 but apt will handle the dependency later
fatalerror "No Python found! However, python should be available by default on all supported platforms; please install it yourself through your package manager (and ensure it is in your \$PATH)"
fi
fi
echo ""
echo "Detected OS: $OS"
echo "Detected distribution ID: $DISTRIB_ID"
echo "Detected distribution release: $DISTRIB_RELEASE"
echo
#Test if we come from LaMachine v1 VM/Docker
if [ "$OS" = "arch" ] && [ -e /usr/src/LaMachine ]; then
echo "${boldred}Automated upgrade from LaMachine v1 not possible${normal}"
echo "A new major LaMachine version (v2) has been released in early 2018."
echo "You are currently on the older v1. Due to many changes a direct upgrade path was not feasible."
echo "It is easier to simply build a new LaMachine Virtual Machine or Docker Container."
echo "We recommend you remove this VM or container and "
echo "obtain the latest version by following the instructions on"
echo "the LaMachine website at https://proycon.github.io/LaMachine ."
exit 6
fi
if [[ "$USERNAME" == "root" ]]; then
fatalerror "Do not run the LaMachine bootstrap process as root!" #we can't do this message earlier because people coming from LaMachine v1 do run as root sometimes
fi
OUTDATED=0
if [ "$OS" != "mac" ]; then
if [ "$DISTRIB_ID" = "ubuntu" ]; then
if [ "${DISTRIB_RELEASE%\.*}" -lt 16 ]; then
echo "WARNING: Your Ubuntu distribution is out of date and not supported, we recommend an upgrade to the latest LTS release!"
OUTDATED=1
fi
elif [ "$DISTRIB_ID" = "debian" ]; then
if [ "${DISTRIB_RELEASE%\.*}" -lt 9 ]; then
echo "WARNING: Your Debian distribution is out of date and not supported, we recommend an upgrade to the latest stable release!"
OUTDATED=1
fi
elif [ "$DISTRIB_ID" = "linuxmint" ]; then
if [ "${DISTRIB_RELEASE%\.*}" -lt 18 ]; then # https://www.linuxmint.com/download_all.php
echo "WARNING: Your Linux Mint distribution is out of date and not supported, we recommend an upgrade to the latest LTS release!"
OUTDATED=1
fi
elif [ "$DISTRIB_ID" = "centos" ] || [ "$DISTRIB_ID" = "rhel" ]; then
if [ "${DISTRIB_RELEASE%\.*}" -lt 7 ]; then
echo "WARNING: Your CentOS/RHEL distribution is out of date and not supported, we recommend an upgrade to the latest release!"
OUTDATED=1
fi
elif [ "$DISTRIB_ID" = "fedora" ]; then
if [ "${DISTRIB_RELEASE%\.*}" -lt 29 ]; then # https://en.wikipedia.org/wiki/Fedora_version_history
echo "WARNING: Your Fedora Linux distribution is out of date and not supported, we recommend an upgrade to the latest release!"
OUTDATED=1
fi
elif [ "$DISTRIB_ID" = "arch" ] || [ "$DISTRIB_ID" = "manjaro" ]; then
echo "Rolling release, okay"
else
echo "WARNING: Your Linux distribution was not properly recognized and may be unsupported!"
OUTDATED=1
fi
if [ $OUTDATED -eq 1 ] && [ $INTERACTIVE -eq 1 ]; then
echo "Running an older or unsupported Linux distribution usually prevents you from doing a successful local or global installation."
echo "You *might*, however, still be able to do a proper VM or Docker installation."
echo -n "${bold}Try to continue anyway?${normal} [yn] "
read yn
case $yn in
[Yy]* ) break;;
* ) exit 1; break;;
esac
fi
fi
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-n|--name)
LM_NAME="$2"
shift # past argument
shift # past value
;;
-c|--config)
STAGEDCONFIG="$2"
shift # past argument
shift # past value
;;
-f|--flavour|--flavor)
FLAVOUR="$2"
shift # past argument
shift # past value
;;
-v|--version) #stable or development
VERSION="$2"
shift # past argument
shift # past value
;;
-b|--branch) #branch of LaMachine git
BRANCH="$2"
shift # past argument
shift # past value
;;
--gitrepo) #git repository of LaMachine
GITREPO="$2"
shift # past argument
shift # past value
;;
--env) #conda or virtualenv
LOCALENV_TYPE="$2"
shift # past argument
shift # past value
;;
--source) #LaMachine source path
BASEDIR="$2"
SOURCEDIR="$2"
shift # past argument
shift # past value
;;
--noroot|--noadmin) #Script mode
LOCALITY=local
SUDO=0
shift
;;
--vagrantbox) #LaMachine source path
VAGRANTBOX="$2"
shift # past argument
shift # past value
;;
--dockerrepo) #Docker repo (proycon/lamachine)
DOCKERREPO="$2"
shift # past argument
shift # past value
;;
--install)
INSTALL="$2"
shift # past argument
shift # past value
;;
-B|--prebuilt)
BUILD=0
shift
;;
--noninteractive) #Script mode
INTERACTIVE=0
shift
;;
--private) #private, do not send LaMachine build analytics
PRIVATE=1
shift
;;
--minimal)
MINIMAL=1
shift
;;
--external)
CONTROLLER="external"
shift
;;
--prefer-distro)
PREFER_DISTRO=1
shift
;;
--extra) #extra ansible parameters
ANSIBLE_OPTIONS="$ANSIBLE_OPTIONS --extra-vars $2"
shift
shift
;;
--hostname)
HOSTNAME="$2"
shift
shift
;;
--username)
USER_SET=1
USERNAME="$2"
shift
shift
;;
--targetdir)
TARGETDIR="$2"
shift
shift
;;
--force)
FORCE="$2"
shift
shift
;;
--nosysupdate)
NOSYSUPDATE=1
shift
;;
--services)
SERVICES="$2"
shift
shift
;;
--disksize)
DISKSIZE="$2"
shift
shift
;;
--vmmem) #extra ansible parameters
VMMEM=$2
shift
shift
;;
--quiet)
ANSIBLE_OPTIONS=""
shift
;;
--verbose)
ANSIBLE_OPTIONS="-vv"
shift
;;
-h|--help)
usage
exit 0
shift
;;
*) # unknown option
echo "Unknown option: $1">&2
exit 2
;;
esac
done
if [ $INTERACTIVE -eq 1 ]; then
echo
echo "Welcome to the LaMachine Installation tool, we will ask some questions how"
echo "you want your LaMachine to be installed and guide you towards the installation"
echo "of any software that is needed to complete this installation."
echo
fi
if [ -z "$FLAVOUR" ]; then
while true; do
echo "${bold}Where do you want to install LaMachine?${normal}"
echo " 1) in a local user environment"
echo " installs as much as possible in a separate directory"
echo " for a particular user; can exists alongside existing"
echo " installations. May also be used (limited) by multiple"
echo " users/groups if file permissions allow it. Can work without"
echo " root but only if all global dependencies are already satisfied."
echo " (uses virtualenv)"
if [ $WINDOWS -eq 0 ]; then
echo " 2) in a Virtual Machine"
echo " complete separation from the host OS"
echo " (uses Vagrant and VirtualBox)"
echo " 3) in a Docker container"
echo " (uses Docker and Ansible)"
fi
echo " 4) Globally on this machine"
echo " dedicates the entire machine to LaMachine and"
echo " modifies the existing system and may"
echo " interact with existing packages. Usually requires root."
echo " 5) On a remote server"
echo " modifies an existing remote system! Usually requires root."
echo " (uses ansible)"
if [ $WINDOWS -eq 0 ]; then
echo " 6) in an LXC/LXD container"
echo " Provides a more persistent and VM-like container experience than Docker"
echo " (uses LXD, LXC and Ansible)"
echo " 7) in a Singularity container (EXPERIMENTAL!)"
echo " (uses Singularity and Ansible)"
fi
echo -n "${bold}Your choice?${normal} [12345] "
read choice
case $choice in
[1]* ) FLAVOUR="local"; break;;
[2]* ) FLAVOUR="vagrant"; break;;
[3]* ) FLAVOUR="docker"; break;;
[4]* ) FLAVOUR="global"; break;;
[5]* ) FLAVOUR="remote"; break;;
[6]* ) FLAVOUR="lxc"; break;;
[7]* ) FLAVOUR="singularity"; break;;
* ) echo "Please answer with the corresponding number of your preference..";;
esac
done
fi
if [[ "$FLAVOUR" == "vm" ]]; then #alias
FLAVOUR="vagrant"
elif [[ "$FLAVOUR" == "remote" ]]; then #alias
CONTROLLER="external"
fi
if [[ $INTERACTIVE -eq 1 ]] && [[ $WINDOWS -eq 0 ]]; then
if [[ "$FLAVOUR" == "vagrant" || "$FLAVOUR" == "docker" || "$FLAVOUR" == "singularity" ]]; then
while true; do
echo "${bold}Do you want to build a new personalised LaMachine image or use and download a prebuilt one?${normal}"
echo " 1) Build a new image"
echo " Offers most flexibility and ensures you are on the latest versions."
echo " Allows you to choose even for development versions or custom versions."
echo " Allows you to choose what software to include from scratch."
echo " Best integration with your custom data."
echo " 2) Download a prebuilt one"
echo " Comes with a fixed selection of software, allows you to update with extra software later."
echo " Fast & easy but less flexible"
echo -n "${bold}Your choice?${normal} [12] "
read choice
case $choice in
[1]* ) break;;
[2]* ) BUILD=0; break;;
* ) echo "Please answer with the corresponding number of your preference..";;
esac
done
if [[ "$FLAVOUR" == "vagrant" ]] && [ $BUILD -eq 1 ] && [ $DISKSIZE -eq 0 ]; then
echo "${bold}Allocate extra diskspace?${normal}"
echo " The standard LaMachine disk is limited in size (about 9GB). If you plan to include certain very large software"
echo " collections that LaMachine offers (such as kaldi, valkuil) then this is not sufficient and"
echo " you need to allocate an extra virtual disk, specify the size below:"
echo " Just enter 0 if you do not need this; you don't need this for the default selection of software."
echo -n "${bold}How much extra diskspace to reserve?${normal} [0 or size in GB] "
while true; do
read choice
case $choice in
[0-9]* ) DISKSIZE=$choice; break;;
* ) echo "Please answer with the corresponding size in GB (use 0 if you don't need an extra disk)";;
esac
done
elif [[ "$FLAVOUR" == "docker" ]] && [ $BUILD -eq 1 ] && [ $DISKSIZE -eq 0 ]; then
echo "${bold}Container diskspace${normal}"
echo " A standard docker container is limited in size (usually 10GB). If you plan to include certain very large optional software"
echo " collections that LaMachine offers (such as kaldi, valkuil) then this is not sufficient and"
echo " you need to increase the base size of your containers (depending on the storage driver you use for docker)."
echo " Consult the docker documentation at https://docs.docker.com/storage/storagedriver/ and do so now if you need this."
echo " You don't need this for the default selection of software."
echo -n "${bold}Press ENTER when ready to continue${normal}"
read choice
fi
fi
fi
if [ -z "$LOCALITY" ]; then
if [[ "$FLAVOUR" == "local" ]]; then
LOCALITY="local"
else
LOCALITY="global"
fi
fi
if [[ "$LOCALITY" == "local" ]]; then
if [ -z "$LOCALENV_TYPE" ]; then
LOCALENV_TYPE="virtualenv"
#echo "${bold}We support two forms of local user environments:${normal}"
#echo " 1) Using virtualenv"
#echo " (originally for Python but extended by us)"
#echo " 2) Using conda"
#echo " provided by the Anaconda Distribution, a powerful data science platform (mostly for Python and R)"
#while true; do
# echo -n "${bold}What form of local user environment do you want?${normal} [12] "
# read choice
# case $choice in
# [1]* ) LOCALENV_TYPE=virtualenv; break;;
# [2]* ) LOCALENV_TYPE=conda; break;;
# * ) echo "Please answer with the corresponding number of your preference..";;
# esac
#done
fi
if [ $INTERACTIVE -ne 0 ]; then
echo "${bold}Where do you want to create the local user environment?${normal}"
echo " By default, a new directory will be created *under* your current location, which is $(pwd)"
echo " If this is what you want, just press ENTER, "
echo " Otherwise, type a new existing path: "
echo -n "${bold}Where do you want to create the local user environment?${normal} [press ENTER for $(pwd)] "
read TARGETDIR
if [ ! -z "$TARGETDIR" ]; then
mkdir -p $TARGETDIR >/dev/null 2>/dev/null
cd $TARGETDIR || fatalerror "Specified target directory does not exist"
BASEDIR="$TARGETDIR"
fi
elif [ ! -z "$TARGETDIR" ]; then
cd $TARGETDIR || fatalerror "Specified target directory does not exist"
BASEDIR="$TARGETDIR"
fi
fi
touch x || fatalerror "Directory $(pwd) is not writable for the current user! Run the bootstrap somewhere where you can write!"
rm x
if [ -z "$LOCALENV_TYPE" ]; then
LOCALENV_TYPE="virtualenv"
fi
if [ $BUILD -eq 1 ]; then
if [[ "$VERSION" == "undefined" ]]; then
echo "${bold}LaMachine comes in several versions:${normal}"
echo " 1) a stable version; you get the latest releases deemed stable (recommended)"
echo " 2) a development version; you get the very latest development versions for testing, this may not always work as expected!"
echo " 3) custom version; you decide explicitly what exact versions you want (for reproducibility);"
echo " this expects you to provide a LaMachine version file (customversions.yml) with exact version numbers."
if [[ "$OS" == "mac" ]]; then
echo " NOTE: CUSTOM VERSIONING IS NOT SUPPORTED ON MAC OS X!"
fi
while true; do
echo -n "${bold}Which version do you want to install?${normal} [123] "
read choice
case $choice in
[1]* ) VERSION=stable; break;;
[2]* ) VERSION=development; break;;
[3]* ) VERSION=custom; break;;
* ) echo "Please answer with the corresponding number of your preference..";;
esac
done
fi
fi
if [ -z "$BRANCH" ]; then
if [[ "$VERSION" == "development" ]]; then
BRANCH="master"
else
BRANCH="master"
fi
fi
if [ -z "$GITREPO" ]; then
GITREPO="https://github.com/proycon/LaMachine"
fi
if [ -z "$SUDO" ]; then
if [ $INTERACTIVE -eq 0 ]; then
SUDO=1 #assume root (use --noadmin option otherwise)
else
while true; do
echo
echo "The installation relies on certain software to be available on your (host)"
echo "system. It will be automatically obtained from your distribution's package manager"
echo "or another official source whenever possible. You need to have sudo permission for this though..."
echo "${red}Answering 'no' to this question may make installation on your system impossible!${normal}"
echo
echo -n "${bold}Do you have administrative access (root/sudo) on the current system?${normal} [yn] "
read yn
case $yn in
[Yy]* ) SUDO=1; break;;
[Nn]* ) SUDO=0; break;;
* ) echo "Please answer yes or no.";;
esac
done
fi
fi
echo "Looking for dependencies..."
if [ $BUILD -eq 0 ]; then
NEED_VIRTUALENV=0 #Do we need a virtualenv with ansible for the controller? Never needed if we are not building ourselves
else
if ! which git; then
NEED+=("git")
fi
if [ "$FLAVOUR" = "docker" ] || [ "$FLAVOUR" = "singularity" ] || [ "$FLAVOUR" = "lxc" ]; then
NEED_VIRTUALENV=0 #Do we need a virtualenv with ansible for the controller? Never for containers, all ansible magic happens inside the container
else
NEED_VIRTUALENV=1 #Do we need a virtualenv with ansible for the controller? (this is a default we will attempt to falsify)
if which ansible-playbook; then
NEED_VIRTUALENV=0
elif [ $SUDO -eq 1 ]; then #we can only install ansible globally if we have root
if [ "$OS" != "mac" ]; then #pip is preferred on mac
if [ "$DISTRIB_ID" = "centos" ] || [ "$DISTRIB_ID" = "rhel" ]; then
NEED+=("epel") #ansible is in EPEL
fi
NEED+=("ansible")
NEED_VIRTUALENV=0
fi
fi
if [ $NEED_VIRTUALENV -eq 1 ]; then
if ! which pip; then
if [ "$DISTRIB_ID" = "centos" ] || [ "$DISTRIB_ID" = "rhel" ]; then
NEED+=("epel") #python-pip is in EPEL
fi
NEED+=("pip")
fi
if ! which virtualenv; then
NEED+=("virtualenv")
fi
fi
fi
fi
if [ -z "$EDITOR" ]; then
if which nano; then
EDITOR=nano
else
EDITOR=vi
fi
fi
if [[ "$OS" == "mac" ]]; then
if ! which brew; then
NEED+=("brew")
fi
NEED+=("brew-cask")
fi
if [ ! -z "$NEED" ]; then
echo " Missing dependencies: ${NEED[@]}"
fi
if [ "$FLAVOUR" == "vagrant" ]; then
echo "Looking for vagrant..."
if ! which vagrant; then
NEED+=("vagrant")
NEED+=("vbguest")
#NEED+=("vagrant-disksize")
else
echo "Checking available vagrant plugins"
if vagrant plugin list | grep vbguest; then
echo "ok"
else
NEED+=("vbguest")
fi
#if vagrant plugin list | grep disksize; then
# echo "ok"
#else
# NEED+=("vagrant-disksize")
#fi
fi
fi
if [ "$FLAVOUR" == "docker" ]; then
echo "Looking for docker..."
if ! which docker; then
if ! which docker.io; then
NEED+=("docker")
fi
fi
fi
if [ "$FLAVOUR" == "lxc" ]; then
echo "Looking for LXD..."
if ! which lxc; then #not a typo
NEED+=("lxd")
fi
fi
if [ "$FLAVOUR" == "singularity" ]; then
echo "Looking for singularity..."
if ! which singularity; then
NEED+=("singularity")
fi
if ! which debootstrap; then
NEED+=("debootstrap")
fi
fi
NONINTERACTIVEFLAGS=""
if [ "$INTERACTIVE" -eq 0 ]; then
if [ "$OS" = "debian" ]; then
NONINTERACTIVEFLAGS="-m -y"
elif [ "$OS" = "redhat" ]; then
NONINTERACTIVEFLAGS="-y"
elif [ "$OS" = "arch" ]; then
NONINTERACTIVEFLAGS="--noconfirm"
fi
fi
for package in ${NEED[@]}; do
if [ "$package" = "vagrant" ]; then
if [ "$OS" = "debian" ]; then
cmd="sudo apt-get $NONINTERACTIVEFLAGS install virtualbox vagrant"
elif [ "$OS" = "redhat" ]; then
cmd="sudo yum $NONINTERACTIVEFLAGS install virtualbox vagrant"
elif [ "$OS" = "arch" ]; then
cmd="sudo pacman $NONINTERACTIVEFLAGS -Sy virtualbox vagrant"
elif [ "$OS" = "mac" ]; then
cmd="brew tap caskroom/cask && brew cask install virtualbox vagrant"
else
cmd=""
fi
echo "Vagrant and Virtualbox are required for your flavour of LaMachine but are not installed yet. ${bold}Install automatically?${normal}"
if [ ! -z "$cmd" ]; then
while true; do
echo -n "${bold}Run:${normal} $cmd ? [yn] "
if [ "$INTERACTIVE" -eq 1 ]; then
read yn
else
yn="y"
fi
case $yn in
[Yy]* ) eval $cmd; break;;
[Nn]* ) echo "Please install vagrant manually from https://www.vagrantup.com/downloads.html and VirtualBox from https://www.virtualbox.org/" && echo " .. press ENTER when done or CTRL-C to abort..." && read; break;;
* ) echo "Please answer yes or no.";;
esac
done
else
echo "No automated installation possible on your OS."
if [ "$INTERACTIVE" -eq 0 ]; then exit 5; fi
echo "Please install vagrant manually from https://www.vagrantup.com/downloads.html and VirtualBox from https://www.virtualbox.org/" && echo " .. press ENTER when done or CTRL-C to abort..." && read
fi
elif [ "$package" = "vbguest" ]; then
cmd="vagrant plugin install vagrant-vbguest"
echo "The vagrant-vbguest plugin is required for building VMs. ${bold}Install automatically?${normal}"
if [ ! -z "$cmd" ]; then
while true; do
echo -n "${bold}Run:${normal} $cmd ? [yn] "
if [ "$INTERACTIVE" -eq 1 ]; then
read yn
else
yn="y"
fi
case $yn in
[Yy]* ) $cmd; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
else
echo "${boldred}Automated installation of vagrant-vbguest failed!${normal}"
if [ "$INTERACTIVE" -eq 0 ]; then exit 5; fi
fi
#elif [ "$package" = "vagrant-disksize" ]; then
# cmd="vagrant plugin install vagrant-disksize"
# echo "The vagrant-disksize plugin is required for building VMs. ${bold}Install automatically?${normal}"
# if [ ! -z "$cmd" ]; then
# while true; do
# echo -n "${bold}Run:${normal} $cmd ? [yn] "
# if [ "$INTERACTIVE" -eq 1 ]; then
# read yn
# else
# yn="y"
# fi
# case $yn in
# [Yy]* ) $cmd; break;;
# [Nn]* ) break;;
# * ) echo "Please answer yes or no.";;
# esac
# done
# else
# echo "${boldred}Automated installation of vagrant-disksize failed!${normal}"
# if [ "$INTERACTIVE" -eq 0 ]; then exit 5; fi
# fi
elif [ "$package" = "docker" ]; then
echo "We expect users of docker to be able to install docker themselves."
echo "Docker was not found on your system yet!"
echo "Please install docker, start the daemon, and press ENTER to continue (or CTRL-C) to abort."
read
elif [ "$package" = "singularity" ]; then
echo "We expect users of singularity to be able to install singularity themselves."
echo "Singularity was not found on your system yet!"
echo "Please install singularity, start the daemon, and press ENTER to continue (or CTRL-C) to abort."
read
elif [ "$package" = "lxd" ]; then
cmd=""
if [ "$OS" = "debian" ]; then
if [ "$DISTRIB_ID" = "ubuntu" ] || [ "$DISTRIB_ID" = "linuxmint" ]; then
cmd="sudo apt-get $NONINTERACTIVEFLAGS install lxd"
else
echo "LXD is not packaged for debian yet, please follow the instructions on https://stgraber.org/2017/01/18/lxd-on-debian/ to install it through snapd"
fi
elif [ "$OS" = "redhat" ]; then
echo "LXD is not packaged for CentOS/RHEL yet, please follow the instructions on https://discuss.linuxcontainers.org/t/lxd-on-centos-7/1250 to install it through snapd"
elif [ "$OS" = "arch" ]; then
echo "LXD is not packaged for Arch Linux but it is in the Arch User Repository (AUR), please install the lxd AUR package and install the lxc package through pacman."
cmd=""
else
cmd=""
fi
if [ ! -z "$cmd" ]; then
echo "LXD is required for LaMachine with LXC but not installed yet. ${bold}Install now?${normal}"
while true; do
echo -n "${bold}Run:${normal} $cmd ? [yn] "
if [ "$INTERACTIVE" -eq 1 ]; then
read yn
else
yn="y"
fi
case $yn in
[Yy]* ) $cmd || fatalerror "LXC installation failed!"; break;;
[Nn]* ) echo "Please install LXC manually" && echo " .. press ENTER when done or CTRL-C to abort..." && read; break;;
* ) echo "Please answer yes or no.";;
esac
done
else
echo "No automated installation possible on your OS."
if [ "$INTERACTIVE" -eq 0 ]; then exit 5; fi
echo "Please install LXD manually" && echo " .. press ENTER when done or CTRL-C to abort..." && read
fi
elif [ "$package" = "debootstrap" ]; then
if [ "$OS" = "debian" ]; then
cmd="sudo apt-get $NONINTERACTIVEFLAGS install debootstrap"
elif [ "$OS" = "redhat" ]; then
cmd="sudo yum $NONINTERACTIVEFLAGS install debootstrap"
elif [ "$OS" = "arch" ]; then
cmd="sudo pacman $NONINTERACTIVEFLAGS -Sy debootstrap"
elif [ "$OS" = "mac" ]; then
cmd="brew install debootstrap" #not sure if this works
else
cmd=""
fi
echo "Debootstrap is required for LaMachine with Singularity but not installed yet. ${bold}Install now?${normal}"
if [ ! -z "$cmd" ]; then
while true; do
echo -n "${bold}Run:${normal} $cmd ? [yn] "
if [ "$INTERACTIVE" -eq 1 ]; then
read yn
else
yn="y"
fi
case $yn in
[Yy]* ) $cmd || fatalerror "Debootstrap installation failed!"; break;;
[Nn]* ) echo "Please install debootstrap manually" && echo " .. press ENTER when done or CTRL-C to abort..." && read; break;;
* ) echo "Please answer yes or no.";;
esac
done
else
echo "No automated installation possible on your OS."
if [ "$INTERACTIVE" -eq 0 ]; then exit 5; fi
echo "Please install debootstrap manually" && echo " .. press ENTER when done or CTRL-C to abort..." && read
fi
elif [ "$package" = "brew" ]; then
echo "Homebrew (https://brew.sh) is required on Mac OS X but was not found yet"
while true; do
echo -n "${bold}Download and install homebrew?${normal} [yn] "
if [ "$INTERACTIVE" -eq 1 ]; then
read yn
else
yn="y"
fi
case $yn in
[Yy]* ) break;;
[Nn]* ) echo "Unable to continue without homebrew, see https://brew.sh/"; exit 2;;
* ) echo "Please answer yes or no.";;
esac
done
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" || fatalerror "Homebrew installation failed!"
brew tap caskroom/cask || brew tap caskroom/cask || fatalerror "Failed to install brew-cask, ran: brew tap caskroom/cask"
# ^-- command is repeated in case of failure because homebrew may update and fail once and work the 2nd time
elif [ "$package" = "brew-cask" ]; then
echo "Installing brew-cask"
brew tap caskroom/cask || brew tap caskroom/cask || fatalerror "Failed to install brew-cask, ran: brew tap caskroom/cask"
elif [ "$package" = "git" ]; then
if [ "$OS" = "debian" ]; then
cmd="sudo apt-get $NONINTERACTIVEFLAGS install git-core"
elif [ "$OS" = "redhat" ]; then
cmd="sudo yum $NONINTERACTIVEFLAGS install git"
elif [ "$OS" = "arch" ]; then
cmd="sudo pacman $NONINTERACTIVEFLAGS -Sy git"
elif [ "$OS" = "mac" ]; then
cmd="brew install git"
else
cmd=""
fi
echo "Git is required for LaMachine but not installed yet. ${bold}Install now?${normal}"
if [ ! -z "$cmd" ]; then
while true; do
echo -n "${bold}Run:${normal} $cmd ? [yn] "
if [ "$INTERACTIVE" -eq 1 ]; then
read yn
else
yn="y"
fi
case $yn in
[Yy]* ) $cmd || fatalerror "Git installation failed!"; break;;
[Nn]* ) echo "Please install git manually" && echo " .. press ENTER when done or CTRL-C to abort..." && read; break;;
* ) echo "Please answer yes or no.";;
esac
done
else
echo "No automated installation possible on your OS."
if [ "$INTERACTIVE" -eq 0 ]; then exit 5; fi
echo "Please install git manually" && echo " .. press ENTER when done or CTRL-C to abort..." && read
fi
elif [ "$package" = "epel" ]; then
cmd="sudo yum $NONINTERACTIVEFLAGS install epel-release"
echo "EPEL is required for LaMachine but not installed yet. ${bold}Install now?${normal}"
if [ ! -z "$cmd" ]; then
while true; do
echo -n "${bold}Run:${normal} $cmd ? [yn] "
if [ "$INTERACTIVE" -eq 1 ]; then
read yn
else
yn="y"
fi
case $yn in
[Yy]* ) $cmd || fatalerror "EPEL installation failed"; break;;
[Nn]* ) echo "Please install EPEL manually" && echo " .. press ENTER when done or CTRL-C to abort..." && read; break;;
* ) echo "Please answer yes or no.";;
esac
done
else
echo "No automated installation possible on your OS."
if [ "$INTERACTIVE" -eq 0 ]; then exit 5; fi
echo "Please install pip manually" && echo " .. press ENTER when done or CTRL-C to abort..." && read
fi
elif [ "$package" = "ansible" ]; then
if [ "$OS" = "debian" ]; then
if [ "$DISTRIB_ID" = "ubuntu" ] || [ "$DISTRIB_ID" = "linuxmint" ]; then
#add PPA
cmd="sudo apt-get update && sudo apt-get $NONINTERACTIVEFLAGS install software-properties-common && sudo apt-add-repository -y ppa:ansible/ansible && sudo apt-get update && sudo apt-get $NONINTERACTIVEFLAGS install ansible"
else
cmd="echo 'deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main' | sudo tee -a /etc/apt/sources.list && sudo apt-get $NONINTERACTIVEFLAGS update && sudo apt-get $NONINTERACTIVEFLAGS install gnupg && sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367 && sudo apt-get $NONINTERACTIVEFLAGS update && sudo apt-get $NONINTERACTIVEFLAGS --allow-unauthenticated install ansible"
fi