This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathe3.bash
executable file
·775 lines (650 loc) · 18.8 KB
/
e3.bash
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
#!/usr/bin/env bash
#
# Copyright (c) 2017 - 2019 Jeong Han Lee
# Copyright (c) 2017 - 2019 European Spallation Source ERIC
#
# The program is free software: you can redistribute
# it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of the
# License, or any newer version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see https://www.gnu.org/licenses/gpl-2.0.txt
#
#
# author : Jeong Han Lee
# email : jeonghan.lee@gmail.com
# date : Wednesday, November 27 16:59:39 CET 2019
# version : 0.7.2
GIT_URL="https://github.com/icshwi"
GIT_CMD="git clone"
declare -gr SC_SCRIPT="$(realpath "$0")"
declare -gr SC_SCRIPTNAME=${0##*/}
declare -gr SC_TOP="${SC_SCRIPT%/*}"
declare -gr SC_LOGDATE="$(date +%y%m%d%H%M)"
# We use only ONE base, and REQUIRE even if it is used as array
declare -ga base_list=("e3-base")
declare -ga require_list=("e3-require")
declare -ga module_list=()
. ${SC_TOP}/.cfgs/.e3_functions.cfg
. ${SC_TOP}/.cfgs/.e3_modules_list.cfg
function make_init2
{
git submodule update --init --recursive ;
git submodule update --remote --merge;
make checkout
}
# BASE
function init_base
{
local rep="";
for rep in ${base_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
make init || die 1 "${FUNCNAME[*]} : MAKE init ERROR at ${rep}: Please check it" ;
if [ "$ANSWER" == "YES" ]; then
make pkgs
fi
make patch || die 1 "${FUNCNAME[*]} : MAKE patch ERROR at ${rep}: Please check it" ;
make vars
popd
else
die 1 "${FUNCNAME[*]} : ${rep} doesn't exist. Please make sure \"make gbase\" first"
fi
printf "\n";
done
}
# BASE
function init2_base
{
local rep="";
local answer="$1"; shift;
for rep in ${base_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
git submodule sync
git submodule update --init --recursive
make checkout
if [ "$ANSWER" == "YES" ]; then
make pkgs
fi
make patch || die 1 "${FUNCNAME[*]} : MAKE patch ERROR at ${rep}: Please check it" ;
make vars
popd
else
die 1 "${FUNCNAME[*]} : ${rep} doesn't exist. Please make sure \"make gbase\" first"
fi
printf "\n";
done
}
# BASE
function setup_base
{
local git_status=$1; shift;
clone_base "${git_status}";
init_base;
}
# BASE
function build_base
{
local rep="";
for rep in ${base_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
make ${PARALLEL} build || die 1 "${FUNCNAME[*]} : Building Error at ${rep}: Please check the building error" ;
popd
else
die 1 "${FUNCNAME[*]} : ${rep} doesn't exist";
fi
done
}
## REQUIRE
function init_require
{
local rep="";
for rep in ${require_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
make init || die 1 "${FUNCNAME[*]} : MAKE init ERROR at ${rep}: Please check it" ;
make vars
popd
else
die 1 "${rep} doesn't exist. Please make sure \"make greq\" first"
fi
printf "\n";
done
}
## REQUIRE
function init2_require
{
local rep="";
for rep in ${require_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
make_init2 || die 1 "${FUNCNAME[*]} : MAKE init ERROR at ${rep}: Please check it" ;
make vars
popd
else
die 1 "${rep} doesn't exist. Please make sure \"make greq\" first"
fi
printf "\n";
done
}
## REQUIRE
function devinit_require
{
local rep="";
for rep in ${require_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
make devinit || die 1 "${FUNCNAME[*]} : MAKE init ERROR at ${rep}: Please check it" ;
make devvars;
popd
else
die 1 "${rep} doesn't exist. Please make sure \"make greq\" first"
fi
printf "\n";
done
}
## REQUIRE
# $1 : "TRUE" : git clone
# " : skip clone
function setup_require
{
local git_status=$1; shift;
clone_require "${git_status}" ;
init_require;
}
## REQUIRE
# $1 : "TRUE" : git clone
# " : skip clone
function devsetup_require
{
local git_status=$1; shift;
clone_require "${git_status}" ;
devinit_require;
}
## REQUIRE
function build_require
{
local rep="";
for rep in ${require_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
make -s build || die 1 "${FUNCNAME[*]} : Building Error at ${rep}: Please check the building error" ;
make -s install || die 1 "${FUNCNAME[*]} : MAKE INSTALL ERROR at ${rep}: Please check it" ;
popd
else
die 1 "${rep} doesn't exist";
fi
done
generate_setenv;
}
## REQUIRE
function devbuild_require
{
local rep="";
for rep in ${require_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
make devbuild || die 1 "${FUNCNAME[*]} : Building Error at ${rep}: Please check the building error" ;
make devinstall || die 1 "${FUNCNAME[*]} : MAKE INSTALL ERROR at ${rep}: Please check it" ;
popd
else
die 1 "${rep} doesn't exist";
fi
done
generate_setenv;
}
## init_modules and init2_modules are needed
## to be installed before.
function init_modules
{
local rep="";
# git credential cache set to 30 mins (enough) in order to minimize the same password, and username again again
# in bitbucket and gitlab.esss.se
# git config credential.helper 'cache --timeout=1800'
for rep in ${module_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
make init || die 1 "${FUNCNAME[*]} : MAKE init ERROR at ${rep}: Please check it" ;
make patch
make vars
popd
else
die 1 "${FUNCNAME[*]} : ${rep} doesn't exist. Please make sure \"make -g all gmod\" first";
fi
printf "\n";
done
# git credential exit, so we clear 30 mins cache
# git credential-cache exit
}
function init2_modules
{
local rep="";
# git credential cache set to 30 mins (enough) in order to minimize the same password, and username again again
# in bitbucket and gitlab.esss.se
# git config credential.helper 'cache --timeout=1800'
for rep in ${module_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
isItLocal=$(find -type d -name "*loc")
if [[ $(checkIfVar "${isItLocal}") -eq "NON_EXIST" ]] ; then
make_init2 || die 1 "${FUNCNAME[*]} : MAKE init ERROR at ${rep}: Please check it" ;
printf ">>>> The %s has the REMOTE sources.\n" "${rep}"
else
printf ">>>> The %s has the LOCAL sources.\n" "${rep}"
fi
make patch
make vars
popd
else
die 1 "${FUNCNAME[*]} : ${rep} doesn't exist. Please make sure \"make -g all gmod\" first";
fi
printf "\n";
done
# git credential exit, so we clear 30 mins cache
# git credential-cache exit
}
function setup_modules
{
local git_status=$1; shift;
clone_modules "${git_status}";
init_modules;
}
function build_modules
{
local rep="";
for rep in ${module_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
make -s ${PARALLEL} build || die 1 "${FUNCNAME[*]} : Building Error at ${rep}: Please check the building error" ;
make -s install || die 1 "${FUNCNAME[*]} : MAKE INSTALL ERROR at ${rep}: Please check it" ;
popd
else
die 1 "${FUNCNAME[*]} : ${rep} doesn't exist";
fi
printf "\n";
done
generate_setenv;
}
#
# module name, configure/MODULES,
# sometimes is different in EPICS_MODULE_NAME in module/configure/CONFIG
# for example, sequencer
# module name is sequencer
# EPICS_MODULE_NAME is seq
function module_loading_test_on_iocsh
{
pushd ${SC_TOP}/e3-require
make requireconf
source tools/setE3Env.bash
popd
local IOC_TEST=$(mktemp)
{
local PREFIX_MODULE="EPICS_MODULE_NAME:="
local PREFIX_LIBVERSION="E3_MODULE_VERSION:="
local mod=""
local ver=""
printf "var requireDebug 1\n";
for rep in ${module_list[@]}; do
while read line; do
if [[ $line =~ "${PREFIX_LIBVERSION}" ]] ; then
ver=${line#$PREFIX_LIBVERSION}
elif [[ $line =~ "${PREFIX_MODULE}" ]] ; then
mod=${line#$PREFIX_MODULE}
fi
done < ${SC_TOP}/${rep}/configure/CONFIG_MODULE
if [ "${mod}" = "StreamDevice" ]; then
mod="stream"
fi
if [ "${mod}" = "ethercatmc" ]; then
mod="EthercatMC"
fi
printf "#\n#\n"
printf "# >>>>> MODULE Loading ........\n";
printf "# >>>>> MODULE NAME ..... ${mod}\n";
printf "# >>>>> VER ..... ${ver}\n";
printf "require ${mod},${ver}\n";
printf "# >>>>>\n";
printf "#\n#\n"
done
} > ${IOC_TEST}
exec iocsh.bash ${IOC_TEST}
}
function generate_startup_script
{
local IOC_TEST=${SC_TOP}/.cmd
printf "Generating a startup script ... in $IOC_TEST\n";
{
local PREFIX_MODULE="EPICS_MODULE_NAME:="
local PREFIX_LIBVERSION="E3_MODULE_VERSION:="
local mod=""
local ver=""
local etherlab_lib=/opt/etherlab/lib/libethercat.so
local load_cmd="dlload"
printf "${load_cmd} ${etherlab_lib}\n";
for rep in ${module_list[@]}; do
while read line; do
if [[ $line =~ "${PREFIX_LIBVERSION}" ]] ; then
ver=${line#$PREFIX_LIBVERSION}
elif [[ $line =~ "${PREFIX_MODULE}" ]] ; then
mod=${line#$PREFIX_MODULE}
fi
done < ${SC_TOP}/${rep}/configure/CONFIG_MODULE
if [ "${mod}" = "StreamDevice" ]; then
mod="stream"
fi
if [ "${mod}" = "ethercatmc" ]; then
mod="EthercatMC"
fi
printf "require ${mod},${ver}\n";
printf "\n";
done
} > ${IOC_TEST}
}
function generate_setenv
{
local E3ENVFILE=""
local SETENV="${SC_TOP}/tools/setenv"
local modules_path=$(make -C ${SC_TOP}/e3-require/ vars |grep ^E3_MODULES_PATH | cut -f 3 -d ' ')
local module_name=$(make -C ${SC_TOP}/e3-require/ vars |grep ^E3_MODULE_NAME | cut -f 3 -d ' ')
local module_version=$(make -C ${SC_TOP}/e3-require/ vars |grep ^E3_MODULE_VERSION | cut -f 3 -d ' ')
local E3ENVFILE=${modules_path}/${module_name}/${module_version}/bin/setE3Env.bash
printf ">>\n"
if [[ $(checkIfFile "${SETENV}") -eq "EXIST" ]]; then
printf " We've found the existent %s\n" "${SETENV}"
printf " Rename it to %s\n" "${SETENV}_${SC_LOGDATE}"
printf " Still, it can be used in order to set old existent e3.\n";
mv ${SETENV} ${SETENV}_${SC_LOGDATE}
fi
printf ">>\n";
printf " Creating %s .... \n" ${SETENV}
printf " Please, source it, if one would like to activate latest installed e3.\n";
printf " source tools/setenv \n"
echo "source ${E3ENVFILE}" > ${SETENV};
}
function all_base
{
clean_base;
setup_base;
build_base;
}
function all_require
{
clean_require;
setup_require;
build_require;
}
function devall_require
{
clean_require;
devsetup_require;
devbuild_require;
}
function all_modules
{
local N="$1";shift;
clean_modules;
setup_modules;
build_modules "$N";
}
function all2_all
{
local answer="$1"; shift;
local N="$1";shift;
clean_all;
clone_all;
init2_base "${answer}";
build_base;
init2_require;
build_require;
init2_modules;
build_modules "$N";
}
function all_all
{
local answer="$1"; shift;
local N="$1";shift;
clean_all;
clone_all;
init_base "${answer}";
build_base;
init_require;
build_require;
init_modules;
build_modules "$N";
}
function configuration_update_modules
{
local rep="";
for rep in ${module_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
printf "We are updating the configuration for %s\n", "${rep}"
e3TemplateGenerator -u ${rep}
else
die 1 "${FUNCNAME[*]} : ${rep} doesn't exist";
fi
printf "\n";
done
}
function git_diff_modules
{
local rep="";
for rep in ${module_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
printf "We are updating the configuration for %s\n", "${rep}"
pushd ${rep}
git diff
popd
else
die 1 "${FUNCNAME[*]} : ${rep} doesn't exist";
fi
printf "\n";
done
}
function show_tag
{
local rep="";
local prefix="e3-";
foo=${string#"$prefix"}
for rep in ${module_list[@]}; do
if [[ $(checkIfDir "${rep}") -eq "$EXIST" ]]; then
pushd ${rep}
atag=$(git describe --tags `git rev-list --tags --max-count=1`)
printf "<project path=\"0.00.000.%s\" name=\"%s\" revision=\"refs/tags/%s\" groups=\"\" />" "${rep#"$prefix"}" "$rep" "$atag";
popd
else
die 1 "${FUNCNAME[*]} : ${rep} doesn't exist";
fi
printf "\n";
done
}
function usage
{
usage_title;
usage_mod;
{
echo " < option > ";
echo "";
echo " env : Print enabled Modules";
echo ""
echo " call : Clean all (base, require, selected module group)";
echo " gall : Clone all (base, require, selected module group)";
echo " all : call, gall, ibase, bbase, ireq, breq, imod, bmod";
echo ""
echo " cbase : Clean Base";
echo " gbase : Clone Base";
echo " ibase : Init Base ";
echo " bbase : Build, Install Base";
echo " base : cbase, gbase, ibase, bbase";
echo ""
echo " creq : Clean Require";
echo " greq : Clone Require";
echo " ireq : Init Require";
echo " breq : Build, Install Require";
echo " req : creq, greq, ireq, breq";
echo ""
echo " cmod : Clean Modules (selected module group)";
echo " gmod : Clone Modules (selected module group)";
echo " imod : Init Modules (selected module group)";
echo " bmod : Build, Install Modules (selected module group)";
echo " mod : cmod, gmod, imod, bmod";
echo ""
echo " co_base \"_check_out_name_\" : Checkout Base";
echo " co_req \"_check_out_name_\" : Checkout Require";
echo " co_mod \"_check_out_name_\" : Checkout Modules (selected module group)";
echo " co_all \"_check_out_name_\" : co_base, co_req, co_mod";
echo ""
echo " vbase : Print BASE Version Information in e3-*";
echo " vreq : Print REQUIRE Version Information in e3-*";
echo " vmod : Print MODULES Version Information in e3-*";
echo " vall : Print ALL Version Information in e3-*";
echo " vins : Print INSTALLED Version Information for locally installed e3 modules";
echo " vdep : Print module depedency names and versions.";
echo "";
echo " allall : Print ALL Version Information in e3-* by using \"make vars\"";
echo "";
echo " load : Load all installed Modules into iocsh.bash";
echo " cmd : create .cmd file in ${SC_TOP}";
echo " setenv : create setenv in ${SC_TOP}/tools";
echo "";
echo " vers : Print Source Tag / Module Versions";
echo " dep : Print DEP_VERSION information";
echo " plotdep : Plot the naive module depdendency drawing";
echo " closeplot : Close all active opened plots";
echo "";
echo " tags : Print the latest tag for a repo manifest";
echo ""
echo ""
echo ""
echo " Examples : ";
echo ""
echo " $0 creq "
echo " $0 -ctpifealb cmod";
echo " $0 -t env";
echo " $0 base";
echo " $0 req";
echo " $0 -e cmod";
echo " $0 -t load";
echo " ";
echo "";
} 1>&2;
exit 1;
}
while getopts "${options}" opt; do
case "${opt}" in
c) common="1" ;;
t) timing="1" ;;
p) psi="1" ;;
i) ifcfree="1" ;;
f) ifcnfree="1";;
e) ecat="1" ;;
a) area="1" ;;
l) llrf="1" ;;
b) bi="1" ;;
4) epicsv4="1" ;;
d) develop="1" ;;
o) only="1" ;;
*) usage ;;
esac
done
shift $((OPTIND-1)) # remove parsed options and args from $@ list
module_list_func
# print_list
case "$1" in
*mod)
echo ">> Selected Modules are :"
echo ${module_list[@]}
echo ""
;;
*all)
echo ">> Selected Modules are :"
echo ${module_list[@]}
echo ""
;;
*)
;;
esac
filter="pkg"
arg=$2
if test "${arg#*$filter}" != "$arg"; then
ANSWER="YES"
fi
filter2="para"
if test "${arg#*$filter2}" != "$arg"; then
PARALLEL="-j -l 4"
fi
case "$1" in
env) print_module_list ;;
vars) print_module_list ;;
# all : clean, clone, init, build, and all
clean) clean_all ;;
call) clean_all ;;
gall) clone_all ;;
# BASE : clean, clone, init, build, and all
cbase) clean_base ;;
gbase) clone_base ;;
ibase) init_base ;;
i2base) init2_base ;;
bbase) build_base ;;
base) all_base ;;
# REQUIRE : clean, clone, init, build, and all
creq) clean_require ;;
greq) clone_require ;;
ireq) init_require ;;
i2req) init2_require ;;
devireq) devinit_require ;;
breq) build_require ;;
req) all_require ;;
devreq) devall_require ;;
# MODULES : clean, clone, init, build, and all
cmod) clean_modules ;;
gmod) clone_modules ;;
imod) init_modules ;;
i2mod) init2_modules ;;
bmod) build_modules ;;
mod) all_modules ;;
pmod) git_pull_modules ;;
# Git Checkout
co_base) git_checkout_base "$2";;
co_req) git_checkout_require "$2";;
co_mod) git_checkout_modules "$2";;
co_all) git_checkout_all "$2";;
# GIT Commands
pull) git_pull_all ;;
add) git_add "$2" ;;
commit) git_commit "$2" ;;
push) git_push ;;
# Module Loading Test
load) module_loading_test_on_iocsh;;
# Module Loading Test Startup Script for Travis-ci
cmd) generate_startup_script;;
setenv) generate_setenv;;
# Print Version Information in e3-* directory
vbase) print_version_info_base ;;
vreq) print_version_info_require ;;
vmod) print_version_info_modules ;;
vall) print_version_info_all ;;
vins) print_installed_modules ;;
vdep) print_depend_modules ;;
# Call *make vars in each e3-* directory
allall) print_version_really_everything ;;
cupdate) configuration_update_modules ;;
gitdiff) git_diff_modules ;;
checksudo) check_sudo_permission_needed ;;
# show version and depdendcy
vers) exec_makefile_rule "vers";;
dep) exec_makefile_rule "dep";;
plotdep) exec_makefile_rule "plotdep";;
closeplot) exec_makefile_rule "closeplot";;
# show the latest tag
tags) show_tag ;;
*) usage;;
esac
exit 0;