-
Notifications
You must be signed in to change notification settings - Fork 0
/
editConfig.sh
executable file
·525 lines (428 loc) · 13.7 KB
/
editConfig.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
#!/bin/bash
#// Copyright (c) 2023 ZKM | Hertz-Lab (http://www.zkm.de)
#// Bernd Lintermann <[email protected]>
#//
#// BSD Simplified License.
#// For information on usage and redistribution, and for a DISCLAIMER OF ALL
#// WARRANTIES, see the file, "LICENSE" in this distribution.
#//
function setDefaults()
{
[ -z ${useNodes+x} ] && useNodes=false
[ -z ${server+x} ] && server="$(hostname -I)"
[ -z ${webPort+x} ] && webPort=8080
[ -z ${hubPort+x} ] && hubPort=' #5000'
[ -z ${adminPort+x} ] && adminPort=8000
[ -z ${portBase+x} ] && portBase=40
[ -z ${useServerGit+x} ] && useServerGit=false
[ -z ${blueprintImageFile+x} ] && blueprintImageFile=''
[ -z ${blueprintExtent+x} ] && blueprintExtent=''
[ -z ${blueprintSimulationFile+x} ] && blueprintSimulationFile=''
[ -z ${blueprintOcclusionFile+x} ] && blueprintOcclusionFile=''
[ -z ${blueprintObstacleImageFile+x} ] && blueprintObstacleImageFile=''
[ -z ${blueprintObstacleExtent+x} ] && blueprintObstacleExtent=''
[ -z ${dataDir+x} ] && dataDir=' #/data'
[ -z ${recordPackedDir+x} ] && recordPackedDir=' #/data/packed'
[ -z ${desktopColor+x} ] && desktopColor=505050
if [ "$conf" == "" ] ; then
if [ -f config.txt ] ; then
dir=$(pwd)
source config.txt
cd $dir
fi
else
[ -z ${desktopLabel+x} ] && desktopLabel=$conf-LIDAR
fi
}
function printValues() {
echo useNodes=$UseNodes
echo server=$server
echo webPort=$webPort
echo hubPort=$hubPort
echo adminPort=$adminPort
echo portBase=$portBase
echo useServerGit=$useServerGit
echo blueprintExtent=$blueprintExtent
echo blueprintImageFile=$blueprintImageFile
echo blueprintOcclusionFile=$blueprintOcclusionFile
echo blueprintSimulationFile=$blueprintSimulationFile
echo blueprintObstacleExtent=$blueprintObstacleExtent
echo blueprintObstacleImageFile=$blueprintObstacleImageFile
echo dataDir=$recordPackedDir
echo recordPackedDir=$dataDir
echo desktopColor=$desktopColor
echo desktopLabel=$desktopLabel
}
function printHelp() {
setDefaults
echo "usage: $0 [-h|--help] [create name|path/to/initDir] [init path/to/initDir] [list] [createRegion regionName] [+conf name] [param=value]"
echo
echo "allows to create or edit a lidar configuration file"
echo "- name is the name of the configuration (e.g. myconf)"
echo
echo "$0 create myconf"
echo "- will create a directory $(realpath -s $(dirname $0)/..)/lidarconfig-myconf with default files"
echo
echo "$0 create myconf init path/to/initDir"
echo "- will create a directory $(realpath -s $(dirname $0)/..)/lidarconfig-myconf and initialize it with the initDir content"
echo
echo "$0 create path/to/osc"
echo "- will create a directory $(realpath -s $(dirname $0)/..)/lidarconfig-osc and initialize it with the path/to/osc content"
echo
echo "$0 +conf myconf server=192.168.1.100"
echo "- will set the server ip in config.txt in directory $(realpath -s $(dirname $0)/..)/lidarconfig-myconf"
echo "- special parameter is obstaclePersons=1 or obstaclePersons=2 which sets up the obstacle image"
echo
echo "$0 createRegion regionName"
echo "- will create a region with name regionName and default geometry. It can be edited in the web ui"
echo
echo "when creating, parameters can also set via environment variables:"
echo "server=192.168.1.100 $0 create myconf"
echo "- will create a default config in directory $(realpath -s $(dirname $0)/..)/lidarconfig-myconf and set the server ip in config.txt"
echo
echo "linkConfDir=/tmp/altconf $0 create myconf"
echo "- will create a default config in directory $(realpath -s $(dirname $0)/..)/lidarconfig-myconf and link the conf dir to /tmp/altconf"
echo
echo "$0 list"
echo "- will list the variables defined in the local config.txt"
echo
exit 0
}
nonint=false
create=false
list=false
updateBlueprint=false
params=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
+h|-h|-help|--help|+help|help)
printHelp
exit 0
shift # past argument
;;
create)
conf=$2
if [ -d "$conf" ] ; then
initDir="$(pwd)/$2"
conf=$(basename "$initDir")
fi
nonint=true
shift # past argument
shift # past value
;;
init)
initDir="$(pwd)/$2"
if [ ! -d "$initDir" ] ; then
echo "error: directory \"$initDir\" does not exist !!!" 1>&2
exit 1
fi
shift # past argument
shift # past value
;;
list)
list=true
shift # past argument
;;
createRegion|setRegion)
regionName=$2
nonint=true
shift # past argument
shift # past value
break;
;;
updateBlueprint)
nonint=true
updateBlueprint=true
shift # past argument
;;
+conf)
conf=$2
shift # past argument
shift # past value
;;
nonint)
nonint=true
shift # past argument
;;
*)
var="$(echo $1 | sed 's/=.*//')"
if [ "$var" != "$1" ] ; then
params+=("$1")
nonint=true
else
printHelp
exit 1
fi
shift # past argument
;;
esac
done
setDefaults
if [ "$conf" == "" ] ; then
printHelp
exit 1
fi
if $list ; then
printValues
exit 0
fi
confDir="$(realpath -s $(dirname $0)/..)/lidarconfig-$conf"
function createConfig () {
lidarroot="$(realpath -s $(dirname $0)/..)"
echo "creating config in $confDir"
create=true
if [ "$linkConfDir" != "" ] ; then
mkdir -p "$linkConfDir"
if [ ! -L "$confDir" ] ; then
ln -s "$linkConfDir" "$confDir"
fi
else
mkdir -p "$confDir"
fi
cd "$confDir"
mkdir -p "$conf"
echo "conf=$conf" > config.txt
echo '' >> config.txt
echo "lidarroot=\"$lidarroot\"" >> config.txt
cat >> config.txt << EOL
useNodes=$useNodes
server=$server
portBase=$portBase
useServerGit=$useServerGit
webPort=$webPort
hubPort=$hubPort
adminPort=$adminPort
blueprintExtent=$blueprintExtent
blueprintImageFile=$blueprintImageFile
blueprintOcclusionFile=$blueprintOcclusionFile
blueprintSimulationFile=$blueprintSimulationFile
blueprintObstacleImageFile=$blueprintObstacleImageFile
blueprintObstacleExtent=$blueprintObstacleExtent
dataDir=$dataDir
recordPackedDir=$recordPackedDir
desktopColor=$desktopColor
desktopLabel=$desktopLabel
EOL
}
config="$confDir/config.txt"
if [ ! -f "$config" ] ; then
if $nonint ; then
answer=yes
else
read -p "create directory $confDir ? [y/N] " answer
fi
if [[ "$answer" =~ ^([Yy][Ee][Ss]|[Yy])$ ]] ; then
createConfig $conf
else
exit 0
fi
fi
source config.txt
lidartool="$lidarroot/lidartool"
lidaradmin="$lidarroot/lidaradmin"
lidarconfig="$lidarroot/lidarconfig"
cd $lidartool
if [ ! -L conf/$conf ] ; then
ln -s "$confDir/$conf" conf/.
fi
cd $confDir
$lidarconfig/setupConfig.sh
if [ ! -f sensorDB.txt ] ; then
echo "# Group Type Num NodeId Active MAC" > sensorDB.txt
echo "# example: " >> sensorDB.txt
echo "# samp ld 01 001 + xx:xx:xx:xx:xx:xx" >> sensorDB.txt
fi
if [ ! -f LidarSensors.txt ] ; then
echo "# single lines with devices, e.g. for an LD06 at /dev/ttyUSB0" > LidarSensors.txt
echo "# ld06:0" >> LidarSensors.txt
fi
if [ ! -f LidarRunMode.txt ] ; then
if $useNodes ; then
echo "simulation" > LidarRunMode.txt
else
echo "setup" > LidarRunMode.txt
fi
fi
function argValue () {
var="$(echo $1 | sed 's:=.*::')"
value=$(echo "$1" | sed "s+$var=++")
value=$(echo $value | sed 's+^[ ]*++g') # remove leading whitespace
}
function paramValue () {
line="$(grep $1= $config)"
value=$(echo "$line" | sed "s+$1=++")
if [ "$line" == "" ] ; then
line="$(grep '#'$1= $config)"
value='#'$(echo "$line" | sed "s+#$1=++")
fi
value=$(echo $value | sed 's+^[ ]*++g') # remove leading whitespace
}
function getValue () {
paramValue $1
if [ "$(echo $value | cut -c 1)" == "#" ] ; then
value=
fi
}
function putParam () {
answer="$2"
if [ "$answer" == "" ] ; then
return
fi
answer=$(echo $answer | sed 's+^[ ]*++g') # remove leading whitespace
answer=$(echo $answer | sed 's+[ ]*$++g') # remove trailing whitespace
if [ $(echo $answer | cut -c1) == "#" ] ; then
answer=" $answer"
fi
if [ "$(grep $1= $config)" == "" ] ; then
echo "# $3" >> $config
echo "$1=$answer" >> $config
echo "" >> $config
else
sed -i "s+^$1=.*+$1=$answer+" $config
fi
}
function promptParam () {
paramValue "$1"
read -p "$2 ($1=$value): " answer
putParam "$1" "$answer" "$2"
}
function updateBlueprintFiles {
getValue blueprintImageFile
imageFile="$value"
getValue blueprintExtent
bpExtent="$value"
if [ "$imageFile" != "" ] && [ "$bpExtent" != "" ] ; then
cp -n "$imageFile" $conf/.
$lidartool/lidarTool +conf $conf +setBlueprintImage "$(basename $imageFile)"
$lidartool/lidarTool +conf $conf +setBlueprintExtent "$bpExtent"
getValue blueprintSimulationFile
if [ "$value" != "" ] ; then
cp -n "$value" $conf/.
$lidartool/lidarTool +conf $conf +setBlueprintSimulationEnvMap "$(basename $value)"
fi
getValue blueprintOcclusionFile
if [ "$value" != "" ] ; then
cp -n "$value" $conf/.
$lidartool/lidarTool +conf $conf +setBlueprintTrackOcclusionMap "$(basename $value)"
fi
fi
if [ "$obstaclePersons" == "1" ] ; then
blueprintObstacleImageFile="$lidarconfig/media/obstacleSinglePerson.png"
blueprintObstacleExtent="0.7"
putParam blueprintObstacleImageFile "$blueprintObstacleImageFile" "obstacle image file"
putParam blueprintObstacleExtent "$blueprintObstacleExtent" "obstacle extent"
elif [ "$obstaclePersions" == "2" ] ; then
blueprintObstacleImageFile="$lidarconfig/media/obstacleTwoPersons.png"
blueprintObstacleExtent="2"
putParam blueprintObstacleImageFile "$blueprintObstacleImageFile" "obstacle image file"
putParam blueprintObstacleExtent "$blueprintObstacleExtent" "obstacle extent"
fi
getValue blueprintObstacleImageFile
if [ "$value" != "" ] ; then
cp -n "$value" $conf/.
$lidartool/lidarTool +conf $conf +setBlueprintObstacleImage "$(basename $value)"
fi
getValue blueprintObstacleExtent
bpObstacleExtent="$value"
if [ "$bpObstacleExtent" != "" ] ; then
$lidartool/lidarTool +conf $conf +setBlueprintObstacleExtent "$bpObstacleExtent"
fi
}
numParam=${#params[@]}
if [ $numParam -gt 0 ] ; then
for ((i=0; i < $numParam; i++))
do
param="${params[$i]}"
var="$(echo $param | sed 's:=.*::')"
if [ "$var" == "obstaclePersons" ] ; then
eval $param
elif [ "$var" == "runMode" ] ; then
argValue $param
echo "$value" > LidarRunMode.txt
else
sed -i "s:^$var=.*:$param:g" $confDir/config.txt
fi
done
fi
updateBlueprintFiles
if [ "$initDir" != "" ] ; then
GLOBIGNORE="$initDir/README.md:$initDir/*~:$initDir/.git:$initDir/.log"
echo cp -r "$initDir"/* .
cp -r "$initDir"/* .
[ -f observer.txt ] && mv observer.txt $conf/.
if [ -e init_config.sh ] ; then
echo ./init_config.sh
./init_config.sh
nonint=true
fi
fi
if [ "$regionName" != "" ] ; then
$lidartool/lidarTool +conf $conf +setRegion $regionName $@
fi
if $nonint ; then
exit
fi
promptParam useNodes "Use nodes as virtual devices ?"
source config.txt
if $useNodes ; then
promptParam server "Admin server name or IP"
promptParam portBase "prefix for virtal device ports"
promptParam useServerGit "Manage registered nodes with git ?"
fi
promptParam webPort "Port to provide graphical UI per http"
promptParam adminPort "Port to provide admin access per http"
promptParam dataDir "directory where to store data. will be checked for full disk"
promptParam recordPackedDir "directory where to record packed data. leave empty for no recording"
promptParam blueprintExtent "Extent of blueprint in Pixel=Meter"
updateBlueprintFiles
# blueprint image file name
paramValue blueprintImageFile
read -n1 -p "do you want to update the blueprint image file (blueprintImageFile=$value) ? [y/N] " answer
if [[ "$answer" =~ ^([Yy][Ee][Ss]|[Yy])$ ]] ; then
file=$(nnn -p -)
putParam blueprintImageFile "$file" "blueprint image file"
updateBlueprintFiles
fi
# blueprint simulation file name
paramValue blueprintSimulationFile
read -n1 -p "do you want to update the blueprint simulation file (blueprintSimulationFile=$value) ? [y/N] " answer
if [[ "$answer" =~ ^([Yy][Ee][Ss]|[Yy])$ ]] ; then
file=$(nnn -p -)
putParam blueprintSimulationFile "$file" "blueprint simulation file"
updateBlueprintFiles
fi
# blueprint occlusion file name
paramValue blueprintOcclusionFile
read -n1 -p "do you want to update the blueprint occlusion file (blueprintOcclusionFile=$value) ? [y/N] " answer
if [[ "$answer" =~ ^([Yy][Ee][Ss]|[Yy])$ ]] ; then
file=$(nnn -p -)
putParam blueprintOcclusionFile "$file" "blueprint occlusion file"
updateBlueprintFiles
fi
# blueprint obstacle
paramValue blueprintObstacleImageFile
read -n1 -p "do you want to update the blueprint obstacle (blueprintObstacleImageFile=$value) ? [y/N] " answer
if [[ "$answer" =~ ^([Yy][Ee][Ss]|[Yy])$ ]] ; then
echo
read -n1 -p "single or double person ? [s/D] " answer
echo
if [[ "$answer" =~ ^([Ss])$ ]] ; then
obstaclePersons="1"
else
obstaclePersons="2"
fi
updateBlueprintFiles
fi
# set desktop background for ubuntu mate
if [ "$(export | grep -i mate)" != "" ] ; then
read -n1 -p "do you want to update the desktop background (only Ubuntu MATE)? [y/N] " answer
if [[ "$answer" =~ ^([Yy][Ee][Ss]|[Yy])$ ]] ; then
promptParam desktopLabel "desktop label"
promptParam desktopColor "desktop color"
source $config
convert -size 1920x1080 -background "#$desktopColor" -fill white -gravity center -pointsize 112 -font Ubuntu label:"$desktopLabel\\nServer" $confDir/desktopBackground.jpg
dconf write "/org/mate/desktop/background/picture-filename" "'$confDir/desktopBackground.jpg'"
fi
fi