From 02f81fb51840c0b9f068c732893294c055546df8 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 13 Sep 2024 13:59:27 +0900 Subject: [PATCH 1/5] Remove unnecessary -R option from chown and chmod commands --- start_node_genesis_onprem.sh | 2 +- start_node_incremental_onprem.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/start_node_genesis_onprem.sh b/start_node_genesis_onprem.sh index 8249e5503..cfb2c4d1f 100644 --- a/start_node_genesis_onprem.sh +++ b/start_node_genesis_onprem.sh @@ -183,7 +183,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf 'Setting up new working directory..\n' sudo rm -rf /home/${SEASON}/ain-blockchain* # NOTE(platfowner): Add $SEASON to the node job name to be selectively killed in restarts. - CODE_CMD="sudo mkdir -p /home/${SEASON}; sudo chmod -R 777 /home/${SEASON}; sudo chown -R $ONPREM_USER:$ONPREM_USER /home/${SEASON}; cd ~; sudo mv ./ain-blockchain /home/${SEASON}; sudo chmod -R 777 /home/${SEASON}/ain-blockchain; sudo chown -R $ONPREM_USER:$ONPREM_USER /home/${SEASON}/ain-blockchain; cd /home/${SEASON}/ain-blockchain; mv client/index.js client/${SEASON}-ain-blockchain-index.js" + CODE_CMD="sudo mkdir -p /home/${SEASON}; sudo chmod 777 /home/${SEASON}; sudo chown $ONPREM_USER:$ONPREM_USER /home/${SEASON}; cd ~; sudo mv ./ain-blockchain /home/${SEASON}; sudo chmod -R 777 /home/${SEASON}/ain-blockchain; sudo chown -R $ONPREM_USER:$ONPREM_USER /home/${SEASON}/ain-blockchain; cd /home/${SEASON}/ain-blockchain; mv client/index.js client/${SEASON}-ain-blockchain-index.js" printf "\nCODE_CMD=$CODE_CMD\n" eval $CODE_CMD else diff --git a/start_node_incremental_onprem.sh b/start_node_incremental_onprem.sh index e76aacbc6..03d3a6226 100644 --- a/start_node_incremental_onprem.sh +++ b/start_node_incremental_onprem.sh @@ -247,7 +247,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Setting up new working directory..\n' # NOTE(platfowner): Add $SEASON to the node job name to be selectively killed in restarts. - CODE_CMD="sudo mkdir -p /home/${SEASON}; sudo chmod -R 777 /home/${SEASON}; sudo chown -R $ONPREM_USER:$ONPREM_USER /home/${SEASON}; cd ~; sudo mv ain-blockchain $NEW_DIR_PATH; sudo chmod -R 777 $NEW_DIR_PATH; sudo chown -R $ONPREM_USER:$ONPREM_USER $NEW_DIR_PATH; cd $NEW_DIR_PATH; mv client/index.js client/${SEASON}-ain-blockchain-index.js" + CODE_CMD="sudo mkdir -p /home/${SEASON}; sudo chmod 777 /home/${SEASON}; sudo chown $ONPREM_USER:$ONPREM_USER /home/${SEASON}; cd ~; sudo mv ain-blockchain $NEW_DIR_PATH; sudo chmod -R 777 $NEW_DIR_PATH; sudo chown -R $ONPREM_USER:$ONPREM_USER $NEW_DIR_PATH; cd $NEW_DIR_PATH; mv client/index.js client/${SEASON}-ain-blockchain-index.js" printf "\nCODE_CMD=$CODE_CMD\n" eval $CODE_CMD else From 90513dc808571baec88af5f3c8613cdd0b2f71e5 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 13 Sep 2024 14:04:44 +0900 Subject: [PATCH 2/5] Add _gcp suffix to gcp ip address files --- config_client_api_ip_whitelist.sh | 2 +- config_node_param.sh | 2 +- deploy_blockchain_genesis_gcp.sh | 2 +- deploy_blockchain_incremental_gcp.sh | 2 +- deploy_blockchain_sandbox_gcp.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config_client_api_ip_whitelist.sh b/config_client_api_ip_whitelist.sh index 85a0781de..a71eb53de 100644 --- a/config_client_api_ip_whitelist.sh +++ b/config_client_api_ip_whitelist.sh @@ -65,7 +65,7 @@ else fi # Read node urls -IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_gcp.txt # Get keystore password printf "Enter keystore password: " diff --git a/config_node_param.sh b/config_node_param.sh index 55679bf4e..72386a10d 100644 --- a/config_node_param.sh +++ b/config_node_param.sh @@ -74,7 +74,7 @@ else fi # Read node urls -IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_gcp.txt # Get keystore password printf "Enter keystore password: " diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 54a5f9dad..078868075 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -162,7 +162,7 @@ fi if [[ ! $KILL_OPTION = '--kill-only' ]]; then # Read node urls - IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt + IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_gcp.txt if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then # Get keystore password printf "Enter keystore password: " diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index 4fa960546..bad1cb075 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -161,7 +161,7 @@ fi if [[ ! $KILL_OPTION = '--kill-only' ]]; then # Read node urls - IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt + IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_gcp.txt if [[ $ACCOUNT_INJECTION_OPTION = "--keystore" ]]; then # Get keystore password printf "Enter keystore password: " diff --git a/deploy_blockchain_sandbox_gcp.sh b/deploy_blockchain_sandbox_gcp.sh index bf66bb5ef..12514faf0 100644 --- a/deploy_blockchain_sandbox_gcp.sh +++ b/deploy_blockchain_sandbox_gcp.sh @@ -89,7 +89,7 @@ then fi # Read node urls -IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_gcp.txt function inject_account() { local node_index="$1" From 3e2249be89b9979d84ba11a4cc08e2ce6096d33f Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 13 Sep 2024 15:49:20 +0900 Subject: [PATCH 3/5] Update node params-related scripts --- config_client_api_ip_whitelist.sh | 51 +++++++++++++++----------- config_node_param.sh | 60 ++++++++++++++++++------------- 2 files changed, 66 insertions(+), 45 deletions(-) diff --git a/config_client_api_ip_whitelist.sh b/config_client_api_ip_whitelist.sh index a71eb53de..65a27f4b6 100644 --- a/config_client_api_ip_whitelist.sh +++ b/config_client_api_ip_whitelist.sh @@ -2,16 +2,16 @@ function usage() { printf "\n" - printf "Usage: bash config_client_api_ip_whitelist.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [get|add|remove] []\n" - printf "Example: bash config_client_api_ip_whitelist.sh dev get\n" - printf "Example: bash config_client_api_ip_whitelist.sh dev add 32.190.239.181\n" - printf "Example: bash config_client_api_ip_whitelist.sh dev add '*'\n" - printf "Example: bash config_client_api_ip_whitelist.sh dev remove 32.190.239.181\n" + printf "Usage: bash config_client_api_ip_whitelist.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [gcp|onprem] [get|add|remove] []\n" + printf "Example: bash config_client_api_ip_whitelist.sh staging onprem get\n" + printf "Example: bash config_client_api_ip_whitelist.sh staging onprem add 32.190.239.181\n" + printf "Example: bash config_client_api_ip_whitelist.sh staging onprem add '*'\n" + printf "Example: bash config_client_api_ip_whitelist.sh staging onprem remove 32.190.239.181\n" printf "\n" exit } -if [[ $# -lt 2 ]] || [[ $# -gt 3 ]]; then +if [[ $# -lt 3 ]] || [[ $# -gt 4 ]]; then usage fi printf "\n[[[[[ config_client_api_ip_whitelist.sh ]]]]]\n\n" @@ -19,27 +19,37 @@ printf "\n[[[[[ config_client_api_ip_whitelist.sh ]]]]]\n\n" if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ "$1" = 'exp' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'summer' ]] || [[ "$1" = 'mainnet' ]]; then SEASON="$1" else - printf "Invalid argument: $1\n" + printf "\nInvalid argument: $1\n" usage fi printf "SEASON=$SEASON\n" -if [[ "$2" = 'get' ]]; then - COMMAND="$2" - IP_ADDR="$3" +if [[ "$2" = 'gcp' ]] || [[ "$2" = 'onprem' ]]; then + BLOCKCHAIN_HOSTING="$2" +else + printf "\nInvalid argument: $2\n" + usage +fi +printf "BLOCKCHAIN_HOSTING=$BLOCKCHAIN_HOSTING\n" + +COMMAND="$3" +IP_ADDR="" +if [[ $# = 4 ]]; then + IP_ADDR="$4" +fi + +if [[ "$COMMAND" = 'get' ]]; then if [[ ! "$IP_ADDR" = "" ]]; then - printf "\nInvalid argument: $IP_ADDR\n" + printf "\nInvalid argument: $IP_ADDR\n" usage fi -elif [[ "$2" = 'add' ]] || [[ "$2" = 'remove' ]]; then - COMMAND="$2" - IP_ADDR="$3" +elif [[ "$COMMAND" = 'add' ]] || [[ "$COMMAND" = 'remove' ]]; then if [[ "$IP_ADDR" = "" ]]; then printf "\nInvalid argument: $IP_ADDR\n" usage fi else - printf "Invalid argument: $2\n" + printf "\nInvalid argument: $COMMAND\n" usage fi printf "COMMAND=$COMMAND\n" @@ -65,7 +75,7 @@ else fi # Read node urls -IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_gcp.txt +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_${BLOCKCHAIN_HOSTING}.txt # Get keystore password printf "Enter keystore password: " @@ -101,9 +111,10 @@ function config_node() { printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_url) >>>\n\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" - CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID keystore $KEYSTORE_FILE_PATH" - if [[ ! $COMMAND = "get" ]]; then - CONFIG_NODE_CMD="$CONFIG_NODE_CMD '$IP_ADDR'" + if [[ $COMMAND = "get" ]]; then + CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID keystore $KEYSTORE_FILE_PATH" + else + CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID $IP_ADDR keystore $KEYSTORE_FILE_PATH" fi printf "\n" @@ -111,6 +122,6 @@ function config_node() { eval "echo $KEYSTORE_PW | $CONFIG_NODE_CMD" } -for j in `seq $(( 0 )) $(( 9 ))`; do +for j in `seq $(( 0 )) $(( 4 ))`; do config_node "$j" done diff --git a/config_node_param.sh b/config_node_param.sh index 72386a10d..06f582600 100644 --- a/config_node_param.sh +++ b/config_node_param.sh @@ -2,18 +2,18 @@ function usage() { printf "\n" - printf "Usage: bash config_node_param.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [get|add|remove] []\n" - printf "Example: bash config_node_param.sh dev get DEV_CLIENT_API_IP_WHITELIST\n" - printf "Example: bash config_node_param.sh dev add DEV_CLIENT_API_IP_WHITELIST 32.190.239.181\n" - printf "Example: bash config_node_param.sh dev add DEV_CLIENT_API_IP_WHITELIST '*'\n" - printf "Example: bash config_node_param.sh dev remove DEV_CLIENT_API_IP_WHITELIST 32.190.239.181\n" - printf "Example: bash config_node_param.sh dev set DEV_CLIENT_API_IP_WHITELIST '*'\n" - printf "Example: bash config_node_param.sh dev get CORS_WHITELIST\n" + printf "Usage: bash config_node_param.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [gcp|onprem] [get|add|remove] []\n" + printf "Example: bash config_node_param.sh staging onprem get DEV_CLIENT_API_IP_WHITELIST\n" + printf "Example: bash config_node_param.sh staging onprem add DEV_CLIENT_API_IP_WHITELIST 32.190.239.181\n" + printf "Example: bash config_node_param.sh staging onprem add DEV_CLIENT_API_IP_WHITELIST '*'\n" + printf "Example: bash config_node_param.sh staging onprem remove DEV_CLIENT_API_IP_WHITELIST 32.190.239.181\n" + printf "Example: bash config_node_param.sh staging onprem set DEV_CLIENT_API_IP_WHITELIST '*'\n" + printf "Example: bash config_node_param.sh staging onprem get CORS_WHITELIST\n" printf "\n" exit } -if [[ $# -lt 3 ]] || [[ $# -gt 4 ]]; then +if [[ $# -lt 4 ]] || [[ $# -gt 5 ]]; then usage fi printf "\n[[[[[ config_node_param.sh ]]]]]\n\n" @@ -21,23 +21,32 @@ printf "\n[[[[[ config_node_param.sh ]]]]]\n\n" if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ "$1" = 'exp' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'summer' ]] || [[ "$1" = 'mainnet' ]]; then SEASON="$1" else - printf "Invalid argument: $1\n" + printf "\nInvalid argument: $1\n" usage fi printf "SEASON=$SEASON\n" -if [[ "$2" = 'get' ]]; then - COMMAND="$2" - PARAM="$3" - VALUE="$4" +if [[ "$2" = 'gcp' ]] || [[ "$2" = 'onprem' ]]; then + BLOCKCHAIN_HOSTING="$2" +else + printf "\nInvalid argument: $2\n" + usage +fi +printf "BLOCKCHAIN_HOSTING=$BLOCKCHAIN_HOSTING\n" + +COMMAND="$3" +PARAM="$4" +VALUE="" +if [[ $# = 5 ]]; then + VALUE="$5" +fi + +if [[ "$COMMAND" = 'get' ]]; then if [[ ! "$VALUE" = "" ]]; then - printf "\nInvalid argument: $VALUE\n" + printf "\nInvalid argument: $VALUE\n" usage fi -elif [[ "$2" = 'add' ]] || [[ "$2" = 'remove' ]] || [[ "$2" = 'set' ]]; then - COMMAND="$2" - PARAM="$3" - VALUE="$4" +elif [[ "$COMMAND" = 'add' ]] || [[ "$COMMAND" = 'remove' ]] || [[ "$COMMAND" = 'set' ]]; then if [[ "$PARAM" = "" ]]; then printf "\nInvalid argument: $PARAM\n" usage @@ -47,7 +56,7 @@ elif [[ "$2" = 'add' ]] || [[ "$2" = 'remove' ]] || [[ "$2" = 'set' ]]; then usage fi else - printf "Invalid argument: $2\n" + printf "\nInvalid argument: $COMMAND\n" usage fi printf "COMMAND=$COMMAND\n" @@ -74,7 +83,7 @@ else fi # Read node urls -IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_gcp.txt +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_${BLOCKCHAIN_HOSTING}.txt # Get keystore password printf "Enter keystore password: " @@ -109,12 +118,13 @@ function config_node() { local node_index="$1" local node_url=${NODE_URL_LIST[${node_index}]} - printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_url) >>>\n\n" + printf "\n\n<<< Configuring node params of node $node_index ($node_url) >>>\n\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" - CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID keystore $KEYSTORE_FILE_PATH $PARAM" - if [[ ! $COMMAND = "get" ]]; then - CONFIG_NODE_CMD="$CONFIG_NODE_CMD '$VALUE'" + if [[ $COMMAND = "get" ]]; then + CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID $PARAM $VALUE keystore $KEYSTORE_FILE_PATH" + else + CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID $PARAM $VALUE keystore $KEYSTORE_FILE_PATH" fi printf "\n" @@ -122,6 +132,6 @@ function config_node() { eval "echo $KEYSTORE_PW | $CONFIG_NODE_CMD" } -for j in `seq $(( 0 )) $(( 9 ))`; do +for j in `seq $(( 0 )) $(( 4 ))`; do config_node "$j" done From 74c98216bc7ac5f5fae7c67ebbaf221e06ed4ab7 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 13 Sep 2024 15:51:29 +0900 Subject: [PATCH 4/5] Tweak messages of deploy scripts --- deploy_blockchain_genesis_gcp.sh | 2 +- deploy_blockchain_genesis_onprem.sh | 2 +- deploy_blockchain_incremental_gcp.sh | 2 +- deploy_blockchain_incremental_onprem.sh | 2 +- deploy_monitoring_gcp.sh | 2 +- setup_monitoring_gcp.sh | 2 +- start_node_genesis_gcp.sh | 8 ++++---- start_node_genesis_onprem.sh | 6 +++--- start_node_incremental_gcp.sh | 8 ++++---- start_node_incremental_onprem.sh | 8 ++++---- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 078868075..28205e694 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -23,7 +23,7 @@ if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ PROJECT_ID="testnet-$1-ground" fi else - printf "Invalid project/season argument: $1\n" + printf "Invalid argument: $1\n" exit fi printf "SEASON=$SEASON\n" diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 10ba48735..cc48dae34 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -16,7 +16,7 @@ printf "\n[[[[[ deploy_blockchain_genesis_onprem.sh ]]]]]\n\n" if [[ "$1" = 'staging' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'mainnet' ]]; then SEASON="$1" else - printf "Invalid project/season argument: $1\n" + printf "Invalid argument: $1\n" exit fi printf "SEASON=$SEASON\n" diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index bad1cb075..88e07d863 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -23,7 +23,7 @@ if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ PROJECT_ID="testnet-$1-ground" fi else - printf "Invalid argument: $1\n" + printf "Invalid argument: $1\n" exit fi printf "SEASON=$SEASON\n" diff --git a/deploy_blockchain_incremental_onprem.sh b/deploy_blockchain_incremental_onprem.sh index fa335cb40..aa95c8e0a 100644 --- a/deploy_blockchain_incremental_onprem.sh +++ b/deploy_blockchain_incremental_onprem.sh @@ -16,7 +16,7 @@ printf "\n[[[[[ deploy_blockchain_incremental_onprem.sh ]]]]]\n\n" if [[ "$1" = 'staging' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'mainnet' ]]; then SEASON="$1" else - printf "Invalid argument: $1\n" + printf "Invalid argument: $1\n" exit fi printf "SEASON=$SEASON\n" diff --git a/deploy_monitoring_gcp.sh b/deploy_monitoring_gcp.sh index c86e3f60a..3e4d420cf 100644 --- a/deploy_monitoring_gcp.sh +++ b/deploy_monitoring_gcp.sh @@ -19,7 +19,7 @@ if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ PROJECT_ID="testnet-$1-ground" fi else - printf "Invalid project/season argument: $1\n" + printf "Invalid argument: $1\n" exit fi printf "SEASON=$SEASON\n" diff --git a/setup_monitoring_gcp.sh b/setup_monitoring_gcp.sh index 039445369..0bb8228d9 100644 --- a/setup_monitoring_gcp.sh +++ b/setup_monitoring_gcp.sh @@ -9,7 +9,7 @@ fi printf "\n[[[[[ setup_monitoring_gcp.sh ]]]]]\n\n" if [[ "$1" != 'dev' ]] && [[ "$1" != 'staging' ]] && [[ "$1" != 'sandbox' ]] && [[ "$1" != 'exp' ]] && [[ "$1" != 'spring' ]] && [[ "$1" != 'summer' ]] && [[ "$1" != 'mainnet' ]]; then - printf "Invalid season argument: $1\n" + printf "Invalid argument: $1\n" exit fi diff --git a/start_node_genesis_gcp.sh b/start_node_genesis_gcp.sh index cd8dd26ae..c64347257 100644 --- a/start_node_genesis_gcp.sh +++ b/start_node_genesis_gcp.sh @@ -51,7 +51,7 @@ function parse_options() { if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ "$1" = 'exp' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'summer' ]] || [[ "$1" = 'mainnet' ]]; then SEASON="$1" else - printf "Invalid project/season argument: $1\n" + printf "Invalid argument: $1\n" exit fi GCP_USER="$2" @@ -119,7 +119,7 @@ printf "PEER_WHITELIST_NODE_INDEX_LE=$PEER_WHITELIST_NODE_INDEX_LE\n" # NOTE(liayoo): Currently this script supports [--keystore|--mnemonic] option only for the parent chain. if [[ $ACCOUNT_INJECTION_OPTION != "--private_key" ]] && [[ "$SHARD_INDEX" -gt 0 ]]; then - printf 'Invalid account injection option\n' + printf 'Invalid option\n' return 1 fi @@ -293,14 +293,14 @@ elif [[ $SEASON = 'dev' ]]; then elif [[ $SHARD_INDEX = 20 ]]; then export TRACKER_UPDATE_JSON_RPC_URL="http://35.201.248.92:8080/json-rpc" # dev-shard-20-tracker-ip else - printf "Invalid shard ID argument: $SHARD_INDEX\n" + printf "Invalid argument: $SHARD_INDEX\n" return 1 fi if [[ $SHARD_INDEX -gt 0 ]]; then export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/sim-shard fi else - printf "Invalid season argument: $SEASON\n" + printf "Invalid argument: $SEASON\n" return 1 fi diff --git a/start_node_genesis_onprem.sh b/start_node_genesis_onprem.sh index cfb2c4d1f..aecf528cb 100644 --- a/start_node_genesis_onprem.sh +++ b/start_node_genesis_onprem.sh @@ -61,7 +61,7 @@ function parse_options() { if [[ "$1" = 'staging' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'mainnet' ]]; then SEASON="$1" else - printf "Invalid project/season argument: $1\n" + printf "Invalid argument: $1\n" exit fi ONPREM_USER="$2" @@ -129,7 +129,7 @@ printf "PEER_WHITELIST_NODE_INDEX_LE=$PEER_WHITELIST_NODE_INDEX_LE\n" # NOTE(liayoo): Currently this script supports [--keystore|--mnemonic] option only for the parent chain. if [[ $ACCOUNT_INJECTION_OPTION != "--private_key" ]] && [[ "$SHARD_INDEX" -gt 0 ]]; then - printf 'Invalid account injection option\n' + printf 'Invalid option\n' return 1 fi @@ -240,7 +240,7 @@ elif [[ $SEASON = 'staging' ]]; then export PEER_WHITELIST="0x00ADEc28B6a845a085e03591bE7550dd68673C1C,0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204,0x02A2A1DF4f630d760c82BE07F18e5065d103Fa00,0x03AAb7b6f16A92A1dfe018Fe34ee420eb098B98A,0x04A456C92A880cd59D7145C457475515a6f6E0f2,0x05A1247A7400f0C2A893611adD1505743552c631,0x06AD9C8F611f1e9d9CACD4738167A51aA2e80a1A,0x07A43138CC760C85A5B1F115aa60eADEaa0bf417,0x08Aed7AF9354435c38d52143EE50ac839D20696b,0x09A0d53FDf1c36A131938eb379b98910e55EEfe1" fi else - printf "Invalid season argument: $SEASON\n" + printf "Invalid argument: $SEASON\n" return 1 fi diff --git a/start_node_incremental_gcp.sh b/start_node_incremental_gcp.sh index e70433c57..f16cf1f90 100644 --- a/start_node_incremental_gcp.sh +++ b/start_node_incremental_gcp.sh @@ -50,7 +50,7 @@ function parse_options() { if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ "$1" = 'exp' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'summer' ]] || [[ "$1" = 'mainnet' ]]; then SEASON="$1" else - printf "Invalid project/season argument: $1\n" + printf "Invalid argument: $1\n" exit fi GCP_USER="$2" @@ -224,7 +224,7 @@ elif [[ $SEASON = 'dev' ]]; then EOF fi else - printf "Invalid argument: $SEASON\n" + printf "Invalid argument: $SEASON\n" exit fi @@ -235,7 +235,7 @@ printf "PEER_WHITELIST=$PEER_WHITELIST\n" # NOTE(liayoo): Currently this script supports [--keystore|--mnemonic] option only for the parent chain. if [[ $ACCOUNT_INJECTION_OPTION != "--private_key" ]] && [[ "$SHARD_INDEX" -gt 0 ]]; then - printf 'Invalid account injection option\n' + printf 'Invalid option\n' return 1 fi @@ -285,7 +285,7 @@ fi # NOTE(liayoo): Currently this script supports [--keystore|--mnemonic] option only for the parent chain. if [[ $ACCOUNT_INJECTION_OPTION != "private_key" ]] && [[ "$SHARD_INDEX" -gt 0 ]]; then - printf 'Invalid account injection option\n' + printf 'Invalid option\n' exit fi diff --git a/start_node_incremental_onprem.sh b/start_node_incremental_onprem.sh index 03d3a6226..ee4d87353 100644 --- a/start_node_incremental_onprem.sh +++ b/start_node_incremental_onprem.sh @@ -60,7 +60,7 @@ function parse_options() { if [[ "$1" = 'staging' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'mainnet' ]]; then SEASON="$1" else - printf "Invalid project/season argument: $1\n" + printf "Invalid argument: $1\n" exit fi ONPREM_USER="$2" @@ -157,7 +157,7 @@ elif [[ $SEASON = 'staging' ]]; then # NOTE(platfowner): For non-api-servers, the value in the blockchain configs # (https://staging-api.ainetwork.ai/json-rpc) is used. else - printf "Invalid argument: $SEASON\n" + printf "Invalid argument: $SEASON\n" exit fi @@ -168,7 +168,7 @@ printf "PEER_WHITELIST=$PEER_WHITELIST\n" # NOTE(liayoo): Currently this script supports [--keystore|--mnemonic] option only for the parent chain. if [[ $ACCOUNT_INJECTION_OPTION != "--private_key" ]] && [[ "$SHARD_INDEX" -gt 0 ]]; then - printf 'Invalid account injection option\n' + printf 'Invalid option\n' return 1 fi @@ -218,7 +218,7 @@ fi # NOTE(liayoo): Currently this script supports [--keystore|--mnemonic] option only for the parent chain. if [[ $ACCOUNT_INJECTION_OPTION != "private_key" ]] && [[ "$SHARD_INDEX" -gt 0 ]]; then - printf 'Invalid account injection option\n' + printf 'Invalid option\n' exit fi From 8ecd02d6db66f496d61795e8bfef41ce6de193e4 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 13 Sep 2024 18:37:12 +0900 Subject: [PATCH 5/5] Rename port number directory in blockchain data uploading --- copy_blockchain_data_gcp.sh | 38 +++++++++++++++++++++++++++++----- copy_blockchain_data_onprem.sh | 38 +++++++++++++++++++++++++++++----- 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/copy_blockchain_data_gcp.sh b/copy_blockchain_data_gcp.sh index b53c4ae07..f91efd56d 100644 --- a/copy_blockchain_data_gcp.sh +++ b/copy_blockchain_data_gcp.sh @@ -1,14 +1,14 @@ #!/bin/bash function usage() { - printf "Usage: bash copy_blockchain_data_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [download|upload]\n" + printf "Usage: bash copy_blockchain_data_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [download|upload] [ ]\n" printf "Example: bash copy_blockchain_data_gcp.sh spring 0 download\n" - printf "Example: bash copy_blockchain_data_gcp.sh spring 1 upload\n" + printf "Example: bash copy_blockchain_data_gcp.sh spring 1 upload 8079 8080\n" printf "\n" exit } -if [[ $# -lt 3 ]] || [[ $# -gt 3 ]]; then +if [[ $# != 3 ]] && [[ $# != 5 ]]; then usage fi @@ -22,7 +22,7 @@ if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ PROJECT_ID="testnet-$1-ground" fi else - printf "Invalid argument: $1\n" + printf "Invalid argument: $1\n" exit fi printf "\n" @@ -56,6 +56,28 @@ else fi printf "COMMAND=$COMMAND\n" +if [[ "$COMMAND" = 'download' ]]; then + if [[ $# != 3 ]]; then + printf "\n" + printf " and can be used only with 'upload' command.\n" + printf "\n" + usage + fi + OLD_PORT="" + NEW_PORT="" +else + if [[ $# != 5 ]]; then + printf "\n" + printf " and should be specified with 'upload' command.\n" + printf "\n" + usage + fi + OLD_PORT="$4" + NEW_PORT="$5" +fi +printf "OLD_PORT=$OLD_PORT\n" +printf "NEW_PORT=$NEW_PORT\n" + # Get confirmation. if [[ "$SEASON" = "mainnet" ]]; then printf "\n" @@ -151,7 +173,13 @@ function upload_data() { printf "TGZ_CMD=$TGZ_CMD\n\n" eval $TGZ_CMD - # 3. Clean up tgz file for node + # 3. Change port number directory + printf "\n\n<<< Changing port number directory for node $node_index >>>\n\n" + MV_CMD="gcloud compute ssh $node_target_addr --command 'mv /home/ain_blockchain_data/chains/${OLD_PORT} /home/ain_blockchain_data/chains/${NEW_PORT}; mv /home/ain_blockchain_data/snapshots/${OLD_PORT} /home/ain_blockchain_data/snapshots/${NEW_PORT}' --project $PROJECT_ID --zone $node_zone" + printf "MV_CMD=$MV_CMD\n\n" + eval $MV_CMD + + # 4. Clean up tgz file for node printf "\n\n<<< Cleaning up tgz file for node $node_index >>>\n\n" CLEANUP_CMD="gcloud compute ssh $node_target_addr --command 'rm ~/ain_blockchain_data.tar.gz' --project $PROJECT_ID --zone $node_zone" printf "CLEANUP_CMD=$CLEANUP_CMD\n\n" diff --git a/copy_blockchain_data_onprem.sh b/copy_blockchain_data_onprem.sh index 72b62b67d..918ea12a1 100644 --- a/copy_blockchain_data_onprem.sh +++ b/copy_blockchain_data_onprem.sh @@ -1,21 +1,21 @@ #!/bin/bash function usage() { - printf "Usage: bash copy_blockchain_data_onprem.sh [staging|spring|mainnet] [download|upload]\n" + printf "Usage: bash copy_blockchain_data_onprem.sh [staging|spring|mainnet] [download|upload] [ ]\n" printf "Example: bash copy_blockchain_data_onprem.sh staging 0 download\n" - printf "Example: bash copy_blockchain_data_onprem.sh staging 1 upload\n" + printf "Example: bash copy_blockchain_data_onprem.sh staging 1 upload 8080 8079\n" printf "\n" exit } -if [[ $# -lt 3 ]] || [[ $# -gt 3 ]]; then +if [[ $# != 3 ]] && [[ $# != 5 ]]; then usage fi if [[ "$1" = 'staging' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'mainnet' ]]; then SEASON="$1" else - printf "Invalid argument: $1\n" + printf "Invalid argument: $1\n" exit fi printf "\n" @@ -48,6 +48,28 @@ else fi printf "COMMAND=$COMMAND\n" +if [[ "$COMMAND" = 'download' ]]; then + if [[ $# != 3 ]]; then + printf "\n" + printf " and can be used only with 'upload' command.\n" + printf "\n" + usage + fi + OLD_PORT="" + NEW_PORT="" +else + if [[ $# != 5 ]]; then + printf "\n" + printf " and should be specified with 'upload' command.\n" + printf "\n" + usage + fi + OLD_PORT="$4" + NEW_PORT="$5" +fi +printf "OLD_PORT=$OLD_PORT\n" +printf "NEW_PORT=$NEW_PORT\n" + # Get confirmation. if [[ "$SEASON" = "mainnet" ]]; then printf "\n" @@ -120,7 +142,13 @@ function upload_data() { printf "TGZ_CMD=$TGZ_CMD\n\n" eval "echo ${node_login_pw} | sshpass -f <(printf '%s\n' ${node_login_pw}) ${TGZ_CMD}" - # 3. Clean up tgz file for node + # 3. Change port number directory + printf "\n\n<<< Changing port number directory for node $node_index >>>\n\n" + MV_CMD="ssh $node_target_addr 'mv /home/${SEASON}/ain_blockchain_data/chains/${OLD_PORT} /home/${SEASON}/ain_blockchain_data/chains/${NEW_PORT}; mv /home/${SEASON}/ain_blockchain_data/snapshots/${OLD_PORT} /home/${SEASON}/ain_blockchain_data/snapshots/${NEW_PORT}'" + printf "MV_CMD=$MV_CMD\n\n" + eval "sshpass -f <(printf '%s\n' ${node_login_pw}) ${MV_CMD}" + + # 4. Clean up tgz file for node printf "\n\n<<< Cleaning up tgz file for node $node_index >>>\n\n" CLEANUP_CMD="ssh $node_target_addr 'rm ~/ain_blockchain_data.tar.gz'" printf "CLEANUP_CMD=$CLEANUP_CMD\n\n"