forked from lavabit/robox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
robox.sh
executable file
·1398 lines (1143 loc) · 57.1 KB
/
robox.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
# Name: robox.sh
# Author: Ladar Levison
#
# Description: Used to build various virtual machines using packer.
# Version Information
export VERSION="3.1.16"
export AGENT="Vagrant/2.2.9 (+https://www.vagrantup.com; ruby2.6.6)"
# Limit the number of cpus packer will use.
export GOMAXPROCS="2"
export PACKERMAXPROCS="1"
# Handle self referencing, sourcing etc.
if [[ $0 != $BASH_SOURCE ]]; then
export CMD=$BASH_SOURCE
else
export CMD=$0
fi
# Ensure a consistent working directory so relative paths work.
pushd `dirname $CMD` > /dev/null
BASE=`pwd -P`
popd > /dev/null
cd $BASE
# Credentials and tokens.
if [ ! -f $BASE/.credentialsrc ]; then
cat << EOF > $BASE/.credentialsrc
#!/bin/bash
export GOMAXPROCS="2"
export QUAY_USER="LOGIN"
export QUAY_PASSWORD="PASSWORD"
export DOCKER_USER="LOGIN"
export DOCKER_PASSWORD="PASSWORD"
export VMWARE_WORKSTATION="SERIAL"
export VAGRANT_CLOUD_TOKEN="TOKEN"
# Overrides the repo version with a default value.
VERSION="1.0.0"
EOF
tput setaf 1; printf "\n\nCredentials file was missing. Stub file created.\n\n\n"; tput sgr0
sleep 5
fi
# Import the credentials.
source $BASE/.credentialsrc
# The list of packer config files.
FILES="packer-cache.json "\
"magma-docker.json magma-hyperv.json magma-vmware.json magma-libvirt.json magma-virtualbox.json "\
"generic-docker.json generic-hyperv.json generic-vmware.json generic-libvirt.json generic-libvirt-x32.json generic-parallels.json generic-virtualbox.json "\
"lineage-hyperv.json lineage-vmware.json lineage-libvirt.json lineage-virtualbox.json "\
"developer-ova.json developer-hyperv.json developer-vmware.json developer-libvirt.json developer-virtualbox.json"
# Media Files
MEDIAFILES="res/media/rhel-server-6.10-x86_64-dvd.iso"\
"|res/media/rhel-server-7.6-x86_64-dvd.iso"\
"|res/media/rhel-8.0-beta-1-x86_64-dvd.iso"
MEDIASUMS="1e15f9202d2cdd4b2bdf9d6503a8543347f0cb8cc06ba9a0dfd2df4fdef5c727"\
"|60a0be5aeed1f08f2bb7599a578c89ec134b4016cd62a8604b29f15d543a469c"\
"|005d4f88fff6d63b0fc01a10822380ef52570edd8834321de7be63002cc6cc43"
MEDIAURLS="https://archive.org/download/rhel-server-6.10-x86_64-dvd/rhel-server-6.10-x86_64-dvd.iso"\
"|https://archive.org/download/rhel-server-7.6-x86_64-dvd/rhel-server-7.6-x86_64-dvd.iso"\
"|https://archive.org/download/rhel-8.0-x86_64-dvd/rhel-8.0-x86_64-dvd.iso"
# When validating ISO checksums skip these URLS.
DYNAMICURLS="http://cdimage.ubuntu.com/ubuntu-server/daily/current/disco-server-amd64.iso|"\
"https://cdimage.debian.org/cdimage/weekly-builds/amd64/iso-cd/debian-testing-amd64-netinst.iso"
# Collect the list of ISO urls.
ISOURLS=(`grep -E "iso_url|guest_additions_url" $FILES | grep -Ev "$DYNAMICURLS" | awk -F'"' '{print $4}'`)
ISOSUMS=(`grep -E "iso_checksum|guest_additions_sha256" $FILES | awk -F'"' '{print $4}' | sed "s/^sha256://g"`)
UNIQURLS=(`grep -E "iso_url|guest_additions_url" $FILES | awk -F'"' '{print $4}' | sort | uniq`)
# Collect the list of box names.
MAGMA_BOXES=`grep -E '"name":' $FILES | awk -F'"' '{print $4}' | grep "magma-" | sort --field-separator=- -k 3i -k 2.1,2.0`
MAGMA_SPECIAL_BOXES="magma-hyperv magma-vmware magma-libvirt magma-virtualbox magma-docker "\
"magma-centos-hyperv magma-centos-vmware magma-centos-libvirt magma-centos-virtualbox magma-centos-docker "\
"magma-ubuntu-hyperv magma-ubuntu-vmware magma-ubuntu-libvirt magma-ubuntu-virtualbox"
GENERIC_BOXES=`grep -E '"name":' $FILES | awk -F'"' '{print $4}' | grep "generic-" | sort --field-separator=- -k 3i -k 2.1,2.0`
ROBOX_BOXES=`grep -E '"name":' $FILES | awk -F'"' '{print $4}' | grep "generic-" | sed "s/generic-/roboxes-/g"| sort --field-separator=- -k 3i -k 2.1,2.0`
LINEAGE_BOXES=`grep -E '"name":' $FILES | awk -F'"' '{print $4}' | grep -E "lineage-" | sort --field-separator=- -k 1i,1.8 -k 3i -k 2i,2.4`
LINEAGEOS_BOXES=`grep -E '"name":' $FILES | awk -F'"' '{print $4}' | grep -E "lineage-" | sed "s/lineage-/lineageos-/g"| sort --field-separator=- -k 1i,1.8 -k 3i -k 2i,2.4`
MAGMA_BOXES=`echo $MAGMA_SPECIAL_BOXES $MAGMA_BOXES | sed 's/ /\n/g' | sort -u --field-separator=- -k 3i -k 2.1,2.0`
BOXES="$GENERIC_BOXES $ROBOX_BOXES $MAGMA_BOXES $LINEAGE_BOXES $LINEAGEOS_BOXES"
# Collect the list of box tags.
MAGMA_TAGS=`grep -E '"name":' $FILES | awk -F'"' '{print $4}' | grep "magma" | grep -v "magma-developer-ova" | sed "s/magma-/lavabit\/magma-/g" | sed "s/alpine36/alpine/g" | sed "s/debian8/debian/g" | sed "s/fedora27/fedora/g" | sed "s/freebsd11/freebsd/g" | sed "s/openbsd6/openbsd/g" | sed "s/\(-hyperv\|-vmware\|-libvirt\|-parallels\|-virtualbox\|-docker\)\$//g" | sort -u --field-separator=-`
MAGMA_SPECIAL_TAGS="lavabit/magma lavabit/magma-centos lavabit/magma-ubuntu"
ROBOX_TAGS=`grep -E '"name":' $FILES | awk -F'"' '{print $4}' | grep "generic" | sed "s/generic-/roboxes\//g" | sed "s/\(-hyperv\|-vmware\|-x32-libvirt\|-libvirt\|-parallels\|-virtualbox\|-docker\)\$//g" | sort -u --field-separator=-`
GENERIC_TAGS=`grep -E '"name":' $FILES | awk -F'"' '{print $4}' | grep "generic" | sed "s/generic-/generic\//g" | sed "s/\(-hyperv\|-vmware\|-x32-libvirt\|-libvirt\|-parallels\|-virtualbox\|-docker\)//g" | sort -u --field-separator=-`
LINEAGE_TAGS=`grep -E '"name":' $FILES | awk -F'"' '{print $4}' | grep "lineage" | sed "s/lineage-/lineage\/lineage-/g" | sed "s/\(-hyperv\|-vmware\|-libvirt\|-parallels\|-virtualbox\|-docker\)\$//g" | sort -u --field-separator=-`
LINEAGEOS_TAGS=`grep -E '"name":' $FILES | awk -F'"' '{print $4}' | grep "lineage" | sed "s/lineage-/lineageos\/lineage-/g" | sed "s/\(-hyperv\|-vmware\|-libvirt\|-parallels\|-virtualbox\|-docker\)\$//g" | sort -u --field-separator=-`
MAGMA_TAGS=`echo $MAGMA_SPECIAL_TAGS $MAGMA_TAGS | sed 's/ /\n/g' | sort -u --field-separator=-`
TAGS="$GENERIC_TAGS $ROBOX_TAGS $MAGMA_TAGS $LINEAGE_TAGS $LINEAGEOS_TAGS"
# These boxes aren't publicly available yet, so we filter them out of available test.
FILTERED_TAGS="lavabit/magma-alpine lavabit/magma-arch lavabit/magma-freebsd lavabit/magma-gentoo lavabit/magma-openbsd"
# A list of configs to skip during complete build operations.
export EXCEPTIONS=""
# Detect Windows subsystem for Linux.
if [ -z $OS ]; then
if [[ "`uname -r`" =~ -Microsoft$ ]]; then
export OS="Windows_NT"
fi
fi
# If Vagrant is installed, use the newer version of curl.
if [ -f /opt/vagrant/embedded/bin/curl ]; then
export CURL="/opt/vagrant/embedded/bin/curl"
if [ -f /opt/vagrant/embedded/lib64/libssl.so ] && [ -z LD_PRELOAD ]; then
export LD_PRELOAD="/opt/vagrant/embedded/lib64/libssl.so"
elif [ -f /opt/vagrant/embedded/lib64/libssl.so ]; then
export LD_PRELOAD="/opt/vagrant/embedded/lib64/libssl.so:$LD_PRELOAD"
fi
if [ -f /opt/vagrant/embedded/lib64/libcrypto.so ] && [ -z LD_PRELOAD ]; then
export LD_PRELOAD="/opt/vagrant/embedded/lib64/libcrypto.so"
elif [ -f /opt/vagrant/embedded/lib64/libcrypto.so ]; then
export LD_PRELOAD="/opt/vagrant/embedded/lib64/libcrypto.so:$LD_PRELOAD"
fi
export LD_LIBRARY_PATH="/opt/vagrant/embedded/bin/lib/:/opt/vagrant/embedded/lib64/"
else
export CURL="curl"
fi
function retry() {
local COUNT=1
local DELAY=1
local RESULT=0
while [[ "${COUNT}" -le 10 ]]; do
[[ "${RESULT}" -ne 0 ]] && {
tput setaf 1; printf "\n${*} failed... retrying ${COUNT} of 10.\n" >&2; tput sgr0
}
"${@}" && { RESULT=0 && break; } || RESULT="${?}"
COUNT="$((COUNT + 1))"
# Increase the delay with each iteration.
DELAY="$((DELAY + 10))"
sleep $DELAY
done
[[ "${COUNT}" -gt 10 ]] && {
tput setaf 1; printf "\nThe command failed 10 times.\n" >&2; tput sgr0
}
return "${RESULT}"
}
function curltry() {
local COUNT=1
local DELAY=1
local RESULT=0
while [[ "${COUNT}" -le 100 ]]; do
RESULT=0 ; OUTPUT=`"${@}"` || RESULT="${?}"
if [[ $RESULT == 0 ]] || [[ `echo "$OUTPUT" | grep --count "404"` == 1 ]]; then
break
fi
COUNT="$((COUNT + 1))"
DELAY="$((DELAY + 1))"
sleep $DELAY
done
echo "$OUTPUT"
return "${RESULT}"
}
function start() {
# Disable IPv6 or the VMware builder won't be able to load the Kick Start configuration.
sudo sysctl net.ipv6.conf.all.disable_ipv6=1
# Start the required services.
# sudo systemctl restart vmtoolsd.service
if [ -f /usr/lib/systemd/system/vboxdrv.service ]; then sudo systemctl restart vboxdrv.service ; fi
if [ -f /usr/lib/systemd/system/libvirtd.service ]; then sudo systemctl restart libvirtd.service ; fi
if [ -f /usr/lib/systemd/system/docker-latest.service ]; then sudo systemctl restart docker-latest.service ;
elif [ -f /usr/lib/systemd/system/docker.service ]; then sudo systemctl restart docker.service ; fi
if [ -f /etc/init.d/vmware ]; then sudo /etc/init.d/vmware start ; fi
if [ -f /etc/init.d/vmware-USBArbitrator ]; then sudo /etc/init.d/vmware-USBArbitrator start ; fi
if [ -f /etc/init.d/vmware-workstation-server ]; then sudo /etc/init.d/vmware-workstation-server start ; fi
# Confirm the VMware modules loaded.
if [ -f /usr/bin/vmware-modconfig ]; then
MODS=`sudo /etc/init.d/vmware status | grep --color=none --extended-regexp "Module vmmon loaded|Module vmnet loaded" | wc -l`
if [ "$MODS" != "2" ]; then
sudo vmware-modconfig --console --install-all
if [ $? != 0 ]; then
tput setaf 1; tput bold; printf "\n\nThe vmware kernel modules failed to load properly...\n\n"; tput sgr0
for i in 1 2 3; do printf "\a"; sleep 1; done
exit 1
fi
fi
fi
# Confirm the VirtualBox kernel modules loaded.
if [ -f /usr/lib/virtualbox/vboxdrv.sh ]; then
/usr/lib/virtualbox/vboxdrv.sh status | grep --color=none "VirtualBox kernel modules \(.*\) are loaded."
if [ $? != 0 ]; then
sudo /usr/lib/virtualbox/vboxdrv.sh setup
if [ $? != 0 ]; then
tput setaf 1; tput bold; printf "\n\nThe virtualbox kernel modules failed to load properly...\n\n"; tput sgr0
for i in 1 2 3; do printf "\a"; sleep 1; done
exit 1
fi
fi
fi
# Set the tuning profile to virtual-host.
if [ -f /usr/sbin/tuned-adm ]; then
sudo /usr/sbin/tuned-adm profile virtual-host
sudo /usr/sbin/tuned-adm active
fi
# Set the CPU performance level to maximum.
if [ -f /usr/bin/cpupower ]; then
sudo /usr/bin/cpupower set -b 0
sudo /usr/bin/cpupower info
fi
}
function print_iso() {
SHA=`curl --silent --location "${2}" | sha256sum | awk -F' ' '{print $1}'`
if [ $? != 0 ]; then
tput setaf 1; printf "\n$1 failed.\n\n"; tput sgr0; printf "${2}\n\n"
return 1
fi
tput setaf 2; printf "\n$1\n\n"; tput sgr0; printf "${2}\n${SHA}\n\n"
}
# Print the current URL and SHA hash for install discs which are updated frequently.
function isos() {
# Find the Gentoo URL.
URL="https://mirrors.kernel.org/gentoo/releases/amd64/autobuilds/current-install-amd64-minimal/"
ISO=`curl --silent "${URL}" | grep --invert-match sha256 | grep --extended-regexp --only-matching --max-count=1 "install\-amd64\-minimal\-[0-9]{8}T[0-9]{6}Z\.iso" | uniq`
URL="${URL}${ISO}"
N=( "${N[@]}" "Gentoo" ); U=( "${U[@]}" "$URL" )
# Find the Arch URL.
URL="https://mirrors.edge.kernel.org/archlinux/iso/latest/"
ISO=`curl --silent "${URL}" | grep --invert-match sha256 | grep --extended-regexp --only-matching --max-count=1 "archlinux\-[0-9]{4}\.[0-9]{2}\.[0-9]{2}\-x86\_64\.iso" | uniq`
URL="${URL}${ISO}"
N=( "${N[@]}" "Arch" ); U=( "${U[@]}" "$URL" )
# Ubuntu Disco
# URL="http://cdimage.ubuntu.com/ubuntu-server/daily/current/disco-server-amd64.iso"
# N=( "${N[@]}" "Disco" ); U=( "${U[@]}" "$URL" )
# Debian Buster
# URL="https://cdimage.debian.org/cdimage/weekly-builds/amd64/iso-cd/debian-testing-amd64-netinst.iso"
# N=( "${N[@]}" "Buster" ); U=( "${U[@]}" "$URL" )
export -f print_iso
parallel -j 16 --xapply print_iso {1} {2} ::: "${N[@]}" ::: "${U[@]}"
}
function iso() {
if [ "$1" == "gentoo" ]; then
# Find the existing Arch URL and hash values.
ISO_URL=`cat "$BASE/packer-cache.json" | jq -r -c ".builders[] | select( .name | contains(\"gentoo\")) | .iso_url" 2>/dev/null`
ISO_CHECKSUM=`cat "$BASE/packer-cache.json" | jq -r -c ".builders[] | select( .name | contains(\"gentoo\")) | .iso_checksum" 2>/dev/null`
# Find the Gentoo URL.
URL="https://mirrors.kernel.org/gentoo/releases/amd64/autobuilds/current-install-amd64-minimal/"
ISO=`curl --fail --silent "${URL}" | grep --invert-match sha256 | grep --extended-regexp --only-matching --max-count=1 "install\-amd64\-minimal\-[0-9]{8}T[0-9]{6}Z\.iso" | uniq`
if [ $? != 0 ] || [ "$ISO" == "" ]; then
tput setaf 1; printf "\nThe Gentoo ISO update failed.\n\n"; tput sgr0
return 1
fi
# Calculate the new URL.
URL="${URL}${ISO}"
# Download the ISO file and calculate the new hash value.
set -o pipefail
SHA=`curl --fail --speed-limit 0 --speed-time 10 --silent --location "${URL}" | sha256sum | awk -F' ' '{print $1}'`
if [ $? != 0 ] || [ "$SHA" == "" ]; then
tput setaf 1; printf "\nThe Gentoo ISO update failed.\n\n"; tput sgr0
return 1
fi
set +o pipefail
# Escape the URL strings.
URL=`echo $URL | sed "s/\//\\\\\\\\\//g"`
ISO_URL=`echo $ISO_URL | sed "s/\//\\\\\\\\\//g"`
# Replace the existing ISO and hash values with the update values.
sed --in-place "s/$ISO_URL/$URL/g" $FILES
sed --in-place "s/$ISO_CHECKSUM/sha256:$SHA/g" $FILES
elif [ "$1" == "arch" ]; then
# Find the existing Arch URL and hash values.
ISO_URL=`cat "$BASE/packer-cache.json" | jq -r -c ".builders[] | select( .name | contains(\"arch\")) | .iso_url" 2>/dev/null`
ISO_CHECKSUM=`cat "$BASE/packer-cache.json" | jq -r -c ".builders[] | select( .name | contains(\"arch\")) | .iso_checksum" 2>/dev/null`
# Find the Arch URL.
URL="https://mirrors.edge.kernel.org/archlinux/iso/latest/"
ISO=`curl --fail --silent "${URL}" | grep --invert-match sha256 | grep --extended-regexp --only-matching --max-count=1 "archlinux\-[0-9]{4}\.[0-9]{2}\.[0-9]{2}\-x86\_64\.iso" | uniq`
if [ $? != 0 ] || [ "$ISO" == "" ]; then
tput setaf 1; printf "\nThe Arch ISO update failed.\n\n"; tput sgr0
return 1
fi
# Calculate the new URL.
URL="${URL}${ISO}"
# Download the ISO file and calculate the new hash value.
set -o pipefail
SHA=`curl --fail --speed-limit 0 --speed-time 10 --silent --location "${URL}" | sha256sum | awk -F' ' '{print $1}'`
if [ $? != 0 ] || [ "$SHA" == "" ]; then
tput setaf 1; printf "\nThe Arch ISO update failed.\n\n"; tput sgr0
return 1
fi
set +o pipefail
# Escape the URL strings.
URL=`echo $URL | sed "s/\//\\\\\\\\\//g"`
ISO_URL=`echo $ISO_URL | sed "s/\//\\\\\\\\\//g"`
# Replace the existing ISO and hash values with the update values.
sed --in-place "s/$ISO_URL/$URL/g" $FILES
sed --in-place "s/$ISO_CHECKSUM/sha256:$SHA/g" $FILES
fi
}
function cache {
unset PACKER_LOG ; unset LD_PRELOAD ; unset LD_LIBRARY_PATH ;
if [[ $OS == "Windows_NT" ]]; then
packer.exe build -on-error=cleanup -color=false -parallel-builds=$PACKERMAXPROCS -except= packer-cache.json 2>&1 | tr -cs [:print:] [\\n*] | grep --line-buffered --color=none -E "Download progress|Downloading or copying|Found already downloaded|Transferred:|[0-9]*[[:space:]]*items:"
else
packer build -on-error=cleanup -color=false -parallel-builds=$PACKERMAXPROCS -except= packer-cache.json 2>&1 | tr -cs [:print:] [\\n*] | grep --line-buffered --color=none -E "Download progress|Downloading or copying|Found already downloaded|Transferred:|[0-9]*[[:space:]]*items:"
fi
if [[ $? != 0 ]]; then
tput setaf 1; tput bold; printf "\n\nDistro disc image download aborted...\n\n"; tput sgr0
else
tput setaf 2; tput bold; printf "\n\nDistro disc images have finished downloading...\n\n"; tput sgr0
fi
}
# Verify all of the ISO locations are still valid.
function verify_url {
# Grab just the response header and look for the 200 response code to indicate the link is valid.
curl --head --silent --location --retry 3 --retry-delay 4 --connect-timeout 60 "$1" | grep --extended-regexp "HTTP/1\.1 [0-9]*|HTTP/2\.0 [0-9]*|HTTP/2 [0-9]*" | tail -1 | grep --silent --extended-regexp "HTTP/1\.1 200 OK|HTTP/2\.0 200 OK|HTTP/2 200"
# The grep return code tells us whether it found a match in the header or not.
if [ $? != 0 ]; then
# Wait a minute, and then try again. Many of the failures are transient network errors.
sleep 10; curl --head --silent --location --retry 3 --retry-delay 4 --connect-timeout 60 "$1" | grep --extended-regexp "HTTP/1\.1 [0-9]*|HTTP/2\.0 [0-9]*|HTTP/2 [0-9]*" | tail -1 | grep --silent --extended-regexp "HTTP/1\.1 200 OK|HTTP/2\.0 200 OK|HTTP/2 200"
if [ $? != 0 ]; then
printf "Link Failure: $1\n"
return 1
fi
fi
}
# Verify all of the ISO locations are valid and then download the ISO and verify the hash.
function verify_sum {
# Grab just the response header and look for the 200 response code to indicate the link is valid.
curl --silent --location --head "$1" | grep --extended-regexp "HTTP/1\.1 200 OK|HTTP/2\.0 200 OK|HTTP/2 200" | tail -1 | grep --silent --extended-regexp "HTTP/1\.1 200 OK|HTTP/2\.0 200 OK|HTTP/2 200"
# The grep return code tells us whether it found a match in the header or not.
if [ $? != 0 ]; then
printf "Link Failure: $1\n\n"
exit 1
fi
# Grab the ISO and pipe the data through sha256sum, then compare the checksum value.
SUM=`curl --silent --location "$1" | sha256sum | tr -d ' -'`
echo $SUM | grep --silent "$2"
# The grep return code tells us whether we found a checksum match.
if [ $? != 0 ]; then
# Wait a minute, and then try again. Many of the failures are transient network errors.
SUM=`sleep 60; curl --silent --location "$1" | sha256sum | tr -d ' -'`
echo $SUM | grep --silent "$2"
if [ $? != 0 ]; then
printf "Hash Failure: $1\n"
printf "Found - $SUM\n"
printf "Expected - $2\n\n"
exit 1
fi
fi
printf "Validated : $1\n"
return 0
}
# Verify the local ISO files are valid and if necessary download the file.
function verify_local {
ISOAGENT="Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0"
# Make sure the ISO exists, and is the proper size.
if [ ! -f "${2}" ] || [ "`sha256sum \"${2}\" | awk -F' ' '{print \$1}'`" != "${1}" ]; then
curl --location --retry 16 --retry-delay 16 --max-redirs 16 --user-agent "${ISOAGENT}" --output "${2}.part" "${3}"
sha256sum "${2}.part" | grep --silent "${1}"
if [ $? != 0 ]; then
tput setaf 1; tput bold; printf "\n\nLocal ISO file could not be downloaded...\n\n"; tput sgr0
rm --force "${2}"
else
mv --force "${2}.part" "${2}"
fi
fi
}
# Validate the templates before building.
function verify_json() {
unset LD_PRELOAD ; unset LD_LIBRARY_PATH ;
if [[ $OS == "Windows_NT" ]]; then
packer.exe validate $1.json
else
packer validate $1.json
fi
if [[ $? != 0 ]]; then
tput setaf 1; tput bold; printf "\n\nthe $1 packer template failed to validate...\n\n"; tput sgr0
for i in 1 2 3; do printf "\a"; sleep 1; done
exit 1
fi
}
# Make sure the logging directory is avcailable. If it isn't, then create it.
function verify_logdir {
if [ ! -d logs ]; then
mkdir -p logs
elif [ ! -d logs ]; then
mkdir logs
fi
}
# Check whether a box has been uploaded to the cloud.
function verify_availability() {
local RESULT=0
curltry ${CURL} --head --fail --silent --location --user-agent "${AGENT}" --output /dev/null --write-out "%{http_code}" "https://vagrantcloud.com/$1/boxes/$2/versions/$4/providers/$3.box" | grep --silent "200"
if [ $? != 0 ]; then
#printf "Box - "; tput setaf 1; printf "${1}/${2} ${3}\n"; tput sgr0
printf "%sBox - %s${1}/${2} ${3}%s \n%s" "`tput sgr0`" "`tput setaf 1`" "`tput sgr0`" "`tput sgr0`"
let RESULT=1
else
#printf "Box + "; tput setaf 2; printf "${1}/${2} ${3}\n"; tput sgr0
printf "%sBox + %s${1}/${2} ${3}%s \n%s" "`tput sgr0`" "`tput setaf 2`" "`tput sgr0`" "`tput sgr0`"
fi
return $RESULT
}
# Build the boxes and cleanup the packer cache after each run.
function build() {
verify_logdir
export INCREMENT=1
export PACKER_LOG="1"
unset LD_PRELOAD ; unset LD_LIBRARY_PATH ;
while [ $INCREMENT != 0 ]; do
export PACKER_LOG_PATH="$BASE/logs/$1-${INCREMENT}.txt"
if [ ! -f $PACKER_LOG_PATH ]; then
let INCREMENT=0
else
let INCREMENT=$INCREMENT+1
fi
done
if [[ $OS == "Windows_NT" ]]; then
packer.exe build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -except="${EXCEPTIONS}" $1.json
else
packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -except="${EXCEPTIONS}" $1.json
fi
if [[ $? != 0 ]]; then
tput setaf 1; tput bold; printf "\n\n$1 images failed to build properly...\n\n"; tput sgr0
# Auto retry any boxes that failed.
which jq &> /dev/null
if [[ $? == 0 ]]; then
LIST=(`cat $1.json | jq -r " .builders | .[] | .name " | sort`)
for ((i = 0; i < ${#LIST[@]}; ++i)); do
if [ ! -f "$BASE/output/${LIST[$i]}-$VERSION.box" ]; then
packer build -parallel-builds=$PACKERMAXPROCS -only="${LIST[$i]}" -except="${EXCEPTIONS}" $1.json
fi
done
fi
for i in 1 2 3; do printf "\a"; sleep 1; done
fi
}
# Build an individual box.
function box() {
verify_logdir
export PACKER_LOG="1"
export TIMESTAMP=`date +"%Y%m%d.%I%M"`
unset LD_PRELOAD ; unset LD_LIBRARY_PATH ;
if [[ $OS == "Windows_NT" ]]; then
export PACKER_LOG_PATH="$BASE/logs/magma-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*magma.*$ ]] && [[ "$1" =~ ^.*hyperv.*$ ]] && packer.exe build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 magma-hyperv.json
export PACKER_LOG_PATH="$BASE/logs/generic-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*generic.*$ ]] && [[ "$1" =~ ^.*hyperv.*$ ]] && packer.exe build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 generic-hyperv.json
export PACKER_LOG_PATH="$BASE/logs/lineage-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*lineage.*$ ]] && [[ "$1" =~ ^.*hyperv.*$ ]] && packer.exe build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 lineage-hyperv.json
export PACKER_LOG_PATH="$BASE/logs/developer-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*developer.*$ ]] && [[ "$1" =~ ^.*hyperv.*$ ]] && packer.exe build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 developer-hyperv.json
fi
if [[ `uname` == "Darwin" ]]; then
export PACKER_LOG_PATH="$BASE/logs/generic-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*generic.*$ ]] && [[ "$1" =~ ^.*parallels.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 generic-parallels.json
fi
if [[ `uname` == "Linux" ]]; then
export PACKER_LOG_PATH="$BASE/logs/magma-docker-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*magma.*$ ]] && [[ "$1" =~ ^.*docker.*$ ]] && (docker-login && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 magma-docker.json; docker-logout)
export PACKER_LOG_PATH="$BASE/logs/magma-libvirt-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*magma.*$ ]] && [[ "$1" =~ ^.*libvirt.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 magma-libvirt.json
export PACKER_LOG_PATH="$BASE/logs/generic-docker-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*generic.*$ ]] && [[ "$1" =~ ^.*docker.*$ ]] && (docker-login && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 generic-docker.json; docker-logout)
export PACKER_LOG_PATH="$BASE/logs/generic-libvirt-x32-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*generic.*$ ]] && [[ "$1" =~ ^.*x32-libvirt.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 generic-libvirt-x32.json
export PACKER_LOG_PATH="$BASE/logs/generic-libvirt-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*generic.*$ ]] && [[ "$1" =~ ^.*libvirt.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 generic-libvirt.json
export PACKER_LOG_PATH="$BASE/logs/developer-ova-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*developer.*$ ]] && [[ "$1" =~ ^.*ova.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 developer-ova.json
export PACKER_LOG_PATH="$BASE/logs/developer-libvirt-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*developer.*$ ]] && [[ "$1" =~ ^.*libvirt.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 developer-libvirt.json
export PACKER_LOG_PATH="$BASE/logs/lineage-libvirt-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*lineage.*$ ]] && [[ "$1" =~ ^.*libvirt.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 lineage-libvirt.json
fi
export PACKER_LOG_PATH="$BASE/logs/magma-vmware-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*magma.*$ ]] && [[ "$1" =~ ^.*vmware.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 magma-vmware.json
export PACKER_LOG_PATH="$BASE/logs/magma-virtualbox-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*magma.*$ ]] && [[ "$1" =~ ^.*virtualbox.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 magma-virtualbox.json
export PACKER_LOG_PATH="$BASE/logs/generic-vmware-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*generic.*$ ]] && [[ "$1" =~ ^.*vmware.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 generic-vmware.json
export PACKER_LOG_PATH="$BASE/logs/generic-virtualbox-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*generic.*$ ]] && [[ "$1" =~ ^.*virtualbox.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 generic-virtualbox.json
export PACKER_LOG_PATH="$BASE/logs/developer-vmware-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*developer.*$ ]] && [[ "$1" =~ ^.*vmware.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 developer-vmware.json
export PACKER_LOG_PATH="$BASE/logs/developer-virtualbox-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*developer.*$ ]] && [[ "$1" =~ ^.*virtualbox.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 developer-virtualbox.json
export PACKER_LOG_PATH="$BASE/logs/lineage-vmware-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*lineage.*$ ]] && [[ "$1" =~ ^.*vmware.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 lineage-vmware.json
export PACKER_LOG_PATH="$BASE/logs/lineage-virtualbox-log-${TIMESTAMP}.txt"
[[ "$1" =~ ^.*lineage.*$ ]] && [[ "$1" =~ ^.*virtualbox.*$ ]] && packer build -on-error=cleanup -parallel-builds=$PACKERMAXPROCS -only=$1 lineage-virtualbox.json
return 0
}
function links() {
MURLS=(`echo $MEDIAURLS | sed "s/|/ /g"`)
for ((i = 0; i < ${#MURLS[@]}; ++i)); do
(verify_url "${MURLS[$i]}") &
sleep 0.1 &> /dev/null || echo "" &> /dev/null
done
for ((i = 0; i < ${#UNIQURLS[@]}; ++i)); do
(verify_url "${UNIQURLS[$i]}") &
sleep 0.1 &> /dev/null || echo "" &> /dev/null
done
# Wait until the children done working.
wait
# Combine the media URLs with the regular box ISO urls.
let TOTAL=${#UNIQURLS[@]}+${#MURLS[@]}
# Let the user know all of the links passed.
printf "\nAll $TOTAL of the install media locations have been checked...\n\n"
}
function sums() {
# for ((i = 0; i < ${#ISOURLS[@]}; ++i)); do
# verify_sum "${ISOURLS[$i]}" "${ISOSUMS[$i]}"
# done
export -f verify_sum
parallel -j 16 --xapply verify_sum {1} {2} ":::" "${ISOURLS[@]}" ":::" "${ISOSUMS[@]}"
# Let the user know all of the links passed.
# printf "\nAll ${#ISOURLS[@]} of the install media locations have been validated...\n\n"
}
function validate() {
verify_json packer-cache
verify_json magma-docker
verify_json magma-hyperv
verify_json magma-vmware
verify_json magma-libvirt
verify_json magma-virtualbox
verify_json generic-docker
verify_json generic-hyperv
verify_json generic-vmware
verify_json generic-libvirt
verify_json generic-libvirt-x32
verify_json generic-parallels
verify_json generic-virtualbox
verify_json developer-ova
verify_json developer-hyperv
verify_json developer-vmware
verify_json developer-libvirt
verify_json developer-virtualbox
verify_json lineage-hyperv
verify_json lineage-vmware
verify_json lineage-libvirt
verify_json lineage-virtualbox
}
function missing() {
MISSING=0
LIST=($BOXES)
for ((i = 0; i < ${#LIST[@]}; ++i)); do
# With OVA boxes we need to parse the box name and convert it to a filename.
if [[ "${LIST[$i]}" =~ ^.*-ova$ ]]; then
FILENAME=`echo "${LIST[$i]}" | sed "s/\([a-z]*-[a-z0-9-]*\)-ova/\1-${VERSION}.ova/g"`
if [ ! -f $BASE/output/"$FILENAME" ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]}\n"; tput sgr0
else
printf "Box + "; tput setaf 2; printf "${LIST[$i]}\n"; tput sgr0
fi
# With Docker boxes we need to look for a tarball and a box file.
elif [[ "${LIST[$i]}" =~ ^.*-docker$ ]]; then
if [ ! -f $BASE/output/"${LIST[$i]}-${VERSION}.tar.gz" ] || [ ! -f $BASE/output/"${LIST[$i]}-${VERSION}.box" ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]}\n"; tput sgr0
else
printf "Box + "; tput setaf 2; printf "${LIST[$i]}\n"; tput sgr0
fi
else
if [ ! -f $BASE/output/"${LIST[$i]}-${VERSION}.box" ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]}\n"; tput sgr0
else
printf "Box + "; tput setaf 2; printf "${LIST[$i]}\n"; tput sgr0
fi
fi
done
# Let the user know how many boxes were missing.
if [ $MISSING -eq 0 ]; then
printf "\nAll ${#LIST[@]} of the boxes are present and accounted for...\n\n"
else
printf "\nOf the ${#LIST[@]} boxes defined, $MISSING are missing...\n\n"
fi
}
function available() {
FOUND=0
MISSING=0
LIST=($TAGS)
FILTER=($FILTERED_TAGS)
# Loop through and remove the filtered tags from the list.
for ((i = 0; i < ${#FILTER[@]}; ++i)); do
LIST=(${LIST[@]//${FILTER[$i]}})
done
for ((i = 0; i < ${#LIST[@]}; ++i)); do
ORGANIZATION=`echo ${LIST[$i]} | awk -F'/' '{print $1}'`
BOX=`echo ${LIST[$i]} | awk -F'/' '{print $2}'`
PROVIDER="docker"
if [[ "${ORGANIZATION}" =~ ^(generic|roboxes|lavabit)$ ]]; then
if [[ "${BOX}" == "centos6" ]] || [[ "${BOX}" == "centos7" ]] || [[ "${BOX}" == "centos8" ]] || \
[[ "${BOX}" == "rhel6" ]] || [[ "${BOX}" == "rhel7" ]] || [[ "${BOX}" == "rhel8" ]] || \
[[ "${BOX}" == "oracle7" ]] || [[ "${BOX}" == "oracle8" ]] || \
[[ "${BOX}" == "magma" ]] || [[ "${BOX}" == "magma-centos" ]] || \
[[ "${BOX}" == "magma-centos6" ]] || [[ "${BOX}" == "magma-centos7" ]]; then
curl --head --silent --location --user-agent "${AGENT}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box" | head -1 | grep --silent --extended-regexp "HTTP/1\.1 200 OK|HTTP/2\.0 200 OK|HTTP/2 200|HTTP/1\.1 302 Found|HTTP/2.0 302 Found|HTTP/2 302 Found"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
fi
fi
PROVIDER="hyperv"
curl --head --silent --location --user-agent "${AGENT}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box?access_token=${VAGRANT_CLOUD_TOKEN}" | head -1 | grep --silent --extended-regexp "HTTP/1\.1 200 OK|HTTP/2\.0 200 OK|HTTP/2 200|HTTP/1\.1 302 Found|HTTP/2.0 302 Found|HTTP/2 302 Found"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
PROVIDER="libvirt"
curl --head --silent --location --user-agent "${AGENT}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box?access_token=${VAGRANT_CLOUD_TOKEN}" | head -1 | grep --silent --extended-regexp "HTTP/1\.1 200 OK|HTTP/2\.0 200 OK|HTTP/2 200|HTTP/1\.1 302 Found|HTTP/2.0 302 Found|HTTP/2 302 Found"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
PROVIDER="parallels"
if [[ "${ORGANIZATION}" == "generic" ]]; then
curl --head --silent --location --user-agent "${AGENT}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box?access_token=${VAGRANT_CLOUD_TOKEN}" | head -1 | grep --silent --extended-regexp "HTTP/1\.1 200 OK|HTTP/2\.0 200 OK|HTTP/2 200|HTTP/1\.1 302 Found|HTTP/2.0 302 Found|HTTP/2 302 Found"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
fi
PROVIDER="virtualbox"
curl --head --silent --location --user-agent "${AGENT}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box?access_token=${VAGRANT_CLOUD_TOKEN}" | head -1 | grep --silent --extended-regexp "HTTP/1\.1 200 OK|HTTP/2\.0 200 OK|HTTP/2 200|HTTP/1\.1 302 Found|HTTP/2.0 302 Found|HTTP/2 302 Found"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
PROVIDER="vmware_desktop"
curl --head --silent --location --user-agent "${AGENT}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box?access_token=${VAGRANT_CLOUD_TOKEN}" | head -1 | grep --silent --extended-regexp "HTTP/1\.1 200 OK|HTTP/2\.0 200 OK|HTTP/2 200|HTTP/1\.1 302 Found|HTTP/2.0 302 Found|HTTP/2 302 Found"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
done
# Get the totla number of boxes.
let TOTAL=${FOUND}+${MISSING}
let FOUND=${TOTAL}-${MISSING}
# Let the user know how many boxes were missing.
if [ $MISSING -eq 0 ]; then
printf "\nAll ${TOTAL} of the boxes are available...\n\n"
else
printf "\nOf the ${TOTAL} boxes defined, and ${FOUND} are privately available, while ${MISSING} are unavailable...\n\n"
fi
}
function public() {
FOUND=0
MISSING=0
LIST=($TAGS)
FILTER=($FILTERED_TAGS)
# Loop through and remove the filtered tags from the list.
for ((i = 0; i < ${#FILTER[@]}; ++i)); do
LIST=(${LIST[@]//${FILTER[$i]}})
done
for ((i = 0; i < ${#LIST[@]}; ++i)); do
ORGANIZATION=`echo ${LIST[$i]} | awk -F'/' '{print $1}'`
BOX=`echo ${LIST[$i]} | awk -F'/' '{print $2}'`
PROVIDER="docker"
if [[ "${ORGANIZATION}" =~ ^(generic|roboxes|lavabit)$ ]]; then
if [[ "${BOX}" == "centos6" ]] || [[ "${BOX}" == "centos7" ]] || [[ "${BOX}" == "centos8" ]] || \
[[ "${BOX}" == "rhel6" ]] || [[ "${BOX}" == "rhel7" ]] || [[ "${BOX}" == "rhel8" ]] || \
[[ "${BOX}" == "oracle7" ]] || [[ "${BOX}" == "oracle8" ]] || \
[[ "${BOX}" == "magma" ]] || [[ "${BOX}" == "magma-centos" ]] || \
[[ "${BOX}" == "magma-centos6" ]] || [[ "${BOX}" == "magma-centos7" ]]; then
curltry ${CURL} --head --fail --silent --location --user-agent "${AGENT}" --output /dev/null --write-out "%{http_code}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box" | grep --silent "200"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
fi
fi
PROVIDER="hyperv"
curltry ${CURL} --head --fail --silent --location --user-agent "${AGENT}" --output /dev/null --write-out "%{http_code}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box" | grep --silent "200"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
PROVIDER="libvirt"
curltry ${CURL} --head --fail --silent --location --user-agent "${AGENT}" --output /dev/null --write-out "%{http_code}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box" | grep --silent "200"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
PROVIDER="parallels"
if [[ "${ORGANIZATION}" =~ ^(generic|roboxes)$ ]]; then
curltry ${CURL} --head --fail --silent --location --user-agent "${AGENT}" --output /dev/null --write-out "%{http_code}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box" | grep --silent "200"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
fi
PROVIDER="virtualbox"
curltry ${CURL} --head --fail --silent --location --user-agent "${AGENT}" --output /dev/null --write-out "%{http_code}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box" | grep --silent "200"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
PROVIDER="vmware_desktop"
curltry ${CURL} --head --fail --silent --location --user-agent "${AGENT}" --output /dev/null --write-out "%{http_code}" "https://app.vagrantup.com/${ORGANIZATION}/boxes/${BOX}/versions/${VERSION}/providers/${PROVIDER}.box" | grep --silent "200"
if [ $? != 0 ]; then
let MISSING+=1
printf "Box - "; tput setaf 1; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
else
let FOUND+=1
printf "Box + "; tput setaf 2; printf "${LIST[$i]} ${PROVIDER}\n"; tput sgr0
fi
done
# Get the totla number of boxes.
let TOTAL=${FOUND}+${MISSING}
let FOUND=${TOTAL}-${MISSING}
# Let the user know how many boxes were missing.
if [ $MISSING -eq 0 ]; then
printf "\nAll ${TOTAL} of the boxes are available...\n\n"
else
printf "\nOf the ${TOTAL} boxes defined, ${FOUND} are publicly available, while ${MISSING} are unavailable...\n\n"
fi
}
function ppublic() {
FOUND=0
MISSING=0
LIST=($TAGS)
FILTER=($FILTERED_TAGS)
# Loop through and remove the filtered tags from the list.
for ((i = 0; i < ${#FILTER[@]}; ++i)); do
LIST=(${LIST[@]//${FILTER[$i]}})
done
for ((i = 0; i < ${#LIST[@]}; ++i)); do
ORGANIZATION=`echo ${LIST[$i]} | awk -F'/' '{print $1}'`
BOX=`echo ${LIST[$i]} | awk -F'/' '{print $2}'`
PROVIDER="docker"
if [[ "${ORGANIZATION}" =~ ^(generic|roboxes|lavabit)$ ]]; then
if [[ "${BOX}" == "centos6" ]] || [[ "${BOX}" == "centos7" ]] || [[ "${BOX}" == "centos8" ]] || \
[[ "${BOX}" == "rhel6" ]] || [[ "${BOX}" == "rhel7" ]] || [[ "${BOX}" == "rhel8" ]] || \
[[ "${BOX}" == "oracle7" ]] || [[ "${BOX}" == "oracle8" ]] || \
[[ "${BOX}" == "magma" ]] || [[ "${BOX}" == "magma-centos" ]] || \
[[ "${BOX}" == "magma-centos6" ]] || [[ "${BOX}" == "magma-centos7" ]]; then
O=( "${O[@]}" "${ORGANIZATION}" ); B=( "${B[@]}" "${BOX}" ); P=( "${P[@]}" "${PROVIDER}" ); V=( "${V[@]}" "${VERSION}" );
fi
fi
PROVIDER="hyperv"
O=( "${O[@]}" "${ORGANIZATION}" ); B=( "${B[@]}" "${BOX}" ); P=( "${P[@]}" "${PROVIDER}" ); V=( "${V[@]}" "${VERSION}" );
PROVIDER="libvirt"
O=( "${O[@]}" "${ORGANIZATION}" ); B=( "${B[@]}" "${BOX}" ); P=( "${P[@]}" "${PROVIDER}" ); V=( "${V[@]}" "${VERSION}" );
PROVIDER="parallels"
if [[ "${ORGANIZATION}" =~ ^(generic|roboxes)$ ]]; then
O=( "${O[@]}" "${ORGANIZATION}" ); B=( "${B[@]}" "${BOX}" ); P=( "${P[@]}" "${PROVIDER}" ); V=( "${V[@]}" "${VERSION}" );
fi
PROVIDER="virtualbox"
O=( "${O[@]}" "${ORGANIZATION}" ); B=( "${B[@]}" "${BOX}" ); P=( "${P[@]}" "${PROVIDER}" ); V=( "${V[@]}" "${VERSION}" );
PROVIDER="vmware_desktop"
O=( "${O[@]}" "${ORGANIZATION}" ); B=( "${B[@]}" "${BOX}" ); P=( "${P[@]}" "${PROVIDER}" ); V=( "${V[@]}" "${VERSION}" );
done
export -f curltry ; export -f verify_availability ; export CURL ;
# parallel --jobs 16 --keep-order --xapply verify_availability {1} {2} {3} {4} ":::" "${O[@]}" ":::" "${B[@]}" ":::" "${P[@]}" ":::" "${V[@]}"
parallel --jobs 4 --keep-order --line-buffer --xapply verify_availability {1} {2} {3} {4} '||' let MISSING+=1 ":::" "${O[@]}" ":::" "${B[@]}" ":::" "${P[@]}" ":::" "${V[@]}"
# Get the totla number of boxes.
let TOTAL=${#B[@]}
let FOUND=${TOTAL}-${MISSING}
# Let the user know how many boxes were missing.
if [ $MISSING -eq 0 ]; then
printf "\nAll ${TOTAL} of the boxes are available...\n\n"
else
printf "\nOf the ${TOTAL} boxes defined, ${FOUND} are publicly available, while ${MISSING} are unavailable...\n\n"
fi
}
function grab() {
URL=`curl --fail --silent --location --user-agent "${AGENT}" "https://app.vagrantup.com/api/v1/box/$1/$2" \
| jq -r -c "[ .versions[] | .providers[] | select( .name | contains(\"$3\")) | .download_url ][0]" 2>/dev/null`
if [ "$URL" == "" ]; then
printf "\nA copy of " ; tput setaf 1 ; printf "$1/$2" ; tput sgr0 ; printf " using the provider " ; tput setaf 1 ; printf "$3" ; tput sgr0 ; printf " couldn't be found.\n\n"
return 0
fi
CHECKSUM=`curl --fail --silent --location --user-agent "${AGENT}" "https://app.vagrantup.com/api/v1/box/$1/$2" \
| jq -r -c "[ .versions[] | .providers[] | select( .name | contains(\"$3\")) | .checksum ][0]" 2>/dev/null`
if [ ! -d "$BASE/output/" ]; then
mkdir "$BASE/output/"
fi
curl --fail --location --user-agent "${AGENT}" --output "$BASE/output/$1-$2-$3-$VERSION.box" "$URL"
if [ "$?" == 0 ]; then
( cd output ; printf "$CHECKSUM\t$1-$2-$3-$VERSION.box" | sha256sum --check --status )
if [ "$?" != 0 ]; then
rm --force "$BASE/output/$1-$2-$3-$VERSION.box"
printf "\nThe hash check for " ; tput setaf 1 ; printf "$1/$2" ; tput sgr0 ; printf " with the provider " ; tput setaf 1 ; printf "$3" ; tput sgr0 ; printf " failed.\n\n"
return 0
fi
( cd output ; sha256sum "$1-$2-$3-$VERSION.box" | sed -E "s/(.{64}) (.*)/\1\t\2/g" ) > "$BASE/output/$1-$2-$3-$VERSION.box.sha256"
else
rm --force "$BASE/output/$1-$2-$3-$VERSION.box"
printf "\nDownloading " ; tput setaf 1 ; printf "$1/$2" ; tput sgr0 ; printf " with the provider " ; tput setaf 1 ; printf "$3" ; tput sgr0 ; printf " failed.\n\n"
return 0
fi
}