11#! /bin/bash
22source scripts/variables.sh
33source scripts/get_container_details.sh
4+ source scripts/registry_entry.sh
45
56# Function to start a specific service inside docker-compose file
67install_package () {
@@ -130,17 +131,23 @@ install_layer2_config() {
130131
131132# Function to install BAP Protocol Server
132133install_bap_protocol_server () {
133- start_support_services
134+ start_support_services # Start MongoDB, RabbitMQ, and Redis services
135+ # POST containers are started, now update the configuration
134136 if [[ $1 ]]; then
137+ # If parameters are provided, use them to update the configuration
135138 registry_url=$1
136139 bap_subscriber_id=$2
137140 bap_subscriber_key_id=$3
138141 bap_subscriber_url=$4
139- bash scripts/update_bap_config.sh $registry_url $bap_subscriber_id $bap_subscriber_key_id $bap_subscriber_url $api_key $np_domain
142+ source scripts/update_bap_config.sh $registry_url $bap_subscriber_id $bap_subscriber_key_id $bap_subscriber_url $api_key " $np_domain "
140143 else
141- bash scripts/update_bap_config.sh
144+ # If no parameters are provided, use the default configuration
145+ source scripts/update_bap_config.sh
142146 fi
147+
148+
143149 sleep 10
150+
144151 docker volume create bap_client_config_volume
145152 docker volume create bap_network_config_volume
146153 docker run --rm -v $SCRIPT_DIR /../protocol-server-data:/source -v bap_client_config_volume:/target busybox cp /source/bap-client.yml /target/default.yml
@@ -161,26 +168,63 @@ install_bap_protocol_server() {
161168 install_layer2_config bap-client
162169 install_layer2_config bap-network
163170 fi
171+
172+
173+
174+ # Keep trying API call until we get 200 status
175+ status_code=0
176+ attempt=1
177+ max_attempts=10
178+
179+ while [ $status_code -ne 200 ]; do
180+ echo " Checking BAP protocol server health..."
181+
182+ response=$( curl -s -w " %{http_code}" --location " $bap_subscriber_url /health" \
183+ -H " Content-Type: application/json" )
184+
185+ status_code=" ${response: -3} "
186+
187+ if [ $status_code -eq 200 ]; then
188+ echo " ${GREEN} BAP protocol server is up and running${NC} "
189+ break
190+ else
191+ echo " ${YELLOW} BAP protocol server not ready yet (status: $status_code ). Retrying in 5 seconds...${NC} "
192+ sleep 5
193+ (( attempt++ ))
194+ fi
195+ done
196+
197+
198+
199+ echo " ${BLUE} Registering BAP protocol server on the registry${NC} "
200+ create_network_participant " $registry_url " " application/json" " $bap_subscriber_id " " $bap_subscriber_key_id " " $bap_subscriber_url " " $public_key " " $public_key " " $valid_from " " $valid_until " " $type " " $api_key " " $np_domain "
201+
202+
164203 echo " Protocol server BAP installation successful"
165204}
166205
167206# Function to install BPP Protocol Server without Sandbox
168207install_bpp_protocol_server () {
169- start_support_services
208+ start_support_services # Start MongoDB, RabbitMQ, and Redis services
209+ # POST containers are started, now update the configuration
170210 echo " ${GREEN} ................Installing Protocol Server for BPP................${NC} "
171211
172212 if [[ $1 ]]; then
213+ # If parameters are provided, use them to update the configuration
173214 registry_url=$1
174215 bpp_subscriber_id=$2
175216 bpp_subscriber_key_id=$3
176217 bpp_subscriber_url=$4
177- webhook_url=$5
178- bash scripts/update_bpp_config.sh $registry_url $bpp_subscriber_id $bpp_subscriber_key_id $bpp_subscriber_url $webhook_url $api_key $np_domain
218+ webhook_url=$5
219+ source scripts/update_bpp_config.sh $registry_url $bpp_subscriber_id $bpp_subscriber_key_id $bpp_subscriber_url $webhook_url $api_key " $np_domain "
220+
179221 else
180- bash scripts/update_bpp_config.sh
222+ # If no parameters are provided, use the default configuration
223+ source scripts/update_bpp_config.sh
181224 fi
182225
183226 sleep 10
227+
184228 docker volume create bpp_client_config_volume
185229 docker volume create bpp_network_config_volume
186230 docker run --rm -v $SCRIPT_DIR /../protocol-server-data:/source -v bpp_client_config_volume:/target busybox cp /source/bpp-client.yml /target/default.yml
@@ -200,6 +244,33 @@ install_bpp_protocol_server() {
200244 install_layer2_config bpp-client
201245 install_layer2_config bpp-network
202246 fi
247+
248+ # Keep trying API call until we get 200 status
249+ status_code=0
250+ attempt=1
251+ max_attempts=10
252+
253+ while [ $status_code -ne 200 ]; do
254+ echo " Checking BPP protocol server health..."
255+
256+ response=$( curl -s -w " %{http_code}" --location " $bpp_subscriber_url /health" \
257+ -H " Content-Type: application/json" )
258+
259+ status_code=" ${response: -3} "
260+
261+ if [ $status_code -eq 200 ]; then
262+ echo " ${GREEN} BPP protocol server is up and running${NC} "
263+ break
264+ else
265+ echo " ${YELLOW} BPP protocol server not ready yet (status: $status_code ). Retrying in 5 seconds...${NC} "
266+ sleep 5
267+ (( attempt++ ))
268+ fi
269+ done
270+
271+ echo " ${BLUE} Registering BPP protocol server on the registry${NC} "
272+ create_network_participant " $registry_url " " application/json" " $bpp_subscriber_id " " $bpp_subscriber_key_id " " $bpp_subscriber_url " " $public_key " " $public_key " " $valid_from " " $valid_until " " $type " " $api_key " " $np_domain "
273+
203274 echo " Protocol server BPP installation successful"
204275}
205276
@@ -328,29 +399,32 @@ validate_user() {
328399 echo # Move to a new line after input
329400
330401 # Replace '/subscribers' with '/login' for validation
331- local login_url=" ${registry_url%/ subscribers} /login"
332-
402+ local login_url=" ${registry_url%/ subscribers} /auth/local"
403+
404+
333405 # Validate credentials using a POST request
334406 local response
335- response=$( curl -s -w " %{http_code}" -X POST " $login_url " \
407+ response=$( curl -s -w " %{http_code}" --location " $login_url " \
336408 -H " Content-Type: application/json" \
337- -d ' { "Name" : "' " $username " ' ", "Password" : "' " $password " ' " }' )
338-
409+ -d ' { "identifier": "' " $username " ' ", "password": "' " $password " ' " }' )
410+
411+
339412 # Check if the HTTP response is 200 (success)
340413 status_code=" ${response: -3} "
341414 if [ " $status_code " -eq 200 ]; then
342415 response_body=" ${response% ???} "
343- api_key=$( echo " $response_body " | jq -r ' .api_key' )
416+ api_key=$( echo " $response_body " | jq -r ' .jwt' )
417+
344418 return 0
345419 else
346- response=$( curl -s -w " %{http_code}" -X POST " $login_url " \
347- -H " Content-Type: application/json" \
348- -d ' { "User" : { "Name" : " ' " $username " ' ", "Password" : "' " $password " ' " } }' )
420+ response=$( curl -s -w " %{http_code}" --location " $login_url " \
421+ -H " Content-Type: application/json" \
422+ -d ' { "identifier": " ' " $username " ' ", "password" : "' " $password " ' " }' )
349423
350424 status_code=" ${response: -3} "
351425 if [ " $status_code " -eq 200 ]; then
352426 response_body=" ${response% ???} "
353- api_key=$( echo " $response_body " | jq -r ' .api_key ' )
427+ api_key=$( echo " $response_body " | jq -r ' .jwt ' )
354428 return 0
355429 fi
356430 fi
@@ -368,15 +442,18 @@ get_np_domain() {
368442 if [[ " $dchoice " == " Y" || " $dchoice " == " y" ]]; then
369443 local login_url=" ${registry_url%/ subscribers} "
370444 read -p " Enter the domain name for $1 : " np_domain
371- domain_present=$( curl -s -H " ApiKey:$api_key " --header ' Content-Type: application/json' $login_url /network_domains/index | jq -r ' .[].name' | tr ' \n' ' ' )
445+ echo " login_url: $login_url /network_domains/index"
446+
447+ domain_present=$( curl -s --header ' Content-Type: application/json' $login_url /network_domains | jq -r ' .[].name' | tr ' \n' ' ' )
372448 if echo " $domain_present " | grep -Fqw " $np_domain " ; then
449+ echo " The domain '$np_domain ' is present in the network domains."
373450 return 0
374451 else
375452 echo " ${BoldRed} The domain '$np_domain ' is NOT present in the network domains.${NC} "
376453 echo " ${BoldGreen} Available network domains: $domain_present ${NC} "
377454 fi
378455 else
379- np_domain=" " # If user don't want to add specific domain then save empty string
456+ np_domain=" * " # If user don't want to add specific domain then save "*"
380457 return 0
381458 fi
382459}
@@ -430,31 +507,40 @@ completeSetup() {
430507 install_gateway $registry_url $gateway_url
431508 ;;
432509 " BAP" )
510+ # Display installation header
433511 echo " ${GREEN} ................Installing Protocol Server for BAP................${NC} "
434512
513+ # Step 1: Get BAP Subscriber ID
435514 read -p " Enter BAP Subscriber ID: " bap_subscriber_id
515+
516+ # Step 2: Get and validate BAP Subscriber URL
436517 while true ; do
437518 read -p " Enter BAP Subscriber URL: " bap_subscriber_url
438519 if [[ $bap_subscriber_url =~ ^(http| https):// ]]; then
439- break
520+ break # Valid URL format, exit loop
440521 else
441522 echo " ${RED} Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC} "
442523 fi
443524 done
444525
526+ # Step 3: Get and validate Registry URL
445527 while true ; do
446528 read -p " Enter the registry URL (e.g., https://registry.becknprotocol.io/subscribers): " registry_url
447- if [[ $registry_url =~ ^(http| https):// ]] && [[ $registry_url == * /subscribers ]]; then
448- break
529+ # Check if URL starts with http/https AND ends with /subscribers
530+ if [[ $registry_url =~ ^(http| https):// ]]; then
531+ break # Valid URL format, exit loop
449532 else
450533 echo " ${RED} Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC} "
451534 fi
452535 done
536+
537+ # Step 4: Validate user credentials
453538 validate_user
454539 if [ $? -eq 1 ]; then
455540 exit
456541 fi
457542
543+ # Step 5: Get and validate NP Domain
458544 get_np_domain $bap_subscriber_id
459545 if [ $? -eq 1 ]; then
460546 exit
@@ -466,20 +552,28 @@ completeSetup() {
466552 layer2_config
467553 install_package
468554 install_bap_protocol_server $registry_url $bap_subscriber_id $bap_subscriber_key_id $bap_subscriber_url
555+
556+
469557 ;;
470558 " BPP" )
471- echo " ${GREEN} ................Installing Protocol Server for BPP................${NC} "
472559
560+ # Display installation header
561+ echo " ${GREEN} ................Installing Protocol Server for BPP................${NC} "
562+
563+ # Step 1: Get BPP Subscriber ID
473564 read -p " Enter BPP Subscriber ID: " bpp_subscriber_id
565+
566+ # Step 2: Get and validate BPP Subscriber URL
474567 while true ; do
475568 read -p " Enter BPP Subscriber URL: " bpp_subscriber_url
476569 if [[ $bpp_subscriber_url =~ ^(http| https):// ]]; then
477- break
570+ break # Valid URL format, exit loop
478571 else
479572 echo " ${RED} Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC} "
480573 fi
481574 done
482575
576+ # Step 3: Get and validate Webhook URL
483577 while true ; do
484578 read -p " Enter Webhook URL: " webhook_url
485579 if [[ $webhook_url =~ ^(http| https):// ]]; then
@@ -489,19 +583,23 @@ completeSetup() {
489583 fi
490584 done
491585
586+ # Step 4: Get and validate Registry URL
492587 while true ; do
493588 read -p " Enter the registry URL (e.g., https://registry.becknprotocol.io/subscribers): " registry_url
494- if [[ $registry_url =~ ^(http| https):// ]] && [[ $registry_url == * /subscribers ]] ; then
495- break
589+ if [[ $registry_url =~ ^(http| https):// ]]; then
590+ break # Valid URL format, exit loop
496591 else
497592 echo " ${RED} Please mention /subscribers in your registry URL${NC} "
498593 fi
499594 done
595+
596+ # Step 5: Validate user credentials
500597 validate_user
501598 if [ $? -eq 1 ]; then
502599 exit
503600 fi
504601
602+ # Step 6: Get and validate NP Domain
505603 get_np_domain $bpp_subscriber_id
506604 if [ $? -eq 1 ]; then
507605 exit
0 commit comments