From 0494728d0c21c05ef492d98d019231eafacd8581 Mon Sep 17 00:00:00 2001 From: prasad-takale-eminds Date: Mon, 9 Sep 2024 21:19:41 +0530 Subject: [PATCH 1/5] Fixed issue #206 and issue #205 --- install/.gitignore | 2 + install/beckn-onix.sh | 124 ++++++++++++++++++++++++++++-------------- 2 files changed, 85 insertions(+), 41 deletions(-) diff --git a/install/.gitignore b/install/.gitignore index 6a5de0f..82efd4e 100644 --- a/install/.gitignore +++ b/install/.gitignore @@ -12,3 +12,5 @@ protocol-server-data/bpp-network.yml ENV/.env-generic-client-layer registry.*db gateway.*db +gateway_data/config/networks/onix.json + diff --git a/install/beckn-onix.sh b/install/beckn-onix.sh index 8850c51..717d4ed 100755 --- a/install/beckn-onix.sh +++ b/install/beckn-onix.sh @@ -263,73 +263,120 @@ completeSetup() { public_address="https://" echo "Proceeding with the setup for $platform..." - - # Insert the specific commands for each platform, including requesting network config if necessary + case $platform in "Registry") - read -p "Enter publicly accessible registry URL: " registry_url - if [[ $registry_url =~ /$ ]]; then - new_registry_url=${registry_url%/} - else - new_registry_url=$registry_url - fi + while true; do + read -p "Enter publicly accessible registry URL: " registry_url + if [[ $registry_url =~ ^(http|https):// ]]; then + break + else + echo "${RED}Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC}" + fi + done + + new_registry_url="${registry_url%/}" public_address=$registry_url install_package install_registry $new_registry_url ;; "Gateway"|"Beckn Gateway") - read -p "Enter your registry URL: " registry_url - read -p "Enter publicly accessible gateway URL: " gateway_url + while true; do + read -p "Enter your registry URL: " registry_url + if [[ $registry_url =~ ^(http|https):// ]]; then + break + else + echo "${RED}Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC}" + fi + done + + while true; do + read -p "Enter publicly accessible gateway URL: " gateway_url + if [[ $gateway_url =~ ^(http|https):// ]]; then + gateway_url="${gateway_url%/}" + break + else + echo "${RED}Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC}" + fi + done - if [[ $registry_url =~ /$ ]]; then - new_registry_url=${registry_url%/} - else - new_registry_url=$registry_url - fi - if [[ $gateway_url =~ /$ ]]; then - gateway_url=${gateway_url%/} - fi - public_address=$gateway_url install_package - install_gateway $new_registry_url $gateway_url + install_gateway $registry_url $gateway_url ;; "BAP") echo "${GREEN}................Installing Protocol Server for BAP................${NC}" read -p "Enter BAP Subscriber ID: " bap_subscriber_id - read -p "Enter BAP Subscriber URL: " bap_subscriber_url - read -p "Enter the registry_url(e.g. https://registry.becknprotocol.io/subscribers): " registry_url - bap_subscriber_key_id=$bap_subscriber_id-key + while true; do + read -p "Enter BAP Subscriber URL: " bap_subscriber_url + if [[ $bap_subscriber_url =~ ^(http|https):// ]]; then + break + else + echo "${RED}Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC}" + fi + done + + while true; do + read -p "Enter the registry URL (e.g., https://registry.becknprotocol.io/subscribers): " registry_url + if [[ $registry_url =~ ^(http|https):// ]] && [[ $registry_url == */subscribers ]]; then + break + else + echo "Please mention /subscribers in your registry URL" + fi + done + + #read -p "Enter the registry URL (e.g., https://registry.becknprotocol.io/subscribers): " registry_url + bap_subscriber_key_id="$bap_subscriber_id-key" public_address=$bap_subscriber_url + install_package install_bap_protocol_server $registry_url $bap_subscriber_id $bap_subscriber_key_id $bap_subscriber_url ;; "BPP") - echo "${GREEN}................Installing Protocol Server for BAP................${NC}" + echo "${GREEN}................Installing Protocol Server for BPP................${NC}" + read -p "Enter BPP Subscriber ID: " bpp_subscriber_id - read -p "Enter BPP Subscriber URL: " bpp_subscriber_url - read -p "Enter the registry_url(e.g. https://registry.becknprotocol.io/subscribers): " registry_url - read -p "Enter Webhook URL: " webhook_url - - bpp_subscriber_key_id=$bpp_subscriber_id-key + while true; do + read -p "Enter BPP Subscriber URL: " bpp_subscriber_url + if [[ $bpp_subscriber_url =~ ^(http|https):// ]]; then + break + else + echo "${RED}Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC}" + fi + done + + while true; do + read -p "Enter Webhook URL: " webhook_url + if [[ $webhook_url =~ ^(http|https):// ]]; then + break + else + echo "${RED}Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC}" + fi + done + + while true; do + read -p "Enter the registry URL (e.g., https://registry.becknprotocol.io/subscribers): " registry_url + if [[ $registry_url =~ ^(http|https):// ]] && [[ $registry_url == */subscribers ]]; then + break + else + echo "Please mention /subscribers in your registry URL" + fi + done + bpp_subscriber_key_id="$bpp_subscriber_id-key" public_address=$bpp_subscriber_url + install_package install_bpp_protocol_server $registry_url $bpp_subscriber_id $bpp_subscriber_key_id $bpp_subscriber_url $webhook_url ;; *) - echo "Invalid platform selected." - exit 1 + echo "Unknown platform: $platform" ;; esac - - echo "[Installation Logs]" - echo -e "${boldGreen}Your $platform setup is complete.${reset}" - echo -e "${boldGreen}You can access your $platform at $public_address ${reset}" - # Key generation and subscription logic follows here } + # MAIN SCRIPT STARTS HERE echo "Welcome to Beckn-ONIX!" @@ -379,8 +426,3 @@ else fi echo "Process complete. Thank you for using Beckn-ONIX!" - - -echo "Process complete. Thank you for using Beckn-ONIX!" - - From 3f55931e72485e32bb686323b1807c82d8719702 Mon Sep 17 00:00:00 2001 From: prasad-takale-eminds Date: Mon, 9 Sep 2024 21:21:38 +0530 Subject: [PATCH 2/5] Fixed issue #206 and issue #205 --- install/beckn-onix.sh | 2 +- install/gateway_data/config/networks/onix.json | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 install/gateway_data/config/networks/onix.json diff --git a/install/beckn-onix.sh b/install/beckn-onix.sh index 717d4ed..ee8359b 100755 --- a/install/beckn-onix.sh +++ b/install/beckn-onix.sh @@ -360,7 +360,7 @@ completeSetup() { if [[ $registry_url =~ ^(http|https):// ]] && [[ $registry_url == */subscribers ]]; then break else - echo "Please mention /subscribers in your registry URL" + echo "${RED}Please mention /subscribers in your registry URL${NC}" fi done bpp_subscriber_key_id="$bpp_subscriber_id-key" diff --git a/install/gateway_data/config/networks/onix.json b/install/gateway_data/config/networks/onix.json deleted file mode 100644 index 2bb446a..0000000 --- a/install/gateway_data/config/networks/onix.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "core_version" : "1.1.0", - "registry_id": "registry-dev.becknprotocol.io..LREG", - "search_provider_id" : "gateway-dev.becknprotocol.io", - "self_registration_supported": true, - "subscription_needed_post_registration" : true, - "base_url": "https://registry-dev.becknprotocol.io", - "registry_url" : "https://registry-dev.becknprotocol.io/subscribers", - "extension_package": "in.succinct.beckn.boc", - "wild_card" : "" -} \ No newline at end of file From 6f1ef3881e6b0e6c7fa8d94af2c48d6720416c0c Mon Sep 17 00:00:00 2001 From: prasad-takale-eminds Date: Thu, 12 Sep 2024 19:19:16 +0530 Subject: [PATCH 3/5] Added input validation for given menu issue #207 --- install/beckn-onix.sh | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/install/beckn-onix.sh b/install/beckn-onix.sh index ee8359b..35475e9 100755 --- a/install/beckn-onix.sh +++ b/install/beckn-onix.sh @@ -375,6 +375,30 @@ completeSetup() { esac } +restart_script(){ + read -p "${GREEN}Do you want to restart the script or exit the script? (r for restart, e for exit): ${NC}" choice + if [[ $choice == "r" ]]; then + echo "Restarting the script..." + exec "$0" # Restart the script by re-executing it + elif [[ $choice == "e" ]]; then + echo "Exiting the script..." + exit 0 + fi +} + +# Function to validate user input +validate_input() { + local input=$1 + local max_option=$2 + + # Check if the input is a digit and within the valid range + if [[ "$input" =~ ^[0-9]+$ ]] && (( input >= 1 && input <= max_option )); then + return 0 # Valid input + else + echo "${RED}Invalid input. Please enter a number between 1 and $max_option.${NC}" + return 1 # Invalid input + fi +} # MAIN SCRIPT STARTS HERE @@ -390,6 +414,11 @@ echo "Beckn-ONIX is a platform that helps you quickly launch and configure beckn echo -e "\nWhat would you like to do?\n1. Join an existing network\n2. Create new production network\n3. Set up a network on your local machine\n4. Merge multiple networks\n5. Configure Existing Network\n(Press Ctrl+C to exit)" read -p "Enter your choice: " choice +validate_input "$choice" 5 +if [[ $? -ne 0 ]]; then + restart_script # Restart the script if input is invalid +fi + boldGreen="\e[1m\e[92m" reset="\e[0m" if [[ $choice -eq 3 ]]; then @@ -414,14 +443,17 @@ else done read -p "Enter your choice: " platform_choice + validate_input "$platform_choice" "${#platforms[@]}" + if [[ $? -ne 0 ]]; then + restart_script # Restart the script if input is invalid + fi selected_platform="${platforms[$((platform_choice-1))]}" if [[ -n $selected_platform ]]; then completeSetup "$selected_platform" else - echo "Invalid option. Please restart the script and select a valid option." - exit 1 + restart_script fi fi From aca0ec261143b30f72afd5bd6296f272caef2948 Mon Sep 17 00:00:00 2001 From: prasad-takale-eminds Date: Fri, 13 Sep 2024 14:18:35 +0530 Subject: [PATCH 4/5] fixed #209: Removed public and private keys from installation logs of PS --- install/scripts/update_bap_config.sh | 3 --- install/scripts/update_bpp_config.sh | 3 --- 2 files changed, 6 deletions(-) diff --git a/install/scripts/update_bap_config.sh b/install/scripts/update_bap_config.sh index be65d06..077270d 100755 --- a/install/scripts/update_bap_config.sh +++ b/install/scripts/update_bap_config.sh @@ -46,9 +46,6 @@ fi echo "Generating public/private key pair" get_keys -echo "Your Private Key: $private_key" -echo "Your Public Key: $public_key" - if [[ $(uname -s ) == 'Darwin' ]];then valid_from=$(date -u -v-1d +"%Y-%m-%dT%H:%M:%S.%000Z") diff --git a/install/scripts/update_bpp_config.sh b/install/scripts/update_bpp_config.sh index e20cc3a..7b2bac4 100755 --- a/install/scripts/update_bpp_config.sh +++ b/install/scripts/update_bpp_config.sh @@ -47,9 +47,6 @@ fi echo "Generating public/private key pair" get_keys -#echo "Your Private Key: $private_key" -#echo "Your Public Key: $public_key" - if [[ $(uname -s ) == 'Darwin' ]];then valid_from=$(date -u -v-1d +"%Y-%m-%dT%H:%M:%S.%000Z") From 3e2e0d2074d1b3f2a4f8e5070ece199a3ce2ac8f Mon Sep 17 00:00:00 2001 From: prasad-takale-eminds Date: Fri, 13 Sep 2024 19:04:18 +0530 Subject: [PATCH 5/5] Fixed #208: Added docker command validation to the script --- install/beckn-onix.sh | 27 ++++++++++++++++++++++++--- install/scripts/variables.sh | 2 ++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/install/beckn-onix.sh b/install/beckn-onix.sh index 35475e9..581e491 100755 --- a/install/beckn-onix.sh +++ b/install/beckn-onix.sh @@ -400,6 +400,27 @@ validate_input() { fi } +check_docker_permissions() { + if ! command -v docker &> /dev/null; then + echo -e "${RED}Error: Docker is not installed on this system.${NC}" + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + install_package + if [[ $? -ne 0 ]]; then + echo -e "${RED}Please install Docker and try again.${NC}" + echo -e "${RED}Please install Docker and jq manually.${NC}" + exit 1 + fi + fi + fi + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + if ! groups "$USER" | grep -q '\bdocker\b'; then + echo -e "${RED}Error: You do not have permission to run Docker. Please add yourself to the docker group by running the following command:${NC}" + echo -e "${boldGreen}sudo usermod -aG docker \$USER" + echo -e "After running the above command, please log out and log back in to your system, then restart the deployment script.${NC}" + exit 1 + fi + fi +} # MAIN SCRIPT STARTS HERE @@ -410,6 +431,9 @@ else echo "[Display Beckn-ONIX ASCII Art]" fi +echo "Checking prerequisites of Beckn-ONIX deployment" +check_docker_permissions + echo "Beckn-ONIX is a platform that helps you quickly launch and configure beckn-enabled networks." echo -e "\nWhat would you like to do?\n1. Join an existing network\n2. Create new production network\n3. Set up a network on your local machine\n4. Merge multiple networks\n5. Configure Existing Network\n(Press Ctrl+C to exit)" read -p "Enter your choice: " choice @@ -419,11 +443,8 @@ if [[ $? -ne 0 ]]; then restart_script # Restart the script if input is invalid fi -boldGreen="\e[1m\e[92m" -reset="\e[0m" if [[ $choice -eq 3 ]]; then echo "Installing all components on the local machine" - install_package install_registry install_gateway install_bap_protocol_server diff --git a/install/scripts/variables.sh b/install/scripts/variables.sh index fcda32f..247f0e0 100755 --- a/install/scripts/variables.sh +++ b/install/scripts/variables.sh @@ -5,6 +5,8 @@ RED=$(tput setaf 1) GREEN=$(tput setaf 2) YELLOW=$(tput setaf 3) NC=$(tput sgr0) +boldGreen="\e[1m\e[92m" +reset="\e[0m" SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"