-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathi3c.sh
executable file
·2184 lines (1938 loc) · 46.1 KB
/
i3c.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
#################################################################################
#
# R&D platform in a single bash script !
#
#############################################################################################
#
# !This software is free to use & modify as long as You will preserve this copyright notice!
#
# Copyright (c) 2014-2016 Mark Bisz ([email protected])
#
########################################################################################################
#curl -s http://cbsg.sourceforge.net/cgi-bin/live | grep -Eo '^<li>.*</li>' | sed s,\</\\?li\>,,g | shuf -n 1
RED='\033[0;31m'
LRED='\033[1;31m'
LYELLOW='\033[1;93m'
LGREEN='\033[1;92m'
NC='\033[0m' # No Color
# @description echo encapsulation
# @arg noarg
function _echo(){
echo "$@"
}
#@desc set -x encapsulation
# @arg noarg
_setverbose() {
set -x
}
#
# echo filtered in verbose mode
#
_echov(){
if [ $i3cVerbose -ge 1 ]; then
echo "$@"
fi
}
_echoe(){
(>&2 echo -e "${LRED}$@${NC}")
}
_echow(){
(>&2 echo -e "${LYELLOW}$@${NC}")
}
_echoi(){
(>&2 echo -e "${LGREEN}$@${NC}")
}
_mkdir(){
mkdir -p $1
if [ -e $1 ]; then
chmod -R g+w $1
fi
return "$?"
}
#get options
# A POSIX variable
#cho "input: '$@'"
# Initialize our own variables:
i3cOutputFile=""
i3cVerbose=0
i3cShowHelp=0
declare -A i3cOpt
i3cOpt[v]=0
i3cOpt[h]=0
i3cOpt[f]=""
i3cOptStr='';
declare -A i3cOptO
declare -A i3cOptStrs
#process options
doOpt=true;
#this has to be rewritten like those:
#https://github.com/gliderlabs/docker-alpine/blob/master/builder/scripts/mkimage-alpine.bash
#repeat until we have options with optional o required assiciated arguments
while $doOpt; do
doOpt=false;
OPTIND=1 # Reset in case getopts has been used previously in the shell.
ind=0
while getopts "h?vcof:" opt; do
doOpt=false
case "$opt" in
c) shift
((ind++))
i3cOpt[c]=$1;
shift
((ind++))
doOpt=true;
#. $1;
;;
h) i3cShowHelp=1
i3cOpt[h]=1
doOpt=false;
;;
v) i3cVerbose=1
i3cOpt[v]=1
shift
((ind++))
case $1 in
*[!0-2]* | "") ;;
*)
i3cVerbose=$1;
i3cOpt[v]=$1;
shift
((ind++))
doOpt=true;
;;
esac
;;
f) i3cOutputFile=$OPTARG
i3cOpt[f]=1
doOpt=false;
;;
o) shift
((ind++))
i3cOptStr=$i3cOptStr' -o '$1;
doOpt=true;
echo 'argsgromo:'"$@"
IFS=':' read -ra ADDR <<< "$1"
if [ ${ADDR[1]+x} ]; then
oname=${ADDR[0]}
oval=${ADDR[1]}
else
IFS='=' read -ra ADDR <<< "$1"
oname=${ADDR[0]}
oval=${ADDR[1]}
fi
shift
((ind++))
i3cOptO[${oname}]=$oval;
;;
*)
#_echo "Unknown option:"$opt
i3cOpt[$opt]=1
doOpt=false;
esac
done
if [ $((OPTIND-1-$ind)) -ge 0 ]; then
shift $((OPTIND-1-$ind))
fi
[ "${1:-}" = "--" ] && shift
#xit 0
#args=("$@")
_echov "args:" "$@"
if [ $i3cVerbose -ge 2 ]; then
for var in "$@"
do
echo "$var"
done
fi
done
#cho 'i3cOptO[vFrom]'${i3cOptO[vFrom]}
if [ $i3cVerbose -ge 2 ]; then
_setverbose
fi
if [ "x${i3cOpt[c]}" != "x" ]; then
. "${i3cOpt[c]}";
fi
case "$1" in
gstorec)
git config credential.helper store
exit 0
;;
gcachec)
timeoutSec="172800"; # 2 days
if [ ! "x$2" = "x" ]; then
timeoutSec=$2
fi
git config credential.helper cache --timeout=$timeoutSec
exit 0
;;
gapi)
cat /i | ./../i3c-dev-shdoc/shdoc > ./../i3c/i3c-cli-api.md
exit 0
;;
*)
#noop
esac
#domena glowna
i3cHost=i3c.l
#host internal domain
i3cInHost=i3c.l
#host external domains
i3cExHost=i3c.h
#set from env if present
if [ "x$I3C_LOCAL_ENDPOINT" != "x" ]; then
i3cExHost=$I3C_LOCAL_ENDPOINT
fi
#i3cHostIp=$(/sbin/ip route|awk '/default/ { print $3 }');
#i3c platform root folder
i3cRoot="${I3C_ROOT}";
if [ "x${I3C_ROOT}" == "x" ]; then
#_echoe "FATAL ERROR: I3C_ROOT is not set. i3c.Cloud needs this to point to i3c working files ()."
#currently just /i3c as default & working
i3cRoot='/i3c'
fi
if [ -e $i3cRoot/.env ]; then
. $i3cRoot/.env
fi
# some defaults ...
# platform amd64/arm64/armel/armhf/i386/mips/mips64el/mipsel/ppc64el/s390x
# dpkg-architecture --query DEB_BUILD_GNU_TYPE buildpack-deps:buster
i3cPlatform=amd64
if [ "x$I3C_PLATFORM" != "x" ]; then
i3cPlatform=$I3C_PLATFORM
else
hPlatform=$(uname --m)
case "$hPlatform" in
x86_64)
i3cPlatform=amd64
;;
aarch64)
i3cPlatform=arm64
;;
esac
export I3C_PLATFORM=$i3cPlatform
fi
#i3c platform data dir (containers have access here)
i3cDataDir=$i3cRoot'/i3c.data'
#container internal data root
i3cDataRoot='/i3c'
#i3c platform secrets dir (should be unmounted after start)
i3cSecretsDir=$i3cRoot'/.secrets'
#i3c overrides dir - for local scripts overriding defaults
i3cOverridesDir=$i3cRoot'/.overrides'
#i3c platform home dir
i3cHome="${I3C_HOME}";
if [ "x${I3C_HOME}" == "x" ]; then
#_echoe "FATAL ERROR: I3C_HOME is not set. i3c.Cloud needs this to point to i3c project files (https://github.com/i3c-cloud/i3c)."
#currently just [root]/i3c as default & working
i3cHome=$i3cRoot'/i3c'; #'/i3c'
fi
#log dir (normally containers should log here into subfolders)
i3cLogDir=$i3cRoot'/i3c.log'
#platform version
i3cVersion=v0
#folder name for imagedef collections
i3cDfFolder=dockerfiles
#folder name for service collections
i3cSvcFolder=services
#default home uset for priority in path search
i3cDfHome=$i3cHome
#i3cDfDir=$i3cHome$i3cDfFolder
#user imagedef home (second priority in search)
if [ "x$I3C_UDF_HOME" = "x" ]; then
I3C_UDF_HOME=$i3cDataDir'/i3c.user'
#I3C_UDF_HOME=$i3cHome'.local'
fi
i3cUdfHome=$I3C_UDF_HOME
declare -A i3cDFHomes
declare -A i3cDFFroms
#@description autoconfigure i3c user home dir
# (currently only if imagedef folder exists
#
#@arg $1 - operation (create/readUHome/read/store)
#@arg $2 - folder
#@arg $3 - [optional] subfolder
_autoconf(){
#cho "_autoconf:$1:$2"
case "$1" in
create)
if [ -e $2 ]; then
if [ ! -e $2/.gitignore ]; then
echo "/.i3c" > $2/.gitignore
ret=$?;
if [ ! $ret -eq 0 ]; then
return $ret;
fi
fi
if [ ! -e $2/.i3c ]; then
echo "i3cVersionAD=$i3cVersion" > $2/.i3c
ret=$?;
if [ ! $ret -eq 0 ]; then
return $ret;
fi
echo "i3cRootAD=$i3cRoot" >> $2/.i3c
ret=$?;
if [ ! $ret -eq 0 ]; then
return $ret;
fi
#cho "i3cUdfHome=$2" > $2/.i3c
_mkdir $2/$i3cDfFolder
ret=$?;
if [ ! $ret -eq 0 ]; then
return $ret;
fi
if [ "x$3" != "x" ]; then
_mkdir $2/$i3cDfFolder/$3
ret=$?;
if [ ! $ret -eq 0 ]; then
return $ret;
fi
fi
return 0;
else
return 99;
fi
else
return 98;
fi
;;
readUHome)
currDir=$2;
if [ -e $currDir'/.i3c' ]; then
#. $currDir/.i3c
i3cUdfHome=$currDir
fi
;;
read)
currDir=$2;
if [ -e $currDir'/.i3c' ]; then
. $currDir/.i3c
#i3cUdfHome=$currDir
fi
;;
readOptStrs)
#cho '${i3cOptStrs[$2]}'${i3cOptStrs[$2]}
if [ "x${i3cOptStrs[$2]}" != "x" ]; then
optStr="${i3cOptStrs[$2]}";
IFS=' ' read -ra ADDR <<< "$optStr"
for K in "${!ADDR[@]}"; do
os=${ADDR[$K]};
if [ "x$os" != "x" ] && [ "$os" != "-o" ];then
IFS=':' read -ra ADDR <<< "$os"
oname=${ADDR[0]}
oval=${ADDR[1]}
if [ "x${i3cOptO[$oname]}" == "x" ]; then
i3cOptO[$oname]=$oval;
fi
fi
done
fi
#cho '$i3cOptO[vFrom]'${i3cOptO[vFrom]}
;;
#TODO: real update
store)
echo "#stored by i3c.sh version:"$i3cVersion > $i3cHome/.i3c
for K in "${!i3cDFHomes[@]}"; do
#echo $K;
#echo ${i3cDFHomes[$K]}
echo "i3cDFHomes["$K"]="${i3cDFHomes[$K]} >> $i3cHome/.i3c
done
for K in "${!i3cDFFroms[@]}"; do
#echo $K;
#echo ${i3cDFHomes[$K]}
echo "i3cDFFroms["$K"]="${i3cDFFroms[$K]} >> $i3cHome/.i3c
done
for K in "${!i3cOptStrs[@]}"; do
#echo $K;
#echo ${i3cDFHomes[$K]}
echo "i3cOptStrs["$K"]='${i3cOptStrs[$K]}'" >> $i3cHome/.i3c
done
;;
*)
echo "Unknown autoconf operation:"$1;
esac
#scho "_autoconf:end:$1"
}
currDir=$(pwd)
_autoconf readUHome $currDir
_autoconf read $i3cHome
#echo "currDir:"$currDir" udfHOme:"$i3cUdfHome;
#user folder to for saving/loading images (can grow big)
#i3cUdfDir=$i3cDataDir'/i3cd/i3c-crypto/dockerfiles'
declare -r i3cUdiFolder=.dockerimages
#this folder shared between runnig containers
#i3cUdiHome=$i3cDataDir'/i3cd'
declare -r i3cSharedFolder=.shared
#final (calculated) home dir for imagedef !tobe moved to i3cConfig
i3cDfcHome=''
#docker binary name
declare -r dockerBin='docker'
#asoc array for user configs (run-config.sh)
declare -A i3cConfig;
#processing root config scripts
_procConfig(){
if [ -e $i3cHome/i3c-config.sh ]; then
. $i3cHome/i3c-config.sh
fi
if [ -e $i3cHome.local/i3c-config.sh ]; then
. $i3cHome.local/i3c-config.sh
fi
if [ -e $i3cUdfHome/i3c-config.sh ]; then
. $i3cUdfHome/i3c-config.sh
fi
if [ -e $PWD/i3c-config.sh ]; then
. $PWD/i3c-config.sh
fi
}
_procConfig;
#homedir for saved/loaded images
i3cUdiHome=$i3cRoot
if [ ! -e $i3cUdiHome/$i3cUdiFolder ]; then
_mkdir $i3cUdiHome/$i3cUdiFolder
fi
#homedir for .shared folder
i3cSharedHome=$i3cRoot
if [ ! -e $i3cSharedHome/$i3cSharedFolder ]; then
_mkdir $i3cSharedHome/$i3cSharedFolder
fi
#@desc load an image stored in imagedef dir into local docker repo
#@arg $1 - image to load (appName)
load(){
cName=$1
scName=$(_sanitCName $cName)
doRm=''
if [ ! -e $i3cUdiHome/$i3cUdiFolder/$scName.i3ci ]; then
if [ -e $i3cUdiHome/$i3cUdiFolder/$scName.i3czi ]; then
unzip $i3cUdiHome/$i3cUdiFolder/$scName.i3czi -d $i3cUdiHome/$i3cUdiFolder
doRm=$i3cUdiHome/$i3cUdiFolder/$scName.i3ci
rm $i3cUdiHome/$i3cUdiFolder/sha256.txt
else
echo "Saved image $cName not found."
fi
fi
$dockerBin load -i $i3cUdiHome/$i3cUdiFolder/$scName.i3ci
$dockerBin tag i3c-tmp-save i3c/$cName
$dockerBin tag i3c-tmp-save i3c/$cName:v0
echo "Image loaded & tagged as i3c/$cName."
if [ "x$doRm" != "x" ]; then
rm $doRm
fi
}
#@desc save an image from local repo into imagedef dir (.i3ci)
#@arg $1 - appdef to save
save(){
cName=$1
scName=$(_sanitCName $cName)
echo "Commiting $scName ..."
$dockerBin commit $scName i3c-tmp-save
echo "Saving $i3cUdiHome/$i3cUdiFolder/$scName.i3ci ..."
$dockerBin save -o $i3cUdiHome/$i3cUdiFolder/$scName.i3ci i3c-tmp-save
}
savei(){
iName=$1
siName=$(_sanitCName $iName)
echo "Saving $i3cUdiHome/$i3cUdiFolder/$siName.i3ci ..."
$dockerBin save -o $i3cUdiHome/$i3cUdiFolder/$siName.i3ci $iName
}
#@desc save an image from local repo into imagedef dir as zipped (.i3czi)
#@arg $1 - appdef to save
savez(){
cName=$1
scName=$(_sanitCName $cName)
save "$@"
cd $i3cUdiHome/$i3cUdiFolder
sha256=$(docker inspect $scName | grep '\"Image\": \"sha256:' | cut -d '"' -f4);
echo $sha256 > sha256.txt
echo "Creating zip file $i3cUdiHome/$i3cUdiFolder/$scName.i3czi ..."
zip $scName.i3czi $scName.i3ci sha256.txt
if [ $? -eq 0 ];then
rm $i3cUdiHome/$i3cUdiFolder/$scName.i3ci
rm $i3cUdiHome/$i3cUdiFolder/sha256.txt
fi
}
saveiz(){
iName=$1
siName=$(_sanitCName $iName)
savei "$@"
cd $i3cUdiHome/$i3cUdiFolder
echo "Creating zip file $i3cUdiHome/$i3cUdiFolder/$siName.i3czi ..."
zip $siName.i3czi $siName.i3ci
if [ $? -eq 0 ];then
rm $i3cUdiHome/$i3cUdiFolder/$siName.i3ci
fi
}
_procHomes(){
#i3cScriptDir='';
#i3cDfcHome='';
line=$1;
sFile=$2;
if [ "x${i3cDFHomes[$line]}" != "x" ]; then
if [ -e ${i3cDFHomes[$line]}/$i3cDfFolder/$line/$sFile ]; then
i3cDfcHome=${i3cDFHomes[$line]}
i3cScriptDir=${i3cDFHomes[$line]}/$i3cDfFolder/$line
fi
fi
}
_procFroms(){
sFile=$1;
#scho '$cName:'$cName;
if [ "x${i3cDFFroms[$cName]}" != "x" ]; then
line="${i3cDFFroms[$cName]}";
#//ine="${line/\/i3c\//}"
if [ "x${i3cDFHomes[$line]}" != "x" ]; then
_procHomes $line $sFile;
else
echo "[procVars] ERROR: Home dir for inherited ${i3cDFFroms[$cName]} not found."
fi
fi
}
_service(){
cName=$1
if [ -e $i3cDfHome.local/$i3cSvcFolder/$cName/i3c-run.sh ]; then
i3cDfcHome=$i3cDfHome'.local'
i3cScriptDir=$i3cDfHome.local/$i3cSvcFolder/$cName
. $i3cScriptDir/i3c-run.sh $@;
else
echo "No file:$i3cDfHome.local/$i3cSvcFolder/$cName/i3c-run.sh";
exit 1;
fi
ret=$?;
return $ret;
}
#@desc processing different i3c platform config files
# (normally process 'i3c-[command].sh' files according to current priorities
#@arg $@ -some args for taget script
_procVars(){
local sCommand=$1;
#local cName=$2;
local doFirsFound=0;
local doLastFound=0;
i3cScriptDir=''
if [ "$sCommand" == 'run' ] || [ "$sCommand" == 'build' ]; then
doLastFound=1
fi
_procFroms i3c-$sCommand.sh;
if [ "x$i3cScriptDir" != "x" ]; then
if [ $doLastFound -eq 0 ]; then
. $i3cScriptDir/i3c-$sCommand.sh $@;
fi
if [ $doFirsFound -eq 1 ]; then
return 0
fi
fi
_procHomes $cName i3c-$sCommand.sh;
if [ "x$i3cScriptDir" != "x" ]; then
if [ $doLastFound -eq 0 ]; then
. $i3cScriptDir/i3c-$sCommand.sh $@;
fi
if [ $doFirsFound -eq 1 ]; then
return 0
fi
fi
if [ -e $i3cDfHome/$i3cDfFolder/$cName/i3c-$sCommand.sh ]; then
i3cDfcHome=$i3cDfHome
i3cScriptDir=$i3cDfHome/$i3cDfFolder/$cName
if [ $doLastFound -eq 0 ]; then
. $i3cScriptDir/i3c-$sCommand.sh $@;
fi
if [ $doFirsFound -eq 1 ]; then
return 0
fi
fi
if [ -e $i3cDfHome.local/$i3cDfFolder/$cName/i3c-$sCommand.sh ]; then
i3cDfcHome=$i3cDfHome'.local'
i3cScriptDir=$i3cDfHome.local/$i3cDfFolder/$cName
if [ $doLastFound -eq 0 ]; then
. $i3cScriptDir/i3c-$sCommand.sh $@;
fi
if [ $doFirsFound -eq 1 ]; then
return 0
fi
fi
if [ -e $i3cUdfHome/$i3cDfFolder/$cName/i3c-$sCommand.sh ]; then
i3cDfcHome=$i3cUdfHome
i3cScriptDir=$i3cUdfHome/$i3cDfFolder/$cName
if [ $doLastFound -eq 0 ]; then
. $i3cScriptDir/i3c-$sCommand.sh $@;
fi
if [ $doFirsFound -eq 1 ]; then
return 0
fi
fi
if [ -e $i3cUdfHome.local/$i3cDfFolder/$cName/i3c-$sCommand.sh ]; then
i3cDfcHome=$i3cUdfHome'.local'
i3cScriptDir=$i3cUdfHome.local/$i3cDfFolder/$cName
if [ $doLastFound -eq 0 ]; then
. $i3cScriptDir/i3c-$sCommand.sh $@;
fi
if [ $doFirsFound -eq 1 ]; then
return 0
fi
fi
if [ $doLastFound -eq 1 ]; then
if [ "$i3cScriptDir" != '' ]; then
. $i3cScriptDir/i3c-$sCommand.sh $@;
return 0;
fi
fi
return 1
}
_procI3cAfter(){
ret=0;
if [ -n "$(type -t i3cAfter)" ] && [ "$(type -t i3cAfter)" = function ]; then
i3cAfter "$@";
ret=$?;
unset -f i3cAfter;
fi
if [ $ret -eq 0 ]; then
if [ -e $i3cOverridesDir/$cName/i3c-$sCommand-after.sh ]; then
. $i3cOverridesDir/$cName/i3c-$sCommand-after.sh "$@"
fi
fi
return $ret;
}
_procI3cParams(){
lOpts='';
if [ "x${i3cOptO[timeSync]}" != "x" ]; then
lOpts="$lOpts -v /etc/localtime:/etc/localtime:ro";
fi
cNameSanit="$(_sanitCName $cName)"
_vHostList="$cNameSanit.$i3cInHost,$cNameSanit.$i3cExHost";
if [ "x$addVHost" != "x" ]; then
_vHostList="$_vHostList,$addVHost";
fi
if [ "x$onlyVHost" != "x" ]; then
_vHostList=$onlyVHost;
fi
secOverridesPath=" -v $i3cSecretsDir/$cName:/i3c/.secrets -v $i3cOverridesDir/$cName:/i3c/.overrides ";
if [ "$addIParams" == true ]; then
secOverridesPath=" -v $i3cSecretsDir:$i3cSecretsDir -v $i3cOverridesDir:$i3cOverridesDir ";
fi
i3cParams=" $lOpts \
-v $i3cDataDir/$cName:$i3cDataRoot/data \
-v $i3cDataDir/$cName:/data \
-v $i3cHome:/i3c/i3c \
-v $i3cLogDir/$cName:$i3cDataRoot/log \
-v $i3cLogDir/$cName:/log \
-v $i3cSharedHome/$i3cSharedFolder:/i3c/.shared \
$secOverridesPath \
-e VIRTUAL_HOST=$_vHostList \
-e I3C_ROOT=/i3c \
-e I3C_LOCAL_ENDPOINT=$I3C_LOCAL_ENDPOINT \
-e I3C_HOST=$i3cHost \
-e I3C_CNAME=$cName \
-e I3C_HOME=/i3c/i3c \
-e I3C_DATA_DIR=/data \
-e PWD_ENV=$PWD_ENV \
-e I3C_LOG_DIR=/log"
#setup default secrets
if [ -e $i3cScriptDir/i3c-secrets.sh ] && [ ! -e $i3cSecretsDir/$cName/i3c-secrets.sh ]; then
if [ ! -e $i3cSecretsDir/$cName ]; then
_mkdir $i3cSecretsDir/$cName
fi
sudo cp $i3cScriptDir/i3c-secrets.sh $i3cSecretsDir/$cName/i3c-secrets.sh
fi
if [ -e $i3cScriptDir/i3c-secrets-clean.sh ] && [ ! -e $i3cSecretsDir/$cName/i3c-secrets-clean.sh ]; then
if [ ! -e $i3cSecretsDir/$cName ]; then
_mkdir $i3cSecretsDir/$cName
fi
sudo cp $i3cScriptDir/i3c-secrets-clean.sh $i3cSecretsDir/$cName/i3c-secrets-clean.sh
fi
}
#@desc given an git repo and folder take docker imagedef for later build and pull to local repo
# !todo - option -b for automatic build and use from /i level (requires extractind _buildint from build)
#@arg $1 repo url (ie https://github.com/swagger-api)
#@arg $2 folder name inside the repo
#@example 1
# used ie in i3c-build.sh scripts:
# i3c-openapi/swagger-editor
_imageClonePullForBuild(){
appName=$2
dfFolder=$(basename $i3cDfcHome)
if [ ! -e $i3cDataDir/$dfFolder/$cName/$appName ]; then
cd $i3cDataDir
_mkdir $dfFolder
cd $dfFolder
_mkdir $cName
cd $cName
git clone --depth 1 $1/$appName.git
else
echo "folder $i3cDataDir/$dfFolder/$cName/$appName exists - pulling ..."
cd $i3cDataDir/$dfFolder/$cName/$appName
git pull
fi
i3cDfHome=$i3cDataDir/$dfFolder
i3cDfFolder=$cName
}
#not tested
_status(){
dret=$($dockerBin ps --filter "name=^/$1$" --format '{{.Names}}');
#echo "dretRunning:$dret"
[[ ! $dret ]] || { echo "running" && return; }
dret="$($dockerBin ps -a --filter "name=^/$1$" --format '{{.Names}}')";
#echo "dretExists:$dret"
[[ ! $dret ]] || { echo "exists" && return; }
echo "notFound"
}
_running(){
[ ! "$(_status $1)" == "running" ] || echo "is running"
}
#@desc given a git repo and folder name clone (or pull) sources
#@arg $1 repo url (ie https://github.com/swagger-api)
#@arg $2 target folder name (in $uData dir)
_cloneOrPull(){
appName=$cName;
folder=$i3cDataDir/$appName/$2
cdr=$(pwd)
if [ ! -e $i3cDataDir/$appName/$2 ]; then
if [ ! -e $i3cDataDir/$appName ]; then
_mkdir $i3cDataDir/$appName
fi
cd $i3cDataDir/$appName
git clone $1 $2
else
cd $i3cDataDir/$appName/$2
git pull
fi
cd $cdr
}
_db(){
docker build "$@"
}
_cloneAndBuild(){
cloneUDfAndBuild "$@"
return "$?";
}
#@desc clone given 3d party repo
#@deprecated (_cloneAndBuild)
#@arg $1 repo path
#@arg $2 dockerfile folder inside this repo (the path will be available in container under /i3c/data)
#@arg $3 image/container name/appName to build
#@arg $4 optional arg for image name if different than appName
#@alias cldb
cloneUDfAndBuild(){
doCommand=true
dCommand=$dockerBin' build'
sCommand=cldb
imP=$3
IFS='/' read -r -a arrIN <<< "$3"
appName=${arrIN[0]};
cName=$appName
iName=$3
folderWithDockerF=$i3cDataDir/$appName/$2
if [ ! -e $i3cDataDir/$appName/$2 ]; then
if [ ! -e $i3cDataDir/$appName ]; then
_mkdir $i3cDataDir/$appName
fi
cd $i3cDataDir/$appName
git clone $1
else
cd $folderWithDockerF
git pull
fi
i3cDfHome=$i3cDataDir
i3cDfFolder=$appName
iPath=$2
echo "Storing i3cDFHomes[$iName]=$i3cDfHome ...."
i3cDFHomes[$iName]=${i3cDFHomes[$cName]}
i3cOptStrs[$iName]=$i3cOptStr' -o fromDir:'$i3cDfHome'/'$i3cDfFolder'/'$iPath
_autoconf store
_build $iName
}
#@desc clone a workspace from git, build and run given git repo, imagedef/app name and also name of container to run
#@alias clur
#@arg $1 repo path (ie https://github.com/virtimus
#@arg $2 repo name (ie i3c-openapi)
#@arg $3 imagedef/containder name (ie swagger-editor)
#@example 1
# /i clur https://github.com/virtimus i3c-openapi swagger-editor
cloneUdfAndRun(){
cd $i3cRoot
if [ -e $i3cRoot/$2 ]; then
echo "Folder "$i3cRoot/$2." exists ... runing pull ..."
cd $i3cRoot/$2
git pull
else
git clone $1/$2
fi
i3cUdfHome=$i3cRoot/$2
#create local i3c autoconf
_autoconf create $i3cUdfHome
rebuild $3
rerun $3
}
cloneDfAndBuild(){
cloneUDfAndBuild "$@"
return "$?";
}
_procDCPath(){
if [ -e $i3cDfHome/$i3cDfFolder/$cName/docker-compose.yml ]; then
dfHome=$i3cDfHome
fi
if [ -e $i3cDfHome.local/$i3cDfFolder/$cName/docker-compose.yml ]; then
dfHome=$i3cDfHome'.local'
fi
if [ -e $i3cUdfHome/$i3cDfFolder/$cName/docker-compose.yml ]; then
dfHome=$i3cUdfHome
fi
if [ -e $i3cUdfHome.local/$i3cDfFolder/$cName/docker-compose.yml ]; then
dfHome=$i3cUdfHome'.local'
fi
}
#@desc run bootstrap script for current folder or from i3c.local
_bs(){
if [ -e $PWD/bootstrap/i3c-run.sh ]; then
_echoi "Running i3c/bootstrap script from $PWD/bootstrap/i3c-run.sh ..."
. $PWD/bootstrap/i3c-run.sh
else
if [ -e $I3C_ROOT/i3c.local/bootstrap/i3c-run.sh ]; then
_echoi "Running i3c/bootstrap script from $I3C_ROOT/i3c.local/bootstrap/i3c-run.sh ..."
. $I3C_ROOT/i3c.local/bootstrap/i3c-run.sh
fi
fi
}
_iup(){
cName=$1
if [[ "$(_running $cName)" ]]; then
echo "$cName is running ..."
else
_up "$@"
fi
}
#@desc up with composer (if docker-compose.yml file present)
#or try to rebuild & rerun
#@arg $1 appDef
_up(){
ret=0;
doCommand=true
cName=$1
dCommandBuild='docker-compose build '
dCommandRun='docker-compose run -d --name '$cName' '
#todo! integrate with build version
dfHome=''
_procDCPath;
uData=$i3cDataDir/$cName;
uLog=$i3cLogDir/$cName;
iName=$1;
_procConfig;
sCommand='config'
_procVars $sCommand $cName "${@:2}";
if [ -e $i3cOverridesDir/$cName/i3c-up-config.sh ]; then
. $i3cOverridesDir/$cName/i3c-up-config.sh $sCommand $cName "${@:2}"
fi
if [ "$doCommand" == false ]; then
return $?;
fi
sCommand=up
_procVars $sCommand $cName "${@:2}";
#cho "doCommand:$doCommand"
[ $doCommand == true ] || return;
#echo "up run"
#return;
#cName readonly here ?
cName=$1
if [ "x$i3cImage" = "x" ]; then
i3cImage=i3c/$iName
fi
if [ "x$iPath" = "x" ]; then
iPath=$iName
fi
if [ "x$dfHome" != "x" ]; then
if [ $doCommand == true ]; then
if [ "x$dfHome" != "x" ]; then
cd $dfHome/$i3cDfFolder/$cName
fi
sCommand=build
_procVars $sCommand $cName "${@:2}";
#cName readonly here ?
cName=$1
rd1=$?;
if [ $rd1 -ne 0 ]; then
return $rd1;
fi
if [ ${i3cOpt[v]} -le 1 ]; then
echo "$dCommandBuild $i3cParams $dParams $cName"
fi
$dCommandBuild $i3cParams $dParams $cName
ret=$?;
if [ $ret -eq 0 ]; then
sCommand=run
_procVars $sCommand $cName "${@:2}";
if [ "x$i3cParams" = "x" ]; then
_procI3cParams;
fi
#cName readonly here ?
cName=$1
if [ "x$cService" == "x" ]; then
cService=$cName;
fi
if [ ${i3cOpt[v]} -le 1 ]; then
echo "$dCommandRun $i3cParams $dParams $cService $rParams"
fi