Skip to content

Commit

Permalink
Always do make install to make sure binary is newest, in-case sourc…
Browse files Browse the repository at this point in the history
…e code was changed (#23)

- Always do `make install`
- Forward all ERR msg to stderr
  • Loading branch information
VictorTrustyDev committed Jun 26, 2022
1 parent 41d23f9 commit 74d2c97
Show file tree
Hide file tree
Showing 17 changed files with 308 additions and 181 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Here you can find sample scripts and notes of how to [setup multiple EVMOS chains](https://github.com/VictorTrustyDev/EVMOS-sample-scripts/tree/main/blockchain-in-docker) and [connect them via an IBC (using Hermes as relayer)](https://github.com/VictorTrustyDev/EVMOS-sample-scripts/tree/main/hermes-as-ibc-relayer) to transfer tokens & coins cross chains, as well as block explorers for them (using Big Dipper 2.0 for Cosmos based chains)
### Here you can find sample scripts and notes of how to [setup multiple EVMOS chains](https://github.com/VictorTrustyDev/EVMOS-sample-scripts/tree/main/blockchain-in-docker) and [connect them via an IBC (using Hermes as relayer)](https://github.com/VictorTrustyDev/EVMOS-sample-scripts/tree/main/hermes-as-ibc-relayer) to transfer tokens & coins cross chains, as well as [block explorers for them](https://github.com/VictorTrustyDev/EVMOS-sample-scripts/tree/main/big-dipper-as-block-explorer) (using Big Dipper 2.0 for Cosmos based chains)

I wrote hundred lines of comments which explains every steps in each script file and each readme file, hope that helps you guys in exploring Evmos & Cosmos Ecosystem

Expand Down
11 changes: 6 additions & 5 deletions all-in-one.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
# It is not recommended to use this script

if [ ! -f "./env.sh" ]; then
echo "Wrong working directory"
echo >&2 "ERR: Wrong working directory"
exit 1
fi

show_required_tools() {
MSG="'$1' tool is required"
echo >&2 "$MSG"
echo >&2 "ERR: $MSG"
echo >&2 "______"
echo >&2 "The app requires following tools:"
echo >&2 "- jq"
Expand All @@ -36,7 +36,7 @@ show_required_tools() {
echo >&2 " + https://hasura.io/docs/latest/graphql/core/hasura-cli/install-hasura-cli/"
echo >&2 " + Hint: curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash"
echo >&2 "______"
echo >&2 "$MSG"
echo >&2 "ERR: $MSG"
}

command -v jq > /dev/null 2>&1 || { show_required_tools 'jq'; exit 1; }
Expand Down Expand Up @@ -74,8 +74,8 @@ echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
command -v systemctl > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "`systemd` is required!!! You better prepare an Ubuntu machine and try this later.."
if [ $? -ne 0 ] || [ ! -d "/etc/systemd/system" ] ; then
echo >&2 "`systemd` is required!!! You better prepare an Ubuntu machine and try this later.."
exit 1
fi
echo " ! OK, let's go"
Expand Down Expand Up @@ -184,3 +184,4 @@ echo "1. Check 3 validator containers & make sure they are proceducing block"
echo "2. Make sure bdjuno & hasura services are ok"
echo "3. Go to block explorer UI and check things there"
echo "4. Check Hermes is working well"
echo "5. Make sure the service files at '/etc/systemd/system/*.service' has correct working directort and execution path (in case you changed any repo/branch)"
62 changes: 44 additions & 18 deletions big-dipper-as-block-explorer/1_install-bdjuno.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

command -v docker > /dev/null 2>&1 || { echo >&2 "docker is required"; exit 1; }
command -v psql > /dev/null 2>&1 || { echo >&2 "psql is required, you first need to install psql client. Hint: sudo apt install postgresql-client"; exit 1; }
command -v docker > /dev/null 2>&1 || { echo >&2 "ERR: docker is required"; exit 1; }
command -v psql > /dev/null 2>&1 || { echo >&2 "ERR: psql is required, you first need to install psql client. Hint: sudo apt install postgresql-client"; exit 1; }

source ../env.sh

Expand All @@ -14,8 +14,8 @@ fi
if [ -f "./_config.sh" ]; then
source "./_config.sh"
else
echo "ERR: Wrong working directory"
echo "ERR: Scripts must be executed within [big-dipper-as-block-explorer] directory"
echo >&2 "ERR: Wrong working directory"
echo >&2 "Scripts must be executed within [big-dipper-as-block-explorer] directory"
exit 1
fi

Expand All @@ -25,10 +25,10 @@ if [ "$CHAIN_NO" = "1" ]; then
elif [ "$CHAIN_NO" = "2" ]; then
echo "Chain 2"
else
echo 'Missing or incorrect chain no as first argument, valid input is 1 or 2'
echo 'For example:'
echo " $0 1"
echo " or: $0 2"
echo >&2 'ERR: Missing or incorrect chain no as first argument, valid input is 1 or 2'
echo >&2 'For example:'
echo >&2 " $0 1"
echo >&2 " or: $0 2"
exit 1
fi

Expand Down Expand Up @@ -57,38 +57,64 @@ docker run \
-e POSTGRES_PASSWORD=$BD_CFG_PG_USR_PASS \
-v $PG_VOL_NAME:/data/db \
postgres:12.5
[ $? -eq 0 ] || { echo "ERR: Failed to create a PostgreSQL container"; }
[ $? -eq 0 ] || { echo >&2 "ERR: Failed to create a PostgreSQL container"; }

echo 'Waiting DB up'
sleep 3s

echo "- Creating database $BD_PG_DB"
PGPASSWORD=$BD_CFG_PG_USR_PASS psql -h 127.0.0.1 -p $PG_PORT -d postgres -U postgres -c "CREATE DATABASE $BD_PG_DB;"
[ $? -eq 0 ] || { echo "ERR: Operation failed!"; }
[ $? -eq 0 ] || { echo >&2 "ERR: Operation failed!"; }
echo "- Creating user $BD_PG_USER"
PGPASSWORD=$BD_CFG_PG_USR_PASS psql -h 127.0.0.1 -p $PG_PORT -d postgres -U postgres -c "CREATE USER $BD_PG_USER WITH ENCRYPTED PASSWORD '$BD_PG_PASS';"
[ $? -eq 0 ] || { echo "ERR: Operation failed!"; }
[ $? -eq 0 ] || { echo >&2 "ERR: Operation failed!"; }
echo "- Grant all privileges on db $BD_PG_DB to user $BD_PG_USER"
PGPASSWORD=$BD_CFG_PG_USR_PASS psql -h 127.0.0.1 -p $PG_PORT -d postgres -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE $BD_PG_DB TO $BD_PG_USER;"
[ $? -eq 0 ] || { echo "ERR: Operation failed!"; }
[ $? -eq 0 ] || { echo >&2 "ERR: Operation failed!"; }

# Check bdjuno source
# If the repo is different with config, show a warning
if [ -d "./$BD_SOURCE_DIR" ]; then
echo "bdjuno repo was downloaded"
echo "bdjuno repo exists"
echo "Checking repo url & branch name"
CHK_RES_1="$(git --git-dir "./$BD_SOURCE_DIR"/.git --work-tree "./$BD_SOURCE_DIR" config --get remote.origin.url)"
if [ $? -ne 0 ] || [ -z "$CHK_RES_1" ]; then
echo "WARN! Unable to check remote origin url of git repo at $BD_SOURCE_DIR"
sleep 2s
elif [ "$CHK_RES_1" != "$BD_GIT_REPO" ]; then
echo "WARN! Git repo Url does not match"
echo "Expected: '$BD_GIT_REPO'"
echo "Actual: '$CHK_RES_1'"
echo "You should check it (script will continue execution after 10s)"
sleep 10s
fi
CHK_RES_2="$(git --git-dir "./$BD_SOURCE_DIR"/.git --work-tree "./$BD_SOURCE_DIR" rev-parse --abbrev-ref HEAD)"
if [ $? -ne 0 ] || [ -z "$CHK_RES_2" ]; then
echo "WARN! Unable to check branch of git repo at $BD_SOURCE_DIR"
sleep 2s
elif [ "$CHK_RES_2" = "HEAD" ]; then
echo "WARN! Can not check branch"
elif [ "$CHK_RES_2" != "$BD_GIT_BRANCH" ]; then
echo "WARN! Git Branch does not match"
echo "Expected: '$BD_GIT_BRANCH'"
echo "Actual: '$CHK_RES_2'"
echo "You should check it (script will continue execution after 10s)"
sleep 10s
fi
else
echo "Downloading bdjuno source code from branch $BD_BRANCH"
git clone "$BD_GIT_REPO" --branch "$BD_BRANCH" --single-branch "$BD_SOURCE_DIR"
echo "Downloading bdjuno source code from branch $BD_GIT_BRANCH"
git clone "$BD_GIT_REPO" --branch "$BD_GIT_BRANCH" --single-branch "$BD_SOURCE_DIR"

if [ $? -ne 0 ]; then
echo "Git clone bdjuno branch $BD_BRANCH failed"
echo >&2 "ERR: Git clone bdjuno branch $BD_GIT_BRANCH failed"
exit 1
fi
fi

SCHEMA_DIR="./$BD_SOURCE_DIR/database/schema"

if [ ! -d "$SCHEMA_DIR" ]; then
echo "ERR: Schema dir $SCHEMA_DIR could not be found"
echo >&2 "ERR: Schema dir $SCHEMA_DIR could not be found"
exit 1
fi

Expand All @@ -102,7 +128,7 @@ cd "./$BD_SOURCE_DIR"
echo
echo 'Compiling bdjuno'
make install
[ $? -ne 0 ] && { echo "ERR: Failed to compile"; exit 1; }
[ $? -ne 0 ] && { echo >&2 "ERR: Failed to compile"; exit 1; }
echo "Rename $BD_BINARY_ORIGIN into $BD_BINARY"
mv "$BD_BINARY_ORIGIN" "$BD_BINARY"
cd "$CUR_DIR"
Expand Down
21 changes: 11 additions & 10 deletions big-dipper-as-block-explorer/2_install-bdjuno.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ fi
if [ -f "./_config.sh" ]; then
source "./_config.sh"
else
echo "ERR: Wrong working directory"
echo "ERR: Scripts must be executed within [big-dipper-as-block-explorer] directory"
echo >&2 "ERR: Wrong working directory"
echo >&2 "Scripts must be executed within [big-dipper-as-block-explorer] directory"
exit 1
fi

Expand All @@ -22,10 +22,10 @@ if [ "$CHAIN_NO" = "1" ]; then
elif [ "$CHAIN_NO" = "2" ]; then
echo "Chain 2"
else
echo 'Missing or incorrect chain no as first argument, valid input is 1 or 2'
echo 'For example:'
echo " $0 1"
echo " or: $0 2"
echo >&2 'ERR: Missing or incorrect chain no as first argument, valid input is 1 or 2'
echo >&2 'For example:'
echo >&2 " $0 1"
echo >&2 " or: $0 2"
exit 1
fi

Expand All @@ -41,23 +41,23 @@ if [ ! -f "$GENESIS_JSON" ]; then
if [ $EXTRA_FUNC -eq 1 ]; then
cp '../blockchain-in-docker/.evmosd'$CHAIN_NO'0/config/genesis.json' "$GENESIS_JSON"
if [ ! -f "$GENESIS_JSON" ]; then
echo "Please copy genesis.json from your chain into $BD_HOME"
echo >&2 "ERR: Please copy genesis.json from your chain into $BD_HOME"
exit 1
fi
else
echo "Missing genesis.json file (expect: $GENESIS_JSON)"
echo >&2 "ERR: Missing genesis.json file (expect: $GENESIS_JSON)"
echo "Please copy that file from your chain"
exit 1
fi
fi
echo "Parsing genesis file"
$BD_BINARY parse genesis-file --genesis-file-path "$GENESIS_JSON" --home "$BD_HOME"
[ $? -eq 0 ] || { echo "ERR: Failed to parse genesis.json!"; exit 1; }
[ $? -eq 0 ] || { echo >&2 "ERR: Failed to parse genesis.json!"; exit 1; }
## Check chain id
GENESIS_CHAIN_ID=$(cat "$GENESIS_JSON" | jq .chain_id | head -n 1 | tr -d '"')

if [ "$GENESIS_CHAIN_ID" != "$CHAIN_ID" ]; then
echo "ERR: Mis-match chain id, expect [$CHAIN_ID] but found [$GENESIS_CHAIN_ID] on genesis.json"
echo >&2 "ERR: Mis-match chain id, expect [$CHAIN_ID] but found [$GENESIS_CHAIN_ID] on genesis.json"
exit 1
fi

Expand Down Expand Up @@ -111,6 +111,7 @@ if [ $DISABLE_SYSTEMCTL -eq 0 ]; then
fi

echo 'Finished bdjuno installtion'
echo "Notice!!! Make sure the service file at '/etc/systemd/system/$BD_SERVICE_NAME.service' has correct working directort and execution path (in case you changed any repo/branch)"
echo
echo 'Now move to install Hasura by running 3_install-hasura.sh'

Expand Down
18 changes: 9 additions & 9 deletions big-dipper-as-block-explorer/3_install-hasura.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

command -v docker > /dev/null 2>&1 || { echo >&2 "docker is required"; exit 1; }
command -v psql > /dev/null 2>&1 || { echo >&2 "psql is required, you first need to install psql client. Hint: sudo apt install postgresql-client"; exit 1; }
command -v docker > /dev/null 2>&1 || { echo >&2 "ERR: docker is required"; exit 1; }
command -v psql > /dev/null 2>&1 || { echo >&2 "ERR: psql is required, you first need to install psql client. Hint: sudo apt install postgresql-client"; exit 1; }

source ../env.sh

Expand All @@ -14,8 +14,8 @@ fi
if [ -f "./_config.sh" ]; then
source "./_config.sh"
else
echo "ERR: Wrong working directory"
echo "ERR: Scripts must be executed within [big-dipper-as-block-explorer] directory"
echo >&2 "ERR: Wrong working directory"
echo >&2 "Scripts must be executed within [big-dipper-as-block-explorer] directory"
exit 1
fi

Expand All @@ -25,10 +25,10 @@ if [ "$CHAIN_NO" = "1" ]; then
elif [ "$CHAIN_NO" = "2" ]; then
echo "Chain 2"
else
echo 'Missing or incorrect chain no as first argument, valid input is 1 or 2'
echo 'For example:'
echo " $0 1"
echo " or: $0 2"
echo >&2 'ERR: Missing or incorrect chain no as first argument, valid input is 1 or 2'
echo >&2 'For example:'
echo >&2 " $0 1"
echo >&2 " or: $0 2"
exit 1
fi

Expand All @@ -37,7 +37,7 @@ if [ -f "$BD_HASURA_BINARY" ]; then
elif [ command -v hasura > /dev/null 2>&1 ]; then
export BD_HASURA_BINARY="hasura"
else
echo "hasura-cli is required, more info: https://hasura.io/docs/latest/graphql/core/hasura-cli/install-hasura-cli/ . Hint: curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash"
echo >&2 "ERR: hasura-cli is required, more info: https://hasura.io/docs/latest/graphql/core/hasura-cli/install-hasura-cli/ . Hint: curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash"
exit 1
fi

Expand Down
53 changes: 40 additions & 13 deletions big-dipper-as-block-explorer/4_install-front-end.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

command -v npm > /dev/null 2>&1 || { echo >&2 "npm is required"; exit 1; }
command -v npm > /dev/null 2>&1 || { echo >&2 "ERR: npm is required"; exit 1; }

source ../env.sh

Expand All @@ -13,8 +13,8 @@ fi
if [ -f "./_config.sh" ]; then
source "./_config.sh"
else
echo "ERR: Wrong working directory"
echo "ERR: Scripts must be executed within [big-dipper-as-block-explorer] directory"
echo >&2 "ERR: Wrong working directory"
echo >&2 "Scripts must be executed within [big-dipper-as-block-explorer] directory"
exit 1
fi

Expand All @@ -24,10 +24,10 @@ if [ "$CHAIN_NO" = "1" ]; then
elif [ "$CHAIN_NO" = "2" ]; then
echo "Chain 2"
else
echo 'Missing or incorrect chain no as first argument, valid input is 1 or 2'
echo 'For example:'
echo " $0 1"
echo " or: $0 2"
echo >&2 'ERR: Missing or incorrect chain no as first argument, valid input is 1 or 2'
echo >&2 'For example:'
echo >&2 " $0 1"
echo >&2 " or: $0 2"
exit 1
fi

Expand All @@ -40,13 +40,38 @@ fi

# Check Big Dipper 2.0 source
if [ -d "$BD2_SOURCE_DIR" ]; then
echo "Big Dipper 2.0 repo was downloaded"
echo "Big Dipper 2.0 repo exists"
echo "Checking repo url & branch name"
CHK_RES_1="$(git --git-dir "./$BD2_SOURCE_DIR"/.git --work-tree "./$BD2_SOURCE_DIR" config --get remote.origin.url)"
if [ $? -ne 0 ] || [ -z "$CHK_RES_1" ]; then
echo "WARN! Unable to check remote origin url of git repo at $BD2_SOURCE_DIR"
sleep 2s
elif [ "$CHK_RES_1" != "$BD2_GIT_REPO" ]; then
echo "WARN! Git repo Url does not match"
echo "Expected: '$BD2_GIT_REPO'"
echo "Actual: '$CHK_RES_1'"
echo "You should check it (script will continue execution after 10s)"
sleep 10s
fi
CHK_RES_2="$(git --git-dir "./$BD2_SOURCE_DIR"/.git --work-tree "./$BD2_SOURCE_DIR" rev-parse --abbrev-ref HEAD)"
if [ $? -ne 0 ] || [ -z "$CHK_RES_2" ]; then
echo "WARN! Unable to check branch of git repo at $BD2_SOURCE_DIR"
sleep 2s
elif [ "$CHK_RES_2" = "HEAD" ]; then
echo "WARN! Can not check branch"
elif [ "$CHK_RES_2" != "$BD2_BRANCH" ]; then
echo "WARN! Git Branch does not match"
echo "Expected: '$BD2_BRANCH'"
echo "Actual: '$CHK_RES_2'"
echo "You should check it (script will continue execution after 10s)"
sleep 10s
fi
else
echo "Downloading Big Dipper 2.0 source code from branch $BD2_BRANCH"
git clone "$BD2_GIT_REPO" --branch "$BD2_BRANCH" --single-branch "$BD2_SOURCE_DIR"

if [ $? -ne 0 ]; then
echo "Git clone Big Dipper 2.0 from branch $BD2_BRANCH was failed"
echo >&2 "ERR: Git clone Big Dipper 2.0 from branch $BD2_BRANCH was failed"
exit 1
fi
fi
Expand Down Expand Up @@ -93,14 +118,14 @@ WORKING_DIR=$(pwd)
# Build
## Install graphql-codegen
npm i -D @graphql-codegen/cli > /dev/null 2>&1
[ $? -eq 0 ] || { echo "Failed to install @graphql-codegen/cli"; exit 1; }
[ $? -eq 0 ] || { echo >&2 "ERR: Failed to install @graphql-codegen/cli"; exit 1; }
## Gen code
echo 'Generating code'
npm run graphql:codegen
[ $? -eq 0 ] || { echo "Failed to run graphql:codegen"; exit 1; }
[ $? -eq 0 ] || { echo >&2 "ERR: Failed to run graphql:codegen"; exit 1; }
#echo 'Build'
#npm run build
#[ $? -eq 0 ] || { echo "Failed to build"; exit 1; }
#[ $? -eq 0 ] || { echo >&2 "ERR: Failed to build"; exit 1; }

cd "$CUR_DIR"

Expand Down Expand Up @@ -147,4 +172,6 @@ if [ $DISABLE_SYSTEMCTL -eq 0 ]; then
else
echo "OK, you can run it now"
echo "Hint: npm run dev"
fi
fi

echo "Notice!!! Make sure the service file at '/etc/systemd/system/$BD2_SERVICE_NAME.service' has correct working directort and execution path (in case you changed any repo/branch)"
Loading

0 comments on commit 74d2c97

Please sign in to comment.