|
1
|
#!/bin/bash
|
|
2
|
|
|
3
|
#set -x
|
|
4
|
|
|
5
|
# Default values
|
|
6
|
infile="prepare_dir.json"
|
|
7
|
keyboard="US"
|
|
8
|
pljava="FALSE"
|
|
9
|
def_p2j_entry="login.p"
|
|
10
|
def_propath=".:"
|
|
11
|
def_search_path=".:"
|
|
12
|
defdbname="hotel"
|
|
13
|
backup=false
|
|
14
|
overwrite=false
|
|
15
|
srvcerts_store="srvcerts.store"
|
|
16
|
# Environment is used for Docker containers
|
|
17
|
[ -z "$ADMIN_CONSOLE_PASSWORD" ] && admin_console_pw="test123" || admin_console_pw=$ADMIN_CONSOLE_PASSWORD
|
|
18
|
[ -z "$APP_DBADMIN_PASSWORD" ] && db_admin_pw="admin" || db_admin_pw=$APP_DBADMIN_PASSWORD
|
|
19
|
[ -z "$APP_DBUSER_PASSWORD" ] && db_user_pw="user" || db_user_pw=$APP_DBUSER_PASSWORD
|
|
20
|
[ -z "$ROOT_CA_PASSWORD" ] && root_ca_pw="password" || root_ca_pw=$ROOT_CA_PASSWORD
|
|
21
|
[ -z "$SRV_CERTS_PASSWORD" ] && srv_certs_pw="password" || srv_certs_pw=$SRV_CERTS_PASSWORD
|
|
22
|
|
|
23
|
show_usage()
|
|
24
|
{
|
|
25
|
cat <<EOF
|
|
26
|
Usage: $0 [-o]] [--admin_pw=<password>] [--db_admin_pw=<password>] [--db_user_pw=<password>] [--root_ca_pw=<password>] [--srv_certs_pw=<password>] [--backup] [-f <json_cfg_file>"]
|
|
27
|
Where:
|
|
28
|
o = Overwrite the specified directory.xml, otherwise fail
|
|
29
|
--admin_pw=<password> Password to use for the Admin Console (def=${admin_console_pw}).
|
|
30
|
--db_admin_pw=<password> Password to use for \"fwd_admin\" (def=${db_admin_pw}).
|
|
31
|
--db_user_pw=<password> Password to use for \"fwd_user\" (def=${db_user_pw}).
|
|
32
|
--root_ca_pw=<password> Password to use for Root CA (def=[${root_ca_pw}]).
|
|
33
|
--srv_certs_pw=<password> Password to use for \"${srvcerts_store}\" (def=${srv_certs_pw}).
|
|
34
|
--backup Make a backup of the directory as \"directory.xml.backup\"
|
|
35
|
f = input from [json_cfg_file] (def=\"${infile}\". To use the default, make sure this is the last parameter.)
|
|
36
|
EOF
|
|
37
|
}
|
|
38
|
|
|
39
|
# This has limited potential. It has 2 limits:
|
|
40
|
# 1) We can only have 1 argument with options
|
|
41
|
# 2) It must be at the end of the list of arguments
|
|
42
|
# Other than that, it works great.
|
|
43
|
getopts_get_optional_argument()
|
|
44
|
{
|
|
45
|
eval next_token=\${$OPTIND}
|
|
46
|
#${parameter:offset:length}
|
|
47
|
if [[ "${next_token:0:1}" = "-" ]]; then
|
|
48
|
next_token=${next_token:2}
|
|
49
|
fi
|
|
50
|
if [[ -n $next_token && $next_token != -* ]]; then
|
|
51
|
OPTIND=$((OPTIND + 1))
|
|
52
|
OPTARG=$next_token
|
|
53
|
else
|
|
54
|
OPTARG=""
|
|
55
|
fi
|
|
56
|
}
|
|
57
|
|
|
58
|
# Use this in case there are characters in the string that might be the sed delimiter
|
|
59
|
# call: escaped_hash=$(escape_sed_replacement "$admin_console_pw_hash")
|
|
60
|
# usage in sed: sed "s|{admin_console_pw}|$escaped_hash|g" template.txt
|
|
61
|
escape_sed_replacement()
|
|
62
|
{
|
|
63
|
printf '%s' "$1" | sed -e 's/[&/\]/\\&/g'
|
|
64
|
}
|
|
65
|
# Use this in case there are characters in the string that need to be replaced so they
|
|
66
|
# can be used in XML. These would be:
|
|
67
|
# '&' -> & '<' -> < '>' -> > '"' -> " ''' -> '
|
|
68
|
xml_escape()
|
|
69
|
{
|
|
70
|
local s=$1
|
|
71
|
|
|
72
|
s=${s//&/\&}
|
|
73
|
s=${s//</\<}
|
|
74
|
s=${s//>/\>}
|
|
75
|
s=${s//\"/\"}
|
|
76
|
s=${s//\'/\'}
|
|
77
|
|
|
78
|
printf '%s' "$s"
|
|
79
|
}
|
|
80
|
|
|
81
|
# Retrieve a subkey under the main group from the JSON. Allow default to be passed
|
|
82
|
function sub_getval()
|
|
83
|
{
|
|
84
|
local parent="$1" # e.g. broker1
|
|
85
|
local key="$2"
|
|
86
|
local default="$3"
|
|
87
|
local file="$4"
|
|
88
|
|
|
89
|
if val=$(_sub_getval "$parent" "$key" "$file"); then
|
|
90
|
printf '%s\n' "$val"
|
|
91
|
else
|
|
92
|
printf '%s\n' "$default"
|
|
93
|
fi
|
|
94
|
}
|
|
95
|
# Retrieve a subkey under the main group from the JSON.
|
|
96
|
function _sub_getval()
|
|
97
|
{
|
|
98
|
local parent="$1" # e.g. broker1
|
|
99
|
local key="$2" # e.g. client_xml_file
|
|
100
|
local file="$3"
|
|
101
|
local val
|
|
102
|
|
|
103
|
if [[ -z "$parent" || -z "$key" || -z "$file" ]]; then
|
|
104
|
echo "get_json_subkey: missing arguments" >&2
|
|
105
|
return 1
|
|
106
|
fi
|
|
107
|
|
|
108
|
if ! val=$(jq -er --arg p "$parent" --arg k "$key" \
|
|
109
|
'.[$p][$k]' "$file" 2>/dev/null); then
|
|
110
|
return 2 # missing key or invalid
|
|
111
|
fi
|
|
112
|
|
|
113
|
printf '%s\n' "$val"
|
|
114
|
}
|
|
115
|
|
|
116
|
# Retrieve a key from the JSON. Allow default to be passed
|
|
117
|
function getval()
|
|
118
|
{
|
|
119
|
local key="$1"
|
|
120
|
local default="$2"
|
|
121
|
local file="$3"
|
|
122
|
|
|
123
|
if val=$(_getval "$key" "$file"); then
|
|
124
|
printf '%s\n' "$val"
|
|
125
|
else
|
|
126
|
printf '%s\n' "$default"
|
|
127
|
fi
|
|
128
|
}
|
|
129
|
# Retrieve a key from the JSON.
|
|
130
|
function _getval()
|
|
131
|
{
|
|
132
|
local key="$1"
|
|
133
|
local file="$2"
|
|
134
|
local val
|
|
135
|
|
|
136
|
if ! val=$(jq -er ".$key" "$file" 2>/dev/null); then
|
|
137
|
return 2 # missing or jq error
|
|
138
|
fi
|
|
139
|
|
|
140
|
if [[ "$val" == "null" ]]; then
|
|
141
|
return 3 # explicit null
|
|
142
|
fi
|
|
143
|
|
|
144
|
printf '%s\n' "$val"
|
|
145
|
return 0
|
|
146
|
}
|
|
147
|
|
|
148
|
# Function to load list in JSON into array. Backward compatible with old string keys
|
|
149
|
# Returns: 0 - all good, even empty array if not required
|
|
150
|
# 1 - Fail, since array is empty and required
|
|
151
|
function load_array_from_json()
|
|
152
|
{
|
|
153
|
local key="$1" # e.g. "dbnames" or "parent.child.list"
|
|
154
|
local file="$2"
|
|
155
|
local -n out_array="$3" # nameref target
|
|
156
|
local required="${4:-true}" # true = must exist and non-empty
|
|
157
|
|
|
158
|
# Verify key exists
|
|
159
|
if ! jq -e "getpath([\"${key//./\",\"}\"])" "$file" >/dev/null 2>&1; then
|
|
160
|
if [[ "$required" == "true" ]]; then
|
|
161
|
echo "ERROR: Required key missing: $key" >&2
|
|
162
|
return 1
|
|
163
|
else
|
|
164
|
out_array=()
|
|
165
|
return 0
|
|
166
|
fi
|
|
167
|
fi
|
|
168
|
|
|
169
|
local type
|
|
170
|
type=$(jq -r "getpath([\"${key//./\",\"}\"]) | type" "$file")
|
|
171
|
|
|
172
|
case "$type" in
|
|
173
|
array )
|
|
174
|
mapfile -t out_array < <(
|
|
175
|
jq -r "getpath([\"${key//./\",\"}\"])[]" "$file"
|
|
176
|
)
|
|
177
|
;;
|
|
178
|
string )
|
|
179
|
local raw
|
|
180
|
raw=$(jq -r "getpath([\"${key//./\",\"}\"])" "$file")
|
|
181
|
IFS=',' read -r -a out_array <<< "$raw"
|
|
182
|
;;
|
|
183
|
null )
|
|
184
|
if [[ "$required" == "true" ]]; then
|
|
185
|
echo "ERROR: Required key is null: $key" >&2
|
|
186
|
return 1
|
|
187
|
else
|
|
188
|
out_array=()
|
|
189
|
return 0
|
|
190
|
fi
|
|
191
|
;;
|
|
192
|
* )
|
|
193
|
echo "ERROR: $key must be string or array (got $type)" >&2
|
|
194
|
return 1
|
|
195
|
;;
|
|
196
|
esac
|
|
197
|
|
|
198
|
# Enforce non-empty if required
|
|
199
|
if [[ "$required" == "true" ]] && ((${#out_array[@]} == 0)); then
|
|
200
|
echo "ERROR: Required key is empty: $key" >&2
|
|
201
|
return 1
|
|
202
|
fi
|
|
203
|
|
|
204
|
return 0
|
|
205
|
}
|
|
206
|
|
|
207
|
# Helper to perform XML directory copying
|
|
208
|
directory_copy()
|
|
209
|
{
|
|
210
|
local srcfile="$1"
|
|
211
|
local srclocation="$2"
|
|
212
|
local dstfile="$3"
|
|
213
|
local dstlocation="$4"
|
|
214
|
|
|
215
|
result=$(java -Xmx256m -classpath $p2j_jar com.goldencode.p2j.directory.DirectoryCopy copy $srcfile $srclocation $dstfile $dstlocation)
|
|
216
|
if [ ."$result". != ".." ]; then
|
|
217
|
echo "ERROR: ${result}. DirectoryCopy srcfile=$srcfile, srclocation=$srclocation, dstfile=$dstfile, dstlocation=$dstlocation"
|
|
218
|
exit 1
|
|
219
|
fi
|
|
220
|
}
|
|
221
|
|
|
222
|
hash_password()
|
|
223
|
{
|
|
224
|
local pw="$1"
|
|
225
|
|
|
226
|
hashed=$(java -classpath $p2j_jar com.goldencode.p2j.security.HashPassword $pw)
|
|
227
|
if [ ."$hashed". != ".." ]; then
|
|
228
|
echo $hashed
|
|
229
|
fi
|
|
230
|
}
|
|
231
|
|
|
232
|
# Makes key=value substitutions in the content passed in
|
|
233
|
render_memory()
|
|
234
|
{
|
|
235
|
local content="$1"
|
|
236
|
shift
|
|
237
|
local key value kv
|
|
238
|
|
|
239
|
for kv in "$@"; do
|
|
240
|
key="${kv%%=*}"
|
|
241
|
value="${kv#*=}"
|
|
242
|
content="${content//\{$key\}/$value}"
|
|
243
|
done
|
|
244
|
|
|
245
|
printf "%s" "$content"
|
|
246
|
}
|
|
247
|
|
|
248
|
# process options
|
|
249
|
while getopts "h?of-:" opt; do
|
|
250
|
case $opt in
|
|
251
|
o ) overwrite=true ;;
|
|
252
|
f ) getopts_get_optional_argument $@
|
|
253
|
infile=${OPTARG:-$infile}
|
|
254
|
;;
|
|
255
|
- ) case ${OPTARG} in
|
|
256
|
"admin_pw"* ) admin_console_pw=$(echo $OPTARG | cut -d"=" -f2) ;;
|
|
257
|
"db_admin_pw"* ) db_admin_pw=$(echo $OPTARG | cut -d"=" -f2) ;;
|
|
258
|
"db_user_pw"* ) db_user_pw=$(echo $OPTARG | cut -d"=" -f2) ;;
|
|
259
|
"root_ca_pw"* ) root_ca_pw=$(echo $OPTARG | cut -d"=" -f2) ;;
|
|
260
|
"srv_certs_pw"* ) srv_certs_pw=$(echo $OPTARG | cut -d"=" -f2) ;;
|
|
261
|
"backup" ) backup=true ;;
|
|
262
|
* ) echo "Unknown option: --${OPTARG}"
|
|
263
|
show_usage
|
|
264
|
exit 1 ;;
|
|
265
|
esac
|
|
266
|
;;
|
|
267
|
h | \
|
|
268
|
\? ) show_usage && exit 1
|
|
269
|
;;
|
|
270
|
esac
|
|
271
|
done
|
|
272
|
shift $(($OPTIND - 1))
|
|
273
|
|
|
274
|
if [ ! -f "$infile" ]; then
|
|
275
|
echo "ERROR: Input file ${infile} not found."
|
|
276
|
show_usage && exit 1
|
|
277
|
fi
|
|
278
|
|
|
279
|
# Setup p2j_jar for use in DirectoryCopy
|
|
280
|
fwd_lib=${FWD_LIB:-"../../p2j"}
|
|
281
|
if [ ! -e "$fwd_lib" ]; then
|
|
282
|
echo "ERROR: Either FWD_LIB must be set to a valid directory or ../../p2j directory must exist so as to locate p2j.jar"
|
|
283
|
exit 1
|
|
284
|
fi
|
|
285
|
p2j_jar=$([ -e "${fwd_lib}/build/lib/p2j.jar" ] && echo ${fwd_lib}/build/lib/p2j.jar || echo ${fwd_lib}/lib/p2j.jar)
|
|
286
|
p2j_jar=$([ -e "$p2j_jar" ] && echo $p2j_jar || echo ../../p2j/lib/p2j.jar)
|
|
287
|
|
|
288
|
spawner_path=$(getval "spawner_path" "/opt/spawner/spawn" $infile)
|
|
289
|
server_xml_file=$(getval "server_xml_file" "server.xml" $infile)
|
|
290
|
directory_xml_file=$(getval "directory_xml_file" "directory.xml" $infile)
|
|
291
|
client_start_dir=$(getval "client_start_dir" "./deploy/client" $infile)
|
|
292
|
dateFormat=$(getval "dateFormat" "mdy" $infile)
|
|
293
|
numberGroupSep=$(getval "numberGroupSep" "," $infile)
|
|
294
|
numberDecimalSep=$(getval "numberDecimalSep" "." $infile)
|
|
295
|
p2j_entry=$(getval "p2j_entry" "$def_p2j_entry" $infile)
|
|
296
|
pkgroot=$(getval "pkgroot" "com.goldencode.hotel" $infile)
|
|
297
|
propath=$(getval "propath" "$def_propath" $infile)
|
|
298
|
searchpath=$(getval "search_path" "$def_search_path" $infile)
|
|
299
|
path_separator=$(getval "path_separator" ":" $infile)
|
|
300
|
file_separator=$(getval "file_separator" "/" $infile)
|
|
301
|
case_sensitive=$(getval "case_sensitive" "TRUE" $infile)
|
|
302
|
user=$(getval "os_user" "$(whoami)" $infile)
|
|
303
|
keyboard=$(getval "kbd_layout" "US" $infile)
|
|
304
|
dbuser=$(getval "dbuser" "fwd_user" $infile)
|
|
305
|
dbuserpass=$(getval "dbuserpass" $db_user_pw $infile)
|
|
306
|
dbadmin=$(getval "dbadmin" "fwd_admin" $infile)
|
|
307
|
dbadminpass=$(getval "dbadminpass" $db_admin_pw $infile)
|
|
308
|
server_log=$(getval "server_log" "../logs" $infile)
|
|
309
|
client_log=$(getval "client_log" "../logs" $infile)
|
|
310
|
embedded_host=$(getval "embedded_host" "localhost" $infile)
|
|
311
|
admin_port=$(getval "admin_port" "7443" $infile)
|
|
312
|
log_rotation_limit=$(getval "log_rotation_limit" "50000000" $infile)
|
|
313
|
log_rotation_count=$(getval "log_rotation_count" "4" $infile)
|
|
314
|
client_lib_path=$(getval "client_lib_path" "../lib" $infile)
|
|
315
|
webclient_appcds_archive=$(getval "webclient_appcds_archive" "../appcds/client/default.jsa" $infile)
|
|
316
|
webclient_appcds_template=$(getval "webclient_appcds_jvmargs" "-Xshare:auto -XX:SharedArchiveFile={archive}" $infile)
|
|
317
|
if [[ "${webclient_appcds_template,,}" != "none" ]]; then
|
|
318
|
webclient_appcds_jvmargs=$(render_memory "$webclient_appcds_template" "archive=$webclient_appcds_archive")
|
|
319
|
libpath=' <node class="string" name="libPath"> \
|
|
320
|
<node-attribute name="value" value="{client_lib_path}"/> \
|
|
321
|
</node>'
|
|
322
|
libpath_rendered=$(render_memory "$libpath" "client_lib_path=$client_lib_path")
|
|
323
|
else
|
|
324
|
webclient_appcds_jvmargs=""
|
|
325
|
libpath_rendered=""
|
|
326
|
fi
|
|
327
|
webclient_memory=$(getval "webclient_memory" "1024m" $infile)
|
|
328
|
|
|
329
|
|
|
330
|
# Handle DB load. No entry implies H2 hotel DB.
|
|
331
|
if ! load_array_from_json "dbnames" "$infile" db_array false \
|
|
332
|
|| ((${#db_array[@]} == 0)); then
|
|
333
|
db_array=("$defdbname")
|
|
334
|
fi
|
|
335
|
# Default DB is first in the list (whether 1 or more)
|
|
336
|
defdatabase=${db_array[0]}
|
|
337
|
|
|
338
|
# Determine if we can now create the directory file
|
|
339
|
if [[ -f "$directory_xml_file" ]]; then
|
|
340
|
dirfile=$(realpath -e "$directory_xml_file")
|
|
341
|
else
|
|
342
|
dirfile=$(realpath -e $(dirname $directory_xml_file))/$(basename $directory_xml_file)
|
|
343
|
fi
|
|
344
|
if [ -e "$dirfile" ] && [ "$overwrite" == false ]; then
|
|
345
|
echo "ERROR: Output file ${dirfile} exists, and '-o' not specified."
|
|
346
|
show_usage && exit 9
|
|
347
|
elif [ -e "$dirfile" ] && [ "$backup" == "true" ]; then
|
|
348
|
backup_file=$dirfile
|
|
349
|
backup_file+=".backup"
|
|
350
|
cp "$dirfile" "$backup_file"
|
|
351
|
fi
|
|
352
|
if [ ! -w "$(dirname $dirfile)" ] || ([ -f "$dirfile" ] && [ ! -w "$dirfile" ]); then
|
|
353
|
if [ "$USER" != "root" ]; then
|
|
354
|
mysudo=sudo
|
|
355
|
fi
|
|
356
|
fi
|
|
357
|
|
|
358
|
# Setup the server.xml and directory.xml (if possible).
|
|
359
|
sed \
|
|
360
|
-e "s#{directory_xml_file}#$directory_xml_file#g" \
|
|
361
|
server.xml.template > $server_xml_file
|
|
362
|
rc=$?
|
|
363
|
if [ $rc -ne 0 ]; then
|
|
364
|
echo "ERROR: Could not create $server_xml_file rc=$rc"
|
|
365
|
exit $rc
|
|
366
|
fi
|
|
367
|
|
|
368
|
# Hash the admin console password
|
|
369
|
admin_console_pw_hash=$(hash_password $admin_console_pw)
|
|
370
|
if [ ."$admin_console_pw_hash". == ".." ]; then
|
|
371
|
echo "ERROR: Could not hash admin console password."
|
|
372
|
exit 1
|
|
373
|
fi
|
|
374
|
escaped_hash=$(escape_sed_replacement "$admin_console_pw_hash")
|
|
375
|
|
|
376
|
sed_file_separator=$(echo $file_separator | sed -e 's/\\/\\\\/g')
|
|
377
|
sed \
|
|
378
|
-e "s#{spawner_path}#$spawner_path#g" \
|
|
379
|
-e "s#{client_start_dir}#$client_start_dir#g" \
|
|
380
|
-e "s#{libPath}#$libpath_rendered#g" \
|
|
381
|
-e "s/{dateFormat}/$dateFormat/g" \
|
|
382
|
-e "s/{numberGroupSep}/$numberGroupSep/g" \
|
|
383
|
-e "s/{numberDecimalSep}/$numberDecimalSep/g" \
|
|
384
|
-e "s#{p2j_entry}#$p2j_entry#g" \
|
|
385
|
-e "s/{pkgroot}/$pkgroot/g" \
|
|
386
|
-e "s#{propath}#$propath#g" \
|
|
387
|
-e "s#{search_path}#$searchpath#g" \
|
|
388
|
-e "s/{path_separator}/$path_separator/g" \
|
|
389
|
-e "s#{file_separator}#$sed_file_separator#g" \
|
|
390
|
-e "s/{case_sensitive}/$case_sensitive/g" \
|
|
391
|
-e "s/{os_user}/$user/g" \
|
|
392
|
-e "s/{kbd_layout}/$keyboard/g" \
|
|
393
|
-e "s/{dbname}/$defdatabase/g" \
|
|
394
|
-e "s#{server_log}#$server_log#g" \
|
|
395
|
-e "s#{client_log}#$client_log#g" \
|
|
396
|
-e "s#{embedded_host}#$embedded_host#g" \
|
|
397
|
-e "s#{admin_port}#$admin_port#g" \
|
|
398
|
-e "s|{admin_console_pw}|$escaped_hash|g" \
|
|
399
|
-e "s#{webclient_appcds_jvmargs}#$webclient_appcds_jvmargs#g" \
|
|
400
|
-e "s/{webclient_memory}/$webclient_memory/g" \
|
|
401
|
directory.xml.template > directory_tmp.xml
|
|
402
|
rc=$?
|
|
403
|
if [ $rc -ne 0 ]; then
|
|
404
|
echo "ERROR: Could not create directory_tmp.xml rc=$rc"
|
|
405
|
exit $rc
|
|
406
|
fi
|
|
407
|
|
|
408
|
# Handle Proxy portion as appropriate
|
|
409
|
if proxy=$(_getval "proxy" "$infile"); then
|
|
410
|
forwarded_host=$(sub_getval "proxy" "forwarded_host" $embedded_host $infile)
|
|
411
|
forwarded_proto=$(sub_getval "proxy" "forwarded_proto" "https" $infile)
|
|
412
|
forwarded_prefix=$(sub_getval "proxy" "forwarded_prefix" "client" $infile)
|
|
413
|
sed \
|
|
414
|
-e "s/{forwarded_host}/$forwarded_host/g" \
|
|
415
|
-e "s/{forwarded_proto}/$forwarded_proto/g" \
|
|
416
|
-e "s/{forwarded_prefix}/$forwarded_prefix/g" \
|
|
417
|
directory_proxy.xml.template > directory_proxy.xml
|
|
418
|
rc=$?
|
|
419
|
if [ $rc -ne 0 ]; then
|
|
420
|
echo "ERROR: Could not create directory_proxy.xml rc=$rc"
|
|
421
|
exit $rc
|
|
422
|
fi
|
|
423
|
directory_copy "directory_proxy.xml" "/server" "directory_tmp.xml" "/server"
|
|
424
|
rm directory_proxy.xml
|
|
425
|
fi
|
|
426
|
|
|
427
|
# Handle DB portion as appropriate
|
|
428
|
dbdialect_h2="com.goldencode.p2j.persist.dialect.P2JH2Dialect"
|
|
429
|
dbdriver_h2="org.h2.Driver"
|
|
430
|
dbdialect_postgres="com.goldencode.p2j.persist.dialect.P2JPostgreSQLDialect"
|
|
431
|
dbdriver_postgres="org.postgresql.Driver"
|
|
432
|
|
|
433
|
# Loop through our list of DBs
|
|
434
|
for item in "${db_array[@]}"; do
|
|
435
|
dbtype=$(sub_getval $item "dbtype" "h2" $infile)
|
|
436
|
if [ "$dbtype" != "none" ]; then
|
|
437
|
dbhost=$(sub_getval $item "dbhost" "localhost" $infile)
|
|
438
|
if [ "$dbtype" == "postgres" ]; then
|
|
439
|
dbport=$(sub_getval $item "dbport" "5432" $infile)
|
|
440
|
elif [ "$dbtype" == "h2" ]; then
|
|
441
|
dbpath=$(sub_getval $item "dbpath" "../db" $infile)
|
|
442
|
pljava="TRUE"
|
|
443
|
fi
|
|
444
|
max_c3p0_pool=$(sub_getval $item "max_c3p0_pool" "20" $infile)
|
|
445
|
collation=$(sub_getval $item "collation" "en_US@iso88591_fwd_basic" $infile)
|
|
446
|
jdbc_url_h2="h2:${dbpath}/${item};DB_CLOSE_DELAY=-1;MV_STORE=FALSE;RTRIM=TRUE"
|
|
447
|
jdbc_url_postgres="postgresql://${dbhost}:${dbport}/${item}"
|
|
448
|
dbdialect=dbdialect_${dbtype}
|
|
449
|
dbdialect=${!dbdialect}
|
|
450
|
dbdriver=dbdriver_${dbtype}
|
|
451
|
dbdriver=${!dbdriver}
|
|
452
|
jdbc_url=jdbc_url_${dbtype}
|
|
453
|
jdbc_url=${!jdbc_url}
|
|
454
|
|
|
455
|
dbfile="directory_db.xml.${item}"
|
|
456
|
|
|
457
|
sed \
|
|
458
|
-e "s/{dbhost}/$dbhost/g" \
|
|
459
|
-e "s/{dbport}/$dbport/g" \
|
|
460
|
-e "s/{dbname}/$item/g" \
|
|
461
|
-e "s/{dbuser}/$dbuser/g" \
|
|
462
|
-e "s/{dbuserpass}/$dbuserpass/g" \
|
|
463
|
-e "s/{dbadmin}/$dbadmin/g" \
|
|
464
|
-e "s/{dbadminpass}/$dbadminpass/g" \
|
|
465
|
-e "s/{dbdialect}/$dbdialect/g" \
|
|
466
|
-e "s/{dbdriver}/$dbdriver/g" \
|
|
467
|
-e "s/{max_c3p0_pool}/$max_c3p0_pool/g" \
|
|
468
|
-e "s#{dbpath}#$dbdriver#g" \
|
|
469
|
-e "s#{jdbc_url}#$jdbc_url#g" \
|
|
470
|
-e "s/{pljava}/$pljava/g" \
|
|
471
|
-e "s/{collation}/$collation/g" \
|
|
472
|
directory_db.xml.template > $dbfile
|
|
473
|
rc=$?
|
|
474
|
if [ $rc -ne 0 ]; then
|
|
475
|
echo "ERROR: Could not create ${dbfile} rc=$rc"
|
|
476
|
exit $rc
|
|
477
|
fi
|
|
478
|
else
|
|
479
|
dbfile="directory_nodb.xml"
|
|
480
|
cp directory_nodb.xml.template $dbfile
|
|
481
|
fi
|
|
482
|
|
|
483
|
directory_copy $dbfile "/server" "directory_tmp.xml" "/server"
|
|
484
|
rm $dbfile
|
|
485
|
done
|
|
486
|
|
|
487
|
# Loop through our list of brokers, if any
|
|
488
|
i=0
|
|
489
|
if load_array_from_json "brokers" "$infile" broker_array false; then
|
|
490
|
for item in "${broker_array[@]}"; do
|
|
491
|
((i++))
|
|
492
|
tname="broker${i}"
|
|
493
|
client_xml_file=$(sub_getval $item "client_xml_file" "../etc/${tname}_client.xml" $infile)
|
|
494
|
broker_process_name=$(sub_getval $item "broker_process_name" "${tname}_process" $infile)
|
|
495
|
broker_process_description=$(sub_getval $item "broker_process_description" "${tname}_process" $infile)
|
|
496
|
broker_process_name_alias=$(sub_getval $item "broker_process_name_alias" "${tname}" $infile)
|
|
497
|
broker_name=$(sub_getval $item "broker_name" "${tname}" $infile)
|
|
498
|
broker_os_user=$(sub_getval $item "broker_os_user" "${user}" $infile)
|
|
499
|
broker_process_acl=$(sub_getval $item "broker_process_acl" "00000" $infile)
|
|
500
|
spawner_path=$(sub_getval $item "spawner_path" "/opt/spawner/spawn" $infile)
|
|
501
|
broker_client=$(sub_getval $item "broker_client" "localhost" $infile)
|
|
502
|
broker_server=$(sub_getval $item "broker_server" $embedded_host $infile)
|
|
503
|
storepath=$(sub_getval $item "storepath" "./deploy/security" $infile)
|
|
504
|
logpath=$(sub_getval $item "logpath" "./deploy/logs" $infile)
|
|
505
|
fwd_lib=$(sub_getval $item "fwd_lib" "/opt/fwd/build/lib" $infile)
|
|
506
|
|
|
507
|
brokerfile="directory_broker${i}.xml"
|
|
508
|
sed \
|
|
509
|
-e "s/{broker_process_name}/${broker_process_name}/g" \
|
|
510
|
-e "s/{broker_process_description}/${broker_process_description}/g" \
|
|
511
|
-e "s/{broker_process_name_alias}/${broker_process_name_alias}/g" \
|
|
512
|
-e "s/{broker_name}/${broker_name}/g" \
|
|
513
|
-e "s/{broker_os_user}/${broker_os_user}/g" \
|
|
514
|
-e "s/{broker_process_acl}/${broker_process_acl}/g" \
|
|
515
|
directory_broker.xml.template > $brokerfile
|
|
516
|
rc=$?
|
|
517
|
if [ $rc -ne 0 ]; then
|
|
518
|
echo "ERROR: Could not create ${brokerfile} rc=$rc"
|
|
519
|
exit $rc
|
|
520
|
fi
|
|
521
|
|
|
522
|
directory_copy $brokerfile "/security" "directory_tmp.xml" "/security"
|
|
523
|
directory_copy $brokerfile "/server" "directory_tmp.xml" "/server"
|
|
524
|
rm $brokerfile
|
|
525
|
|
|
526
|
cert_output="$(./gencert.sh "$item" -f directory_tmp.xml -s standard --emit-secrets --format=json --pkpw=${root_ca_pw})" \
|
|
527
|
|| { echo "ERROR: gencert.sh failed"; exit 1; }
|
|
528
|
# Validate JSON structure
|
|
529
|
if ! printf '%s' "$cert_output" | jq -e '.store_password and .keyentry_password' >/dev/null; then
|
|
530
|
echo "ERROR: Invalid JSON from gencert.sh"
|
|
531
|
printf '%s\n' "$cert_output"
|
|
532
|
exit 1
|
|
533
|
fi
|
|
534
|
cp ${item}-private-key.store ${storepath}
|
|
535
|
cp ${srvcerts_store} ${storepath}
|
|
536
|
STORE_PASSWORD=$(printf '%s' "$cert_output" | jq -r '.store_password')
|
|
537
|
KEYENTRY_PASSWORD=$(printf '%s' "$cert_output" | jq -r '.keyentry_password')
|
|
538
|
store_pw_xml=$(xml_escape "$STORE_PASSWORD")
|
|
539
|
store_pw_hash=$(escape_sed_replacement "$store_pw_xml")
|
|
540
|
key_pw_xml=$(xml_escape "$KEYENTRY_PASSWORD")
|
|
541
|
key_pw_hash=$(escape_sed_replacement "$key_pw_xml")
|
|
542
|
srv_certs_pw_xml=$(xml_escape "$srv_certs_pw")
|
|
543
|
srv_certs_hash=$(escape_sed_replacement "$srv_certs_pw_xml")
|
|
544
|
|
|
545
|
# Setup the client.xml
|
|
546
|
sed \
|
|
547
|
-e "s#{logpath}#${logpath}#g" \
|
|
548
|
-e "s/{broker_server}/${broker_server}/g" \
|
|
549
|
-e "s#{storepath}#${storepath}#g" \
|
|
550
|
-e "s/{broker_process_name_alias}/${broker_process_name_alias}/g" \
|
|
551
|
-e "s#{spawner_path}#${spawner_path}#g" \
|
|
552
|
-e "s/{broker_client}/${broker_client}/g" \
|
|
553
|
-e "s/{broker_os_user}/${broker_os_user}/g" \
|
|
554
|
-e "s#{fwd_lib}#${fwd_lib}#g" \
|
|
555
|
-e "s/{srv_certs_pw}/${srv_certs_hash}/g" \
|
|
556
|
-e "s/{pks_store_pw}/${store_pw_hash}/g" \
|
|
557
|
-e "s/{pks_key_pw}/${key_pw_hash}/g" \
|
|
558
|
-e "s/{log_rotation_limit}/${log_rotation_limit}/g" \
|
|
559
|
-e "s/{log_rotation_count}/${log_rotation_count}/g" \
|
|
560
|
broker_client.xml.template > $client_xml_file
|
|
561
|
rc=$?
|
|
562
|
if [ $rc -ne 0 ]; then
|
|
563
|
echo "ERROR: Could not create $client_xml_file rc=$rc"
|
|
564
|
exit $rc
|
|
565
|
fi
|
|
566
|
done
|
|
567
|
fi
|
|
568
|
|
|
569
|
$mysudo mv directory_tmp.xml $dirfile
|
|
570
|
|
|
571
|
exit 0
|