From 4617325367c75be70112e0bf5811e265cb1b9971 Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 3 Jun 2018 17:19:33 -0400 Subject: [PATCH] Convert all scripts into a basic bash cli --- .../initShyftGeth.sh | 2 +- .../postgres_setup/create_shyftdb.psql | 0 .../postgres_setup/create_tables.psql | 0 .../postgres_setup/drop_tables.psql | 0 .../postgres_setup/drop_tables.sh | 3 ++ .../postgres_setup/init_tables.sh | 3 ++ shyft-cli/postgres_setup/initdb.sh | 4 +++ .../resetShyftGeth.sh | 0 run_js_in_geth.sh => shyft-cli/runJs.sh | 2 +- shyft-cli/setup.sh | 17 +++++++++ shyft-cli/shyftFullReset.sh | 12 +++++++ .../startShyftGeth.sh | 0 .../web3}/checkbalances.js | 0 .../web3}/deployContract.js | 0 .../web3}/getGreeting.js | 0 .../web3}/sendTransactions.js | 0 .../web3}/token_test/README.md | 0 .../web3}/token_test/callGreeterFnsTest.js | 0 .../web3}/token_test/call_greeter_fns.js | 0 .../web3}/token_test/calltx.js | 0 .../web3}/token_test/deploy.js | 0 .../token_test/deploy_greeter_contracts.js | 0 .../web3}/token_test/package.json | 0 .../web3}/token_test/token.sol | 0 shyft-geth.sh | 36 +++++++++++++++++++ shyftDb/postgres_setup/initdb.sh | 1 - shyftFullReset.sh | 5 --- 27 files changed, 77 insertions(+), 8 deletions(-) rename initShyftGeth.sh => shyft-cli/initShyftGeth.sh (62%) rename {shyftDb => shyft-cli}/postgres_setup/create_shyftdb.psql (100%) rename {shyftDb => shyft-cli}/postgres_setup/create_tables.psql (100%) rename {shyftDb => shyft-cli}/postgres_setup/drop_tables.psql (100%) rename {shyftDb => shyft-cli}/postgres_setup/drop_tables.sh (52%) rename {shyftDb => shyft-cli}/postgres_setup/init_tables.sh (53%) create mode 100644 shyft-cli/postgres_setup/initdb.sh rename resetShyftGeth.sh => shyft-cli/resetShyftGeth.sh (100%) rename run_js_in_geth.sh => shyft-cli/runJs.sh (80%) create mode 100644 shyft-cli/setup.sh create mode 100644 shyft-cli/shyftFullReset.sh rename startShyftGeth.sh => shyft-cli/startShyftGeth.sh (100%) rename {simulations => shyft-cli/web3}/checkbalances.js (100%) rename {simulations => shyft-cli/web3}/deployContract.js (100%) rename {simulations => shyft-cli/web3}/getGreeting.js (100%) rename {simulations => shyft-cli/web3}/sendTransactions.js (100%) rename {simulations => shyft-cli/web3}/token_test/README.md (100%) rename {simulations => shyft-cli/web3}/token_test/callGreeterFnsTest.js (100%) rename {simulations => shyft-cli/web3}/token_test/call_greeter_fns.js (100%) rename {simulations => shyft-cli/web3}/token_test/calltx.js (100%) rename {simulations => shyft-cli/web3}/token_test/deploy.js (100%) rename {simulations => shyft-cli/web3}/token_test/deploy_greeter_contracts.js (100%) rename {simulations => shyft-cli/web3}/token_test/package.json (100%) rename {simulations => shyft-cli/web3}/token_test/token.sol (100%) create mode 100755 shyft-geth.sh delete mode 100644 shyftDb/postgres_setup/initdb.sh delete mode 100644 shyftFullReset.sh diff --git a/initShyftGeth.sh b/shyft-cli/initShyftGeth.sh similarity index 62% rename from initShyftGeth.sh rename to shyft-cli/initShyftGeth.sh index c6a8d115e1..222a23e052 100755 --- a/initShyftGeth.sh +++ b/shyft-cli/initShyftGeth.sh @@ -1,2 +1,2 @@ #!/bin/sh -./build/bin/geth --identity "ShyftTestnetNode" --keystore ./ --datadir "./shyftData" init ShyftNetwork.json \ No newline at end of file +./build/bin/geth --identity "ShyftTestnetNode" --keystore ./ --datadir "./shyftData" init ShyftNetwork.json diff --git a/shyftDb/postgres_setup/create_shyftdb.psql b/shyft-cli/postgres_setup/create_shyftdb.psql similarity index 100% rename from shyftDb/postgres_setup/create_shyftdb.psql rename to shyft-cli/postgres_setup/create_shyftdb.psql diff --git a/shyftDb/postgres_setup/create_tables.psql b/shyft-cli/postgres_setup/create_tables.psql similarity index 100% rename from shyftDb/postgres_setup/create_tables.psql rename to shyft-cli/postgres_setup/create_tables.psql diff --git a/shyftDb/postgres_setup/drop_tables.psql b/shyft-cli/postgres_setup/drop_tables.psql similarity index 100% rename from shyftDb/postgres_setup/drop_tables.psql rename to shyft-cli/postgres_setup/drop_tables.psql diff --git a/shyftDb/postgres_setup/drop_tables.sh b/shyft-cli/postgres_setup/drop_tables.sh similarity index 52% rename from shyftDb/postgres_setup/drop_tables.sh rename to shyft-cli/postgres_setup/drop_tables.sh index 576637538a..b0d91aa52e 100644 --- a/shyftDb/postgres_setup/drop_tables.sh +++ b/shyft-cli/postgres_setup/drop_tables.sh @@ -1 +1,4 @@ +#!/bin/bash + +cd ./shyft-cli/postgres_setup psql -U postgres -d shyftdb -f drop_tables.psql \ No newline at end of file diff --git a/shyftDb/postgres_setup/init_tables.sh b/shyft-cli/postgres_setup/init_tables.sh similarity index 53% rename from shyftDb/postgres_setup/init_tables.sh rename to shyft-cli/postgres_setup/init_tables.sh index 988ad56700..50dfb4e695 100644 --- a/shyftDb/postgres_setup/init_tables.sh +++ b/shyft-cli/postgres_setup/init_tables.sh @@ -1 +1,4 @@ +#!/bin/bash + +cd ./shyft-cli/postgres_setup psql -U postgres -d shyftdb -f create_tables.psql diff --git a/shyft-cli/postgres_setup/initdb.sh b/shyft-cli/postgres_setup/initdb.sh new file mode 100644 index 0000000000..de2cf1c295 --- /dev/null +++ b/shyft-cli/postgres_setup/initdb.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +cd ./shyft-cli/postgres_setup +psql -U postgres -f create_shyftdb.psql diff --git a/resetShyftGeth.sh b/shyft-cli/resetShyftGeth.sh similarity index 100% rename from resetShyftGeth.sh rename to shyft-cli/resetShyftGeth.sh diff --git a/run_js_in_geth.sh b/shyft-cli/runJs.sh similarity index 80% rename from run_js_in_geth.sh rename to shyft-cli/runJs.sh index b4a6649154..5c7f3e4fbd 100644 --- a/run_js_in_geth.sh +++ b/shyft-cli/runJs.sh @@ -1,4 +1,4 @@ file=$1 -echo $file +echo Executing "${file}"... runthing="./build/bin/geth --exec 'loadScript(\""$file"\")' attach http://127.0.0.1:8545" eval $runthing diff --git a/shyft-cli/setup.sh b/shyft-cli/setup.sh new file mode 100644 index 0000000000..dfb23704ee --- /dev/null +++ b/shyft-cli/setup.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +if ! psql -lqt | cut -d \| -f 1 | grep -qw shyftdb; then # Check if db is instantiated + echo Creating postgres db... + sh ./shyft-cli/postgres_setup/initdb.sh && # Init DB + echo Successfully created postgres db! && + sh ./shyft-cli/postgres_setup/init_tables.sh && # Init tables + sh ./shyft-cli/resetShyftGeth.sh && # Reset geth data + sh ./shyft-cli/initShyftGeth.sh # Init Shyft Geth +else + echo Postgres DB found! + sh ./shyft-cli/postgres_setup/drop_tables.sh && # Drop tables + sh ./shyft-cli/postgres_setup/init_tables.sh && # Init tables + sh ./shyft-cli/resetShyftGeth.sh && # Reset geth data + sh ./shyft-cli/initShyftGeth.sh # Init Shyft Geth +fi + diff --git a/shyft-cli/shyftFullReset.sh b/shyft-cli/shyftFullReset.sh new file mode 100644 index 0000000000..5dc4563468 --- /dev/null +++ b/shyft-cli/shyftFullReset.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if ! psql -lqt | cut -d \| -f 1 | grep -qw shyftdb; then + echo Creating postgres db... + sh ./shyft-cli/postgres_setup/initdb.sh && + echo Successfully created postgres db! +fi + +sh ./shyft-cli/postgres_setup/drop_tables.sh && # Drop tables +sh ./shyft-cli/postgres_setup/init_tables.sh && # Init tables +sh ./shyft-cli/resetShyftGeth.sh && # Reset geth data +sh ./shyft-cli/initShyftGeth.sh # Init Shyft Geth \ No newline at end of file diff --git a/startShyftGeth.sh b/shyft-cli/startShyftGeth.sh similarity index 100% rename from startShyftGeth.sh rename to shyft-cli/startShyftGeth.sh diff --git a/simulations/checkbalances.js b/shyft-cli/web3/checkbalances.js similarity index 100% rename from simulations/checkbalances.js rename to shyft-cli/web3/checkbalances.js diff --git a/simulations/deployContract.js b/shyft-cli/web3/deployContract.js similarity index 100% rename from simulations/deployContract.js rename to shyft-cli/web3/deployContract.js diff --git a/simulations/getGreeting.js b/shyft-cli/web3/getGreeting.js similarity index 100% rename from simulations/getGreeting.js rename to shyft-cli/web3/getGreeting.js diff --git a/simulations/sendTransactions.js b/shyft-cli/web3/sendTransactions.js similarity index 100% rename from simulations/sendTransactions.js rename to shyft-cli/web3/sendTransactions.js diff --git a/simulations/token_test/README.md b/shyft-cli/web3/token_test/README.md similarity index 100% rename from simulations/token_test/README.md rename to shyft-cli/web3/token_test/README.md diff --git a/simulations/token_test/callGreeterFnsTest.js b/shyft-cli/web3/token_test/callGreeterFnsTest.js similarity index 100% rename from simulations/token_test/callGreeterFnsTest.js rename to shyft-cli/web3/token_test/callGreeterFnsTest.js diff --git a/simulations/token_test/call_greeter_fns.js b/shyft-cli/web3/token_test/call_greeter_fns.js similarity index 100% rename from simulations/token_test/call_greeter_fns.js rename to shyft-cli/web3/token_test/call_greeter_fns.js diff --git a/simulations/token_test/calltx.js b/shyft-cli/web3/token_test/calltx.js similarity index 100% rename from simulations/token_test/calltx.js rename to shyft-cli/web3/token_test/calltx.js diff --git a/simulations/token_test/deploy.js b/shyft-cli/web3/token_test/deploy.js similarity index 100% rename from simulations/token_test/deploy.js rename to shyft-cli/web3/token_test/deploy.js diff --git a/simulations/token_test/deploy_greeter_contracts.js b/shyft-cli/web3/token_test/deploy_greeter_contracts.js similarity index 100% rename from simulations/token_test/deploy_greeter_contracts.js rename to shyft-cli/web3/token_test/deploy_greeter_contracts.js diff --git a/simulations/token_test/package.json b/shyft-cli/web3/token_test/package.json similarity index 100% rename from simulations/token_test/package.json rename to shyft-cli/web3/token_test/package.json diff --git a/simulations/token_test/token.sol b/shyft-cli/web3/token_test/token.sol similarity index 100% rename from simulations/token_test/token.sol rename to shyft-cli/web3/token_test/token.sol diff --git a/shyft-geth.sh b/shyft-geth.sh new file mode 100755 index 0000000000..5104f01844 --- /dev/null +++ b/shyft-geth.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +illegalCommands=() +while [[ $# -gt 0 ]] +do +key="$1" + +case $key in + --setup) + sh ./shyft-cli/setup.sh + shift # past argument + ;; + --start) + sh ./shyft-cli/startShyftGeth.sh + shift # past argument + ;; + --js) + sh ./shyft-cli/runJs.sh ./shyft-cli/web3/$2 + shift # past argument + shift # past argument + ;; + --reset) + sh ./shyft-cli/shyftFullReset.sh + shift # past argument + ;; + *) # unknown option + illegalCommands+=("$1") # save it in an array for later + shift # past argument + ;; +esac +done + +if [[ "${#illegalCommands[@]}" -gt "0" ]] ; then + echo The following commands are not supported: "${illegalCommands[*]}" +fi + diff --git a/shyftDb/postgres_setup/initdb.sh b/shyftDb/postgres_setup/initdb.sh deleted file mode 100644 index 1fb7d829c5..0000000000 --- a/shyftDb/postgres_setup/initdb.sh +++ /dev/null @@ -1 +0,0 @@ -psql -U postgres -f create_shyftdb.psql diff --git a/shyftFullReset.sh b/shyftFullReset.sh deleted file mode 100644 index 6fbcbc1683..0000000000 --- a/shyftFullReset.sh +++ /dev/null @@ -1,5 +0,0 @@ -cd ./shyftDb/postgres_setup -sh drop_tables.sh && sh init_tables.sh -cd .. -cd .. -sh resetShyftGeth.sh && sh initShyftGeth.sh \ No newline at end of file