-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_nodes_file
executable file
·102 lines (83 loc) · 3 KB
/
build_nodes_file
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
#!/bin/bash
CASE_NAME=UNKNOWN
NOVNC_URL='http://mycuster/kanaka-noVNC-33e1462/vnc_auto.html'
CASE_DATA_CONFIG="case_data_config.json"
CASE_SCRIPT=$(realpath ${1:-case_config.ini})
SITE_SCRIPT=$(realpath ${2:-site_config.ini})
TileSet=${3:-defaulTS}
# get case-specifig config paths (overriding defaults)
if [ -f "${CASE_SCRIPT}" ]; then
sed -e "s@\[CASE\]@#!/bin/bash@" "${CASE_SCRIPT}" > case_config
. case_config
fi
# get site-specifig config paths (overriding defaults)
if [ -f "${SITE_SCRIPT}" ]; then
sed -e "s@\[SITE\]@#!/bin/bash@" "${SITE_SCRIPT}" > site_config
. site_config
fi
FILEPATH=./list_dockers_pass
NUM=$( wc -l ${FILEPATH}| sed -e "s}^\([0-9]*\).*}\1}" )
# NUMCOL=$( grep '"maxColumnNumber" : ' $PWD/config.js |sed -e 's&.*"maxColumnNumber" : \([0-9]*\),.*&\1&' )
# spreadX=$( grep '"X" : ' config.js | sed -e 's&.*"X" : \([0-9]*\),*\ *.*&\1&' )
# spreadY=$( grep '"Y" : ' config.js | sed -e 's&.*"Y" : \([0-9]*\),*\ *.*&\1&' )
# LARGE=$(( 1920 * 4 ))
# TOTX=$(( (110 * spreadX * NUMCOL ) / 100 ))
# NumY=$(( (110 * spreadY * LARGE ) / ( TOTX * 100 ) ))
# HIGH=$(( 1080 * 4 ))
# NUMLINE=$(( HIGH / NumY ))
# #echo "number of Columns :" $NUMCOL " number of Lines " $NUMLINE
# NUMCOL2=$(( NUMCOL / 2 ))
# NUMLINE2=$(( NUMLINE / 2 ))
# #echo "number of 1/2 Columns :" $NUMCOL2 " number of 1/2 Lines " $NUMLINE2
function min {
( [ $1 -le $2 ] && echo $1 ) || ( [ $2 -lt $1 ] && echo $2 )
}
DATE=$(date +%F_%H-%M-%S)
echo '{ "nodes": [' > nodes.json
#echo 'echo '' >> nodes.json' >> nodes.json
i=0
while IFS='' read -r line || [[ -n "$line" ]]; do
if [ X"${line}" == X"" ]; then
echo "error too old passord file."
rm -f nodes.json
exit 2
fi
i2=$((2*(i+1)))
i0=$(printf "%03d" $((i+1)))
thishost=${line% *}
pass=${line##* }
#echo ${i} ${i2} ${pass}
if [ $i -gt 0 ]; then
echo '},' >> nodes.json
fi
if [ $i -eq 0 ]; then
echo '{"title" : "master '$i0'",' >> nodes.json
else
echo '{"title" : "ANATOMIST ",' >> nodes.json
fi
echo ' "variable" : "ID-'$i0'" ,' >> nodes.json
URL=$(echo $NOVNC_URL | envsubst) # expand envars in $NOVNC_URL
echo ' "url" : "'${URL}'?autoconnect=1&host='${HTTP_FRONTEND}'&port='${SOCKETdomain}${i0}'&encrypt=1&password='${pass}'&true_color=1",' >> nodes.json
echo ' "comment" : "Comment for node '$i' from '${thishost}'",' >> nodes.json
echo ' "usersNotes" : "This is node '$i' : Docker host '${thishost}' and noVNC server '${URL}'",' >> nodes.json
tags="\"$TileSet\""
if [ $(( i + 1 )) -eq ${NUM} ]; then
tags=${tags}',"atlas"'
fi
if [ $i -eq 0 ]; then
tags='"master"'
fi
tags=${tags}',"'${thishost}'"'
echo ' "tags" : ['${tags}']' >> nodes.json
i=$(( i + 1 ))
done < list_dockers_pass
echo '}' >> nodes.json
echo '] }' >> nodes.json
echo "var text_ = " > nodes.js
cat nodes.json >> nodes.js
echo 'var jsDataTab = text_.nodes;' >> nodes.js
# allow to import customized tags
if [ -f ./patch_nodes_file_with_data.py ]; then
python ./patch_nodes_file_with_data.py -d "${CASE_DATA_CONFIG}"
fi
exit 0