This repository has been archived by the owner on Jan 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup_ctp7.sh
executable file
·689 lines (586 loc) · 20.8 KB
/
setup_ctp7.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
#!/bin/sh
set -o pipefail
## @file setup_ctp7.sh
## @ingroup SetupCTP7
## @author CMS GEM DAQ Project
## @copyright MIT
## @version 1.0
## @brief Script to facilitate the setup of new CTP7s, or update SW/FW on a CTP7.
## @defgroup SetupCTP7 CTP7 Setup
## @brief Use this module to help manage your CTP7.
## @details This module provides various functions related to
## setting up or updating a CTP7.
##
## @par Usage @c setup_ctp7.sh @c -h
##
## The main entry point is provided in the function @ref setup_ctp7.
## @fn cleanup_ctp7()
## @brief Remove all temporary artifacts created during execution
## @ingroup SetupCTP7
## @details Called in @c trap on
##
## @li @c EXIT
## @li @c SIGQUIT
## @li @c SIGINT
## @li @c SIGTERM
## @li @c SIGSEGV
cleanup_ctp7() {
if ! [ -n "${KEEP_ARTIFACTS}" ] && [ -n "${tmpdir}" ]
then
echo "Cleaning up ${tmpdir}"
rm -rf ${tmpdir}
else
echo "Not removing ${tmpdir}, make sure to clean up after yourself!"
fi
}
trap cleanup_ctp7 EXIT SIGQUIT SIGINT SIGTERM SIGSEGV
## @fn usage_ctp7()
## @brief Usage function for @ref setup_ctp7
## @ingroup SetupCTP7
usage_ctp7() {
cat <<EOF
Usage: $0 [options] <CTP7 hostname>
Options:
-o Update OptoHybrid FW to specified version (version 3.X.Y supported)
-c Update CTP7 FW to specified version (version 3.X.Y supported)
-g GEM station/generation options are:
1 for GE1/1 (default)
2 (alias for 22
21 for GE2/1 V1 OptoHybrid
22 for GE2/1 V2 OptoHybrid
0 for ME0
-l Number of OH links supported in the CTP7 FW (optional, if not specified defaults to 12)
-a Create the gemuser CTP7 user account
-u Update CTP7 libs/bins/fw images
-k Keep downloaded artifacts
-n Do a dry run (don't execute any commands)
-d Increase debugging information
-x XHAL SW release version (optional, if not specified, will select latest)
-m CTP7 modules SW release version (optional, if not specified, will select latest)
Plese report bugs to
https://github.com/cms-gem-daq-project/gemctp7user
EOF
# kill -INT $$
exit 1
}
### Globals
## @var CARD_GEMDAQ_DIR
## @brief location of @c gemdaq directory on CTP7
## @ingroup SetupCTP7
declare -r CARD_GEMDAQ_DIR=/mnt/persistent/gemdaq
## @var GEM_FW_DIR
## @brief location of FW files on PC
## @ingroup SetupCTP7
## @details If not set in the calling shell, use the default
## Path to local storage of bitfiles and xml files for each FW version
## Useful?
declare -rx GEM_FW_DIR=${GEM_FW_DIR:=/opt/gemdaq/fw}
## @var GEM_ADDRESS_TABLE_PATH
## @brief location of XML address table files on PC
## @ingroup SetupCTP7
## @details If not set in the calling shell, use the default
declare -rx GEM_ADDRESS_TABLE_PATH=${GEM_ADDRESS_TABLE_PATH:=/opt/cmsgemos/etc/maps}
## @var XHAL_ROOT
## @brief location of XHAL package on PC
## @ingroup SetupCTP7
## @details If not set in the calling shell, use the default
declare -rx XHAL_ROOT=${XHAL_ROOT:=/opt/xhal}
## @var tmpdir
## @brief location of temporary files
## @ingroup SetupCTP7
## @details variable is set in @ref create_tmp_card
declare tmpdir=
## @var tmpcard
## @brief location of @ref CARD_GEMDAQ_DIR inside the local @ref tmpdir
## @ingroup SetupCTP7
## @details variable is set in @ref create_tmp_card
declare tmpcard=
## @var gesuf
## @brief GEM station specific suffix for downloaded artifacts
## @ingroup SetupCTP7
declare gesuf=
## @fn create_tmp_card()
## @brief Creates a temporary directory to emulate CTP7 filesystem
## @ingroup SetupCTP7
## @details All artifacts to be pushed to a CTP7 are copied into this directory,
## which has the same structure as the CTP7 filesystem
## Upon completion or error, this temporary directory is removed in @ref cleanup_ctp7
## unless the @c KEEP_ARTIFACTS flag is set
create_tmp_card() {
if ! [ -n "${tmpcard}" ] || ! [ -d "${tmpcard}" ]
then
echo "Downloading artifacts to ${tmpdir}"
# Create a local temp structure for the artifacts
tmpdir=$(mktemp -d /tmp/tmp.XXXXXX)
# Create a local tree to mimic the card tree structure
tmpcard=${tmpdir}${CARD_GEMDAQ_DIR}
mkdir -p ${tmpcard}/{fw,oh_fw,scripts,xml,gemloader,vfat3}
else
echo "Temp area already exists at ${tmpdir}"
fi
return 0
}
## @fn update_lmdb()
## @brief Updates the LMDB on the CTP7 following update of FW
## @ingroup SetupCTP7
## @details Called if either @ref update_oh_fw or @ref update_ctp7_fw have been called
update_lmdb() {
echo "Update LMDB address table on the CTP7, make a new .pickle file and resync xml folder"
pushd ${tmpcard}/xml
${DEBUG} ${DRYRUN} set -x
${DRYRUN} rm -rf ${GEM_ADDRESS_TABLE_PATH}/amc_address_table_top.pickle
${DRYRUN} python ${XHAL_ROOT}/bin/gem_reg.py -n ${ctp7host} \
-e update_lmdb ${CARD_GEMDAQ_DIR}/xml/gem_amc_top.xml
${DRYRUN} cp -rfp ${GEM_ADDRESS_TABLE_PATH}/amc_address_table_top.pickle gem_amc_top_v${ctp7fw//./_}.pickle
${DRYRUN} perl -pi -e 's|creg_utils.reg_interface.common.reg_xml_parser|crw_reg|g' gem_amc_top_v${ctp7fw//./_}.pickle
${DRYRUN} ln -sf gem_amc_v${ctp7fw//./_}.pickle gem_amc_top.pickle
${DEBUG} ${DRYRUN} set +x
# Partially update card
${DRYRUN} rsync -ach --progress --partial --links ${tmpcard}/xml root@${ctp7host}:${CARD_GEMDAQ_DIR}/
echo "New pickle file has been copied to the CTP7, make sure you modify it correctly"
popd
return 0
}
## @fn get_gem_generation()
## @brief Determines the appropriate suffix for downloading, depending on the GEM station
## @ingroup SetupCTP7
## @details Valid options are:
## @li @c 1 for GE1/1 (default)
## @li @c 2 (alias for @c 22
## @li @c 21 for GE2/1 V1 OptoHybrid
## @li @c 22 for GE2/1 V2 OptoHybrid
## @li @c 0 for ME0
get_gem_generation() {
declare -rx ge_gen=${ge_gen:="$1"}
${DEBUG} echo ${ge_gen}
local -r genre='^([01]|(2[12]?))$'
if [ -n "${ge_gen}" ]
then
if ! [[ "${ge_gen}" =~ ${genre} ]]
then
echo "Invalid GEM generation specified ${ge_gen}"
usage
fi
if [[ "${ge_gen}" = ^21$ ]]
then
echo "Using GE2/1 OHv1"
gesuf="ge21v1_"
elif [[ "${ge_gen}" =~ "2" ]]
then
echo "Using GE2/1 OHv2"
gesuf="ge21v2_"
elif [[ "${ge_gen}" = ^0$ ]]
then
echo "Using ME0 OH"
gesuf="me0_"
else
echo "Using GE1/1 OH"
gesuf="ge11_"
fi
else
echo "Using GE1/1 OH (default)"
gesuf="ge11_"
fi
return 0
}
## @fn check_gemuser()
## @brief Checks if the @c gemuser account is present on the CTP7
## @ingroup SetupCTP7
## @details
check_gemuser() {
${DRYRUN} ssh -tq root@${ctp7host} cat /etc/passwd|egrep gemuser >/dev/null
}
## @fn create_gemuser()
## @brief Creates the @c gemuser account on the CTP7 and performs minimal user account setup
## @ingroup SetupCTP7
## @details
create_gemuser() {
if ! check_gemuser
then
while true
do
read -u 3 -r -n 1 -p "Create CTP7 user account: gemuser (y|n) : " create
case $create in
[yY]* )
${DEBUG} ${DRYRUN} set -x
${DRYRUN} ssh -tq root@${ctp7host} '/usr/sbin/adduser gemuser -h /mnt/persistent/gemuser && /bin/save_passwd'
${DRYRUN} ssh -tq gemuser@${ctp7host} 'mkdir -p ~/logs'
${DRYRUN} rsync -aXch --progress --partial --links .profile .bashrc .vimrc .inputrc gemuser@${ctp7host}:~/
${DEBUG} ${DRYRUN} set +x
break;;
[nN]* ) break;;
* )
echo
echo "Enter y or n (case insensitive)";;
esac
done 3<&0
else
echo "CTP7 user gemuser already exists"
fi
return 0
}
## @fn update_oh_fw()
## @brief Obtains the specified OptoHybrid firmware version and performs the update
## @ingroup SetupCTP7
## @details This function determines the artifact name and location
##
## @li unpacks the address table file and bitfile
## @li creates expected symlinks
## @li copies the files to the @ref tmpcard
## @li copies the address table file to the @c GEM_ADDRESS_TABLE_PATH on the PC
## @li pushes the files in @ref tmpcard to the CTP7
update_oh_fw() {
local -r ohfw="$1"
local -r ohfwre='^[3]\.[0-9]+\.[0-9]+\.(1C|C|2A)$'
declare -r OH_FW_DOWNLOAD_DIR=https://github.com/cms-gem-daq-project/OptoHybridv3/releases/download
if [[ "${ohfw}" =~ ${ohfwre} ]]
then
echo "Downloading V3 firmware with tag ${ohfw}"
create_tmp_card
pushd ${tmpdir}
${DEBUG} ${DRYRUN} set -x
${DRYRUN} curl -LO ${OH_FW_DOWNLOAD_DIR}/${ohfw%.*}.X/OH_${ohfw}.tar.gz
${DEBUG} ${DRYRUN} set +x
echo "Untar and copy firmware files and xml address table to relevant locations"
${DEBUG} ${DRYRUN} set -x
${DRYRUN} tar xvf OH_${ohfw}.tar.gz
${DRYRUN} cp -rfp OH_${ohfw}/OH_${ohfw//_/-}.bit ${tmpcard}/oh_fw/optohybrid_${ohfw}.bit
${DRYRUN} cp -rfp OH_${ohfw}/oh_registers_${ohfw}.xml ${tmpcard}/xml/oh_registers_${ohfw}.xml
${DRYRUN} ln -sf optohybrid_${ohfw}.bit ${tmpcard}/oh_fw/optohybrid_top.bit
${DRYRUN} ln -sf oh_registers_${ohfw}.xml ${tmpcard}/xml/optohybrid_registers.xml
${DRYRUN} rm -rf OH_${ohfw}*
# Update the card
${DRYRUN} rsync -ach --progress --partial --links ${tmpcard}/{oh_fw,xml} \
root@${ctp7host}:${CARD_GEMDAQ_DIR}/
# Update the PC
${DRYRUN} cp -rfp ${tmpcard}/xml/{optohybrid_registers.xml,oh_registers_${ohfw}.xml} ${GEM_ADDRESS_TABLE_PATH}/
${DEBUG} ${DRYRUN} set +x
popd
else
echo "Invalid OptoHybrid firmware version specified (${ohfw})"
echo "Valid versions usually look like X.Y.Z.C (GE1/1 long)"
echo " or X.Y.Z.1C (GE1/1 short)"
echo " or X.Y.Z.2A (GE2/1)"
usage
fi
return 0
}
## @fn update_ctp7_fw()
## @brief Obtains the specified CTP7 firmware version and performs the update
## @ingroup SetupCTP7
## @details This function determines the artifact name and location
##
## @li unpacks the address table file and bitfile
## @li creates expected symlinks
## @li copies the files to the @c tmpcard
## @li copies the address table file to the @c GEM_ADDRESS_TABLE_PATH on the PC
## @li pushes the files in @c tmpcard to the CTP7
update_ctp7_fw() {
local -r ctp7fw="$1"
local -r ctp7fwre='^[3]\.[0-9]+\.[0-9]+$'
declare -r AMC_FW_DOWNLOAD_DIR=https://github.com/cms-gem-daq-project/GEM_AMC/releases/download
declare -r AMC_FW_RAW_DIR=https://raw.githubusercontent.com/cms-gem-daq-project/GEM_AMC
if ! [[ "${ctp7fw}" =~ ${ctp7fwre} ]]
then
echo "Unsupported CTP7 FW version (${ctp7fw})"
usage
fi
local -r fwbase="v${ctp7fw//./_}_${gesuf}${nlinks}oh"
local -r fwfile="gem_ctp7_${fwbase}.bit"
create_tmp_card
pushd ${tmpcard}/fw
echo "Downloading CTP7 firmware ${fwfile}"
${DEBUG} ${DRYRUN} set -x
${DRYRUN} curl -LO ${AMC_FW_DOWNLOAD_DIR}/v${ctp7fw}/${fwfile}
${DRYRUN} ln -sf ${fwfile} gem_ctp7.bit
${DEBUG} ${DRYRUN} set +x
popd
pushd ${tmpdir}
echo "Downloading CTP7 address table address_table_${fwbase}.zip"
${DEBUG} ${DRYRUN} set -x
${DRYRUN} curl -LO ${AMC_FW_DOWNLOAD_DIR}/v${ctp7fw}/address_table_${fwbase}.zip
${DRYRUN} unzip address_table_${fwbase}.zip
${DRYRUN} rm address_table_${fwbase}.zip
${DRYRUN} cp -rfp address_table_${fwbase}/gem_amc_top_new_style.xml ${tmpcard}/xml/gem_amc_${fwbase}.xml
${DRYRUN} ln -sf gem_amc_${fwbase}.xml ${tmpcard}/xml/gem_amc_v${ctp7fw//./_}.xml
${DRYRUN} ln -sf gem_amc_v${ctp7fw//./_}.xml ${tmpcard}/xml/gem_amc_top.xml
${DRYRUN} ln -sf gem_amc_top.xml ${tmpcard}/xml/amc_address_table_top.xml
${DEBUG} ${DRYRUN} set +x
pushd address_table_${fwbase}
${DRYRUN} rename .xml _${fwbase}.xml uhal*.xml
for uh in $( ls uhal*.xml )
do
uhbase=${uh%%_v*}
${DRYRUN} ln -sf ${uh} ${uhbase}.xml
done
popd
popd
echo "Download gemloader scripts"
pushd ${tmpcard}/gemloader
declare -a gemloaderArray=(
"gemloader_clear_header.sh"
"gemloader_configure.sh"
"gemloader_load_test_data.sh"
"gemloader_read.sh"
)
for gemloaderFile in "${gemloaderArray[@]}"
do
${DEBUG} ${DRYRUN} set -x
${DRYRUN} curl -LO ${AMC_FW_RAW_DIR}/v${ctp7fw}/scripts/gemloader/${gemloaderFile}
${DEBUG} ${DRYRUN} set +x
done
popd
# Update the card
${DRYRUN} rsync -ach --progress --partial --links ${tmpcard}/{fw,gemloader,xml} \
root@${ctp7host}:${CARD_GEMDAQ_DIR}/
# Update the PC
${DRYRUN} cp -rfp ${tmpdir}/address_table_${fwbase}/uhal*.xml ${GEM_ADDRESS_TABLE_PATH}/
${DRYRUN} cp -rfp ${tmpcard}/xml/*.xml ${GEM_ADDRESS_TABLE_PATH}/
return 0
}
## @fn update_ctp7_sw()
## @brief Obtains the latest (or specified) versions of all SW artfacts for the CTP7
## @ingroup SetupCTP7
## @details This function
##
## @li determines the artifact names and locations
## @li downloads the tarballs
## @li unpacks the shared library files
## @li copies the files to the @c tmpcard
## @li pushes the files in @c tmpcard to the CTP7
##
## The packages taken include:
##
## @li @c ctp7-base.tgz : including @c ipbus, @c liblmdb.so
## @li @c reedmuller.tgz : including @c libreedmuller.so, @c rmencode, @c rmdecode
## @li @c rwreg.tgz : including @c librwreg.so
## @li @c reg_interface.tgz : including @c reg_interface
## @li @c xhal.tgz : including @c libxhal.so, @c reg_interface_gem
## @li @c ctp7_modules-${gesuf\%\%_*}\.tgz : including all CTP7 modules libraries for the specified GEM generation
update_ctp7_sw() {
local -r GEMDAQ_DOWNLOAD_URL=https://cern.ch/cmsgemdaq/sw/gemos/repos/releases/legacy/base/tarballs
echo "Creating/updating CTP7 gemdaq directory structure"
create_tmp_card
${DEBUG} ${DRYRUN} set -x
${DRYRUN} ssh -tq root@${ctp7host} "echo Setting up ${CARD_GEMDAQ_DIR} && \
mkdir -p ${CARD_GEMDAQ_DIR} && \
mkdir -p ${CARD_GEMDAQ_DIR}/address_table.mdb && \
touch ${CARD_GEMDAQ_DIR}/address_table.mdb/data.mdb && \
touch ${CARD_GEMDAQ_DIR}/address_table.mdb/lock.mdb && \
chmod -R 777 ${CARD_GEMDAQ_DIR}/address_table.mdb"
${DEBUG} ${DRYRUN} set +x
pushd scripts
gesuf=${gesuf%*_}
gesuf=${gesuf%%v*}
${DRYRUN} cp -rfp ${gesuf}/*.sh .
popd
${DRYRUN} cp -rfp -t ${tmpcard} bin lib scripts
${DRYRUN}
rm -rf ${tmpcard}/scripts/{ge11,ge21,me0}
${DRYRUN} find ${tmpcard} -type d -print0 -exec chmod a+rx {} \+ > /dev/null
${DRYRUN} find ${tmpcard} -type f -print0 -exec chmod a+r {} \+ > /dev/null
${DRYRUN} find ${tmpcard}/bin -type f -print0 -exec chmod a+rx {} \+ > /dev/null
${DRYRUN} find ${tmpcard}/lib -type f -print0 -exec chmod a+rx {} \+ > /dev/null
pushd ${tmpdir}
# Take latest versions
tarballs=(
ctp7-base.tgz
reedmuller.tgz
rwreg.tgz
reg_interface.tgz
xhal.tgz
ctp7_modules-${gesuf%%_*}.tgz
)
${DEBUG} ${DRYRUN} set -x
for tb in ${tarballs[@]}
do
if [[ "${tb}" =~ xhal ]]
then
# Override if a specific version is specified
if [ -n "${xhaltag}" ]
then
${DRYRUN} curl -L ${GEMDAQ_DOWNLOAD_URL}/xhal/xhal-${xhaltag}.tgz -o xhal.tgz
else
${DRYRUN} curl -LO ${GEMDAQ_DOWNLOAD_URL}/${tb%%.tgz*}/${tb}
fi
elif [[ "${tb}" =~ modules ]]
then
if [ -n "${ctp7modtag}" ]
then
${DRYRUN} curl -L ${GEMDAQ_DOWNLOAD_URL}/ctp7_modules/ctp7_modules-${ctp7modtag}-${gesuf%%_*}.tgz -o ctp7_modules-${gesuf%%_*}.tgz
else
${DRYRUN} curl -LO ${GEMDAQ_DOWNLOAD_URL}/ctp7_modules/${tb}
fi
else
${DRYRUN} curl -LO ${GEMDAQ_DOWNLOAD_URL}/${tb%%.tgz*}/${tb}
fi
${DRYRUN} tar xzf ${tb}
${DRYRUN} rm -rf ${tb}
done
${DEBUG} ${DRYRUN} set +x
# Obsolete?
${DEBUG} ${DRYRUN} set -x
mkdir -p ${tmpcard}/vfat3
${DRYRUN} curl -L https://raw.githubusercontent.com/cms-gem-daq-project/ctp7_modules/release/legacy-1.1/conf/conf.txt \
-o ${tmpcard}/vfat3/conf.txt
${DRYRUN} rsync -ach --progress --partial --links mnt root@${ctp7host}:/
${DRYRUN} rsync -ach --progress --partial --links ${tmpcard}/{fw,oh_fw,scripts,xml,gemloader,vfat3} \
root@${ctp7host}:${CARD_GEMDAQ_DIR}/
${DEBUG} ${DRYRUN} set +x
popd
echo "Upload rpc modules and restart rpcsvc"
${DRYRUN} ssh -tq root@${ctp7host} 'killall rpcsvc'
if check_gemuser
then
${DRYRUN} ssh -tq gemuser@${ctp7host} sh -lic 'rpcsvc'
else
echo "CTP7 gemuser account does not exist on ${ctp7host}"
usage
fi
return 0
}
## @fn setup_ctp7()
## @brief Main entrypoint
## @ingroup SetupCTP7
## @details The available flags are:
##
## @li @c -o Update OptoHybrid FW to specified version (version 3.X.Y supported)
## @li @c -c Update CTP7 FW to specified version (version 3.X.Y supported)
## @li @c -g GEM station/generation options are:
## - @c 1 for GE1/1 (default)
## - @c 2 (alias for @c 22
## - @c 21 for GE2/1 V1 OptoHybrid
## - @c 22 for GE2/1 V2 OptoHybrid
## - @c 0 for ME0
## @li @c -l Number of OH links supported in the CTP7 FW (optional, if not specified defaults to 12)
## @li @c -a Create the gemuser CTP7 user account
## @li @c -u Update CTP7 libs/bins/fw images
## @li @c -k Keep downloaded artifacts
## @li @c -n Do a dry run (don't execute any commands)
## @li @c -d Increase debugging information
## @li @c -x XHAL SW release version (optional, if not specified, will select latest)
## @li @c -m CTP7 modules SW release version (optional, if not specified, will select latest)
setup_ctp7() {
if ! ping -q -c 1 ${ctp7host}
then
echo "Unable to ping host ${ctp7host}"
usage
fi
echo "Proceeding..."
create_tmp_card
if [ -n "${ohfw}" ]
then
update_oh_fw "${ohfw}"
fi
get_gem_generation
if ! [ -n "${nlinks}" ]
then
echo "Assuming nlinks=12"
nlinks=12
fi
if [ -n "${ctp7fw}" ]
then
update_ctp7_fw "${ctp7fw}"
fi
if [ -n "${ctp7fw}" ] || [ -n "${ohfw}" ]
then
update_lmdb
fi
if [ -n "${gemuser}" ]
then
create_gemuser
fi
# Update CTP7 gemdaq paths
if [ -n "${update}" ]
then
update_ctp7_sw
fi
return 0
}
#### Option defaults
## @var ctp7fw
## @brief Update the CTP7 firmware to the specified version, script option @c -c
## @ingroup SetupCTP7
declare ctp7fw=
## @var ge_gen
## @brief GEM station/generation specifier, script option @c -g
## @ingroup SetupCTP7
declare ge_gen=
## @var nlinks
## @brief Number of OptoHybrid links to support, script option @c -n (default is 12)
## @ingroup SetupCTP7
declare nlinks=
## @var ohfw
## @brief Update the OptoHybrid firmware to the specified version, script option @c -o
## @ingroup SetupCTP7
declare ohfw=
## @var gemuser
## @brief create the @c gemuser account on the CTP7,script option @c -a
## @ingroup SetupCTP7
declare gemuser=
## @var update
## @brief Perform an update of the SW libraries on the CTP7, script option @c -u
## @ingroup SetupCTP7
declare update=
## @var xhaltag
## @brief Version number of @c xhal package, script option @c -x (default is latest)
## @ingroup SetupCTP7
declare xhaltag=
## @var ctp7modtag
## @brief Version number of CTP7 modules, script option @c -m (default is latest)
## @ingroup SetupCTP7
declare ctp7modtag=
## @var KEEP_ARTIFACTS
## @brief Keep downloaded artifacts and card temp directory after execution, script option @c -k
## @ingroup SetupCTP7
declare KEEP_ARTIFACTS=
## @var DRYRUN
## @brief Perform a dry run, i.e., don't execute any operations, script option @c -n
## @ingroup SetupCTP7
## @details If set, script will @c echo the corresponding commands
declare DRYRUN=
## @var DEBUG
## @brief Flag to increase debugging output, script option @c -d
## @ingroup SetupCTP7
declare DEBUG=:
# Parse the options
while getopts "ac:g:l:o:x:ukdnh" opts
do
case $opts in
c)
ctp7fw="$OPTARG";;
g)
ge_gen="$OPTARG";;
l)
nlinks="$OPTARG";;
o)
ohfw="$OPTARG";;
a)
gemuser="1";;
u)
update="1";;
x)
xhaltag="$OPTARG";;
m)
ctp7modtag="$OPTARG";;
k)
KEEP_ARTIFACTS="1";;
d)
DEBUG= ;;
n)
DRYRUN=echo;;
h)
usage;;
\?)
usage;;
[?])
usage;;
esac
done
shift $((OPTIND-1))
## @var ctp7host
## @brief hostname of the CTP7 to operate on, @c $1 after processing options
## @ingroup SetupCTP7
declare -r ctp7host="$1"
# Call the actual setup script
(setup_ctp7)