forked from art-daq/artdaq-daqinterface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_me
More file actions
390 lines (268 loc) · 11.2 KB
/
source_me
File metadata and controls
390 lines (268 loc) · 11.2 KB
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
######################### DO NOT MODIFY THIS FILE #########################
# JCF, Aug-27-2019
# This sourcefile needs to be sourced before running DAQInterface.
# Consequences of sourcing are:
#
# * An alias is created so the command "DAQInterface" will run DAQInterface
#
# * The output of a DAQInterface session will be saved in a logfile
# referred to by $DAQINTERFACE_LOGFILE
#
# * A user-defined sourcefile referred to by
# $DAQINTERFACE_USER_SOURCEFILE will also be sourced - see below
# under "Requirements" for more on this
# Requirements to be met before the sourcing are:
#
# * DAQInterface needs to have been successfully set up as a ups product
#
# * The sourcefile has not yet been sourced successfully in the
# environment
#
# * The user-defined sourcefile name needs be referred to
# by the environment variable $DAQINTERFACE_USER_SOURCEFILE. The
# user-defined sourcefile must actually be owned by the active user
# in the environment ($USER), and within its body it must export an
# environment variable called "DAQINTERFACE_USER_SOURCEFILE_ERRNO"
# and set it to 0 to let this "parent" sourcefile know that the user
# sourcefile was sourced correctly. It also needs to set DAQINTERFACE_SETTINGS
# and DAQINTERFACE_KNOWN_BOARDREADERS_LIST.
######################################################################
###############TESTS WHICH CAN BE RUN ON THIS SCRIPT##################
# Tests DAQInterface developers can run on this script include:
# -Make sure this script can't be edited without changing its permissions
# -Make sure you can't source this script again in the same environment
# after it's been successfully sourced
# -Make sure you can't source this script from within its own
# directory (most likely risk is someone doesn't bother setting up a
# separate DAQInterface working area and instead tries to run out
# of the git repo area)
# -Make sure DAQINTERFACE_PROCESS_MANAGEMENT_METHOD,
# DAQINTERFACE_LOGDIR, DAQINTERFACE_PARTITION_NUMBER and
# DAQINTERFACE_FHICL_DIRECTORY all have reasonable defaults
# -And that if users in their $DAQINTERFACE_USER_SOURCEFILE script
# override DAQINTERFACE_PROCESS_MANAGEMENT_METHOD,
# DAQINTERFACE_LOGDIR, DAQINTERFACE_PARTITION_NUMBER and
# DAQINTERFACE_FHICL_DIRECTORY, that these variables get picked up
# -Make sure that typing "DAQInterface" after a successful sourcing of
# this script launches DAQInterface, and that it uses the environment
# variable values you expect
# -Make sure this script fails if DAQINTERFACE_USER_SOURCEFILE isn't
# the name of an existing file (including failure if the
# now-deprecated "IGNORED" value is chosen)
# -Make sure this script fails if the owner of
# $DAQINTERFACE_USER_SOURCEFILE isn't the current user
# -Make sure this script doesn't set up the DAQInterface environment if
# $DAQINTERFACE_USER_SOURCEFILE doesn't set an environment variable
# DAQINTERFACE_USER_SOURCEFILE_ERRNO to 0
# -Make sure this script fails if DAQINTERFACE_SETTINGS or
# DAQINTERFACE_KNOWN_BOARDREADERS_LIST doesn't get defined in
# $DAQINTERFACE_USER_SOURCEFILE, or if they're defined in
# $DAQINTERFACE_USER_SOURCEFILE but don't refer to files which exist
#########################END OF LIST OF TESTS#########################
# JCF, Aug-2-2019
# Guard against attempts to edit this file
chmod 444 $ARTDAQ_DAQINTERFACE_DIR/source_me > /dev/null 2>&1
function cleanup() {
export PATH=$( echo $PATH | sed -r 's!'${ARTDAQ_DAQINTERFACE_DIR}/bin':*!!' )
unset DAQINTERFACE_LOGDIR
unset DAQINTERFACE_LOGFILE
unset DAQINTERFACE_USER_SOURCEFILE_ERRNO
unset DAQINTERFACE_STANDARD_SOURCEFILE_SOURCED
unset DAQINTERFACE_TTY
unset DAQINTERFACE_PORT
unalias DAQInterface
cat<<EOF
n.b. As there's no guarantee your environment is the same as before
this unsucessful source attempt, it's recommended you enter a clean
environment (e.g., log out and then back in) before attempting to
source this script again.
EOF
}
if [[ -n $DAQINTERFACE_STANDARD_SOURCEFILE_SOURCED ]]; then
echo "You appear to have already sourced this script in this shell; will do nothing"
return 1
fi
if [[ -n $ARTDAQ_DAQINTERFACE_VERSION ]] ; then
echo "Using ups-installed DAQInterface, version \"$ARTDAQ_DAQINTERFACE_VERSION\""
else
echo "DAQInterface does not appear to have been set up as a ups product; will do nothing"
return 1
fi
if [[ "$PWD" == "$ARTDAQ_DAQINTERFACE_DIR" ]]; then
cat<<EOF
You appear to be trying to source this script within its own directory
(i.e., within either the ups product directory or the git repo);
please read the DAQInterface Manual at
https://cdcvs.fnal.gov/redmine/projects/artdaq-utilities/wiki/Artdaq-daqinterface
to learn how to properly set up the DAQInterface environment.
EOF
return 1
fi
# Eric F: "I hacked all my code on a host with no name"
if [[ -z $HOSTNAME ]]; then
echo
echo -n "HOSTNAME not defined, will define it here as "
export HOSTNAME=$( hostname )
echo "\"$HOSTNAME\""
echo
fi
export DAQINTERFACE_TTY=$( tty | sed -r 's!/dev/!!' )
if ! [[ "$DAQINTERFACE_TTY" =~ pts/[0-9]+ ]]; then
cat<<EOF >&2
WARNING: unable to determine tty. While this will not affect
actual datataking, any DAQInterface launched in this environment
may have problems with sending output to a MessageViewer instance
EOF
fi
if [[ -z $ARTDAQ_BASE_PORT ]]; then
export ARTDAQ_BASE_PORT=10000
fi
if [[ -z $ARTDAQ_PORTS_PER_PARTITION ]]; then
export ARTDAQ_PORTS_PER_PARTITION=1000
fi
alias DAQInterface="$ARTDAQ_DAQINTERFACE_DIR/bin/DAQInterface.sh"
export PATH=$ARTDAQ_DAQINTERFACE_DIR/bin:$PATH
if [[ -n $DAQINTERFACE_USER_SOURCEFILE ]]; then
if [[ "$DAQINTERFACE_USER_SOURCEFILE" != "IGNORED" && -e $DAQINTERFACE_USER_SOURCEFILE ]]; then
user_sourcefile_owner=$( ls -l $DAQINTERFACE_USER_SOURCEFILE | awk '{print $3}' )
if [[ "$user_sourcefile_owner" == "$USER" ]]; then
. $DAQINTERFACE_USER_SOURCEFILE
else
cat<<heredoc
ERROR: Current user "$USER" is not the same as the owner of
${DAQINTERFACE_USER_SOURCEFILE}; source of
$DAQINTERFACE_USER_SOURCEFILE will not take place
heredoc
cleanup
return 1
fi
elif [[ "$DAQINTERFACE_USER_SOURCEFILE" != "IGNORED" && ! -e $DAQINTERFACE_USER_SOURCEFILE ]]; then
cat<<heredoc
ERROR: DAQINTERFACE_USER_SOURCEFILE environment variable has been
set, but the would-be sourcefile it refers to,
"$DAQINTERFACE_USER_SOURCEFILE", doesn't exist.
heredoc
cleanup
return 1
else # $DAQINTERFACE_USER_SOURCEFILE == IGNORED, so we don't source a user-defined script
cat<<EOF
ERROR: DAQINTERFACE_USER_SOURCEFILE environment variable has
been set to "IGNORED"; while previously this meant that this
script would not source a user-defined script referred to by
the DAQINTERFACE_USER_SOURCEFILE variable, this option is now
deprecated
EOF
cleanup
return 1
fi
else
cat<<heredoc
ERROR: the DAQINTERFACE_USER_SOURCEFILE environment variable
must be set, either to the name of the user-defined sourcefile
you wish to have sourced, or to "IGNORED" if you don't want to
source a user-defined sourcefile
heredoc
cleanup
return 1
fi
if [[ -z $DAQINTERFACE_USER_SOURCEFILE_ERRNO ]] ; then
cat<<heredoc
ERROR: the DAQINTERFACE_USER_SOURCEFILE_ERRNO environment
variable doesn't exist; this needs to be set in the user script
referred to by the DAQINTERFACE_USER_SOURCEFILE environment
variable. Setting the variable to "0" in
$DAQINTERFACE_USER_SOURCEFILE implies success, anything else
implies a failure and this script will consequently *not* set up
the DAQInterface environment.
heredoc
cleanup
return 1
elif [[ "$DAQINTERFACE_USER_SOURCEFILE_ERRNO" != "0" ]] ; then
cat<<heredoc
ERROR: the DAQINTERFACE_USER_SOURCEFILE_ERRNO environment
variable was set by the user-defined source script
"$DAQINTERFACE_USER_SOURCEFILE" with a value of
$DAQINTERFACE_USER_SOURCEFILE_ERRNO; anything nonzero is considered to be an error.
heredoc
cleanup
return 1
fi
if [[ -n $DAQINTERFACE_SETTINGS ]]; then
if [[ ! -e $DAQINTERFACE_SETTINGS ]]; then
echo "ERROR: the DAQINTERFACE_SETTINGS environment variable doesn't point to a file which exists"
cleanup
return 1
fi
export DAQINTERFACE_SETUP_FHICLCPP=$( dirname $DAQINTERFACE_SETTINGS )/.setup_fhiclcpp
else
cat<<EOF
ERROR: the environment variable DAQINTERFACE_SETTINGS hasn't been
defined in $DAQINTERFACE_USER_SOURCEFILE. Please read the DAQInterface
Manual at
https://cdcvs.fnal.gov/redmine/projects/artdaq-utilities/wiki/Artdaq-daqinterface
to learn how to properly set up the DAQInterface environment.
EOF
cleanup
return 1
fi
# At this point, set various environment variables DAQInterface needs
# to reasonable defaults if they weren't already set in
# $DAQINTERFACE_USER_SOURCEFILE - or complain if there's no reasonable
# default
if [[ -z $DAQINTERFACE_PARTITION_NUMBER ]]; then
export DAQINTERFACE_PARTITION_NUMBER=0
fi
if [[ -z $DAQINTERFACE_PROCESS_MANAGEMENT_METHOD ]]; then
export DAQINTERFACE_PROCESS_MANAGEMENT_METHOD="direct"
fi
if [[ -z $DAQINTERFACE_KNOWN_BOARDREADERS_LIST ]]; then
cat<<EOF
ERROR: the environment variable DAQINTERFACE_KNOWN_BOARDREADERS_LIST
hasn't been defined in $DAQINTERFACE_USER_SOURCEFILE. Please read the
DAQInterface Manual at
https://cdcvs.fnal.gov/redmine/projects/artdaq-utilities/wiki/Artdaq-daqinterface
to learn how to properly set up the DAQInterface environment.
EOF
cleanup
return 1
elif [[ ! -e $DAQINTERFACE_KNOWN_BOARDREADERS_LIST ]]; then
echo "ERROR: the DAQINTERFACE_KNOWN_BOARDREADERS_LIST environment variable doesn't point to a file which exists"
cleanup
return 1
fi
if [[ -z $DAQINTERFACE_FHICL_DIRECTORY ]]; then
export DAQINTERFACE_FHICL_DIRECTORY="$PWD/simple_test_config"
cat<<EOF
WARNING: the environment variable DAQINTERFACE_FHICL_DIRECTORY hasn't
been defined in $DAQINTERFACE_USER_SOURCEFILE, so we're going to
assume the default configuration area is $DAQINTERFACE_FHICL_DIRECTORY
EOF
fi
if [[ ! -e "$DAQINTERFACE_FHICL_DIRECTORY" && "$DAQINTERFACE_FHICL_DIRECTORY" != "IGNORED" ]]; then
cat<<EOF
ERROR: unable to find the FHiCL directory referred to by the
DAQINTERFACE_FHICL_DIRECTORY environment variable,
$DAQINTERFACE_FHICL_DIRECTORY
EOF
cleanup
return 1
fi
if [[ -z $DAQINTERFACE_LOGDIR ]]; then
export DAQINTERFACE_LOGDIR=/tmp/daqinterface_${USER}
fi
mkdir -p $DAQINTERFACE_LOGDIR
# If you (the developer, otherwise you shouldn't be editing this file)
# change the format of DAQINTERFACE_LOGFILE, make sure this change is
# reflected in the information message that appears after source-ing
# this script
export DAQINTERFACE_LOGFILE=$DAQINTERFACE_LOGDIR/DAQInterface_partition\${DAQINTERFACE_PARTITION_NUMBER}.log
cat<<EOF
* The command was successful
* To launch, just type "DAQInterface &" (excluding quotes, ampersand optional)
* Output will be logged in ${DAQINTERFACE_LOGDIR}/DAQInterface_partition<N>.log, where <N>
is the partition the DAQInterface instance is on
* You're encouraged to read the DAQInterface Manual at https://cdcvs.fnal.gov/redmine/projects/artdaq-utilities/wiki/Artdaq-daqinterface
EOF
echo
export DAQINTERFACE_STANDARD_SOURCEFILE_SOURCED=true
return 0