From 3bc79952bd61deebc30b9049fdc6815f4b143683 Mon Sep 17 00:00:00 2001 From: fryorcraken Date: Thu, 3 Oct 2024 16:42:24 +1000 Subject: [PATCH] feat: wizard script A wizard script to make new users' life easier. --- README.md | 10 ++++ set_storage_retention.sh | 20 ++++---- wizard.sh | 99 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 8 deletions(-) create mode 100755 wizard.sh diff --git a/README.md b/README.md index ff83186..6d22c17 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,16 @@ ${EDITOR} .env Make sure to **NOT** place any secrets into `.env.example`, as they might be unintentionally published in the Git repository. +### EXPERIMENTAL - Use wizard script + +Run the wizard script. +Once the script is done, the node will be started for you, so there is nothing else to do. + +The script is experimental, feedback and pull requests are welcome. + +``` +./wizard.sh +``` ### 🔑 1. Register RLN membership diff --git a/set_storage_retention.sh b/set_storage_retention.sh index bf9767c..0932386 100755 --- a/set_storage_retention.sh +++ b/set_storage_retention.sh @@ -11,7 +11,7 @@ select_store_size() _MAX_SIZE_MB=$5 unset SELECTED_STORAGE_SIZE_MB if [ -z "$_AVAIL_SPACE_MB" ] || [ -z "$_PGSQL_SIZE_MB" ] || [ -z "$_LEEWAY_MB" ] || [ -z "$_MIN_SIZE_MB" ] || [ -z "$_MAX_SIZE_MB" ]; then - echo "Internal error, not enough arguments passed to select_store_size" + >&2 echo "Internal error, not enough arguments passed to select_store_size" fi _USABLE_SPACE_MB=$(( _AVAIL_SPACE_MB + _PGSQL_SIZE_MB )) @@ -20,13 +20,13 @@ select_store_size() _TARGET_MB=$(( _USABLE_SPACE_MB - _LEEWAY_MB)) if [ $_TARGET_MB -lt $_MIN_SIZE_MB ]; then - echo "Flooring storage retention to ${_MIN_SIZE_MB}MB" + >&2 echo "Flooring storage retention to ${_MIN_SIZE_MB}MB" SELECTED_STORAGE_SIZE_MB=$_MIN_SIZE_MB elif [ $_TARGET_MB -gt $_MAX_SIZE_MB ]; then - echo "Capping storage retention to ${_MAX_SIZE_MB}MB" + >&2 echo "Capping storage retention to ${_MAX_SIZE_MB}MB" SELECTED_STORAGE_SIZE_MB=$_MAX_SIZE_MB else - echo "Storage retention set to ${_TARGET_MB}" + >&2 echo "Storage retention set to ${_TARGET_MB}" SELECTED_STORAGE_SIZE_MB=$_TARGET_MB fi } @@ -47,7 +47,7 @@ fi # Check we are in right folder if ! [ -f "./run_node.sh" ]; then - echo "This script must be run from inside the 'nwaku-compose' folder" + >&2 echo "This script must be run from inside the 'nwaku-compose' folder" exit 1 fi @@ -55,7 +55,7 @@ fi if [ -f "./.env" ]; then . ./.env if [ -n "$STORAGE_SIZE" ]; then - echo "STORAGE_SIZE is specified in .env file, doing nothing" + >&2 echo "STORAGE_SIZE is specified in .env file, doing nothing" exit 0 fi fi @@ -76,8 +76,12 @@ AVAIL_SPACE_MB=$(df -BM . | tail -1 | awk '{ print $4 }' | sed 's/^\([0-9]\+\)M$ select_store_size $AVAIL_SPACE_MB $PGSQL_SIZE_MB 1024 1024 $(( 30 * 1024 )) if [ -z "$SELECTED_STORAGE_SIZE_MB" ]; then - echo "Failed to selected a storage size" + >&2 echo "Failed to selected a storage size" exit 1 fi -echo "export STORAGE_SIZE=${SELECTED_STORAGE_SIZE_MB}MB" >> .env +if [ "$1" = "echo-value" ]; then + echo ${SELECTED_STORAGE_SIZE_MB}MB +else + echo "STORAGE_SIZE=${SELECTED_STORAGE_SIZE_MB}MB" >> .env +fi diff --git a/wizard.sh b/wizard.sh new file mode 100755 index 0000000..495b291 --- /dev/null +++ b/wizard.sh @@ -0,0 +1,99 @@ +#!/bin/sh + +if [ -f ./.env ] \ + || [ -f keystore/keystore.json ] ; then + echo "Artefacts already existing, exiting wizard" + exit 1 +fi + +if [ -z "$(which docker 2>/dev/null)" ]; then + echo "Ensure that 'docker' is installed and PATH" + exit 1 +fi + +if [ -z "$(which docker-compose 2>/dev/null)" ]; then + echo "Ensure that 'docker-compose' is installed and PATH" + exit 1 +fi + +echocol() +{ + COL='\033[0;32m' + NC='\033[0m' + printf "$COL${1}${NC}\n" +} + +echocol "##############################" +echocol "#### nwaku-compose wizard ####" +echocol "##############################" +echocol "First, you need a RPC HTTP endpoint for Ethereum Sepolia" +echocol "If you don't have one, try out https://www.infura.io/" +echocol "Expected format is https://sepolia.infura.io/v3/:" +read -r RLN_RELAY_ETH_CLIENT_ADDRESS + +if [ -z "$RLN_RELAY_ETH_CLIENT_ADDRESS" ] \ + || [ $(echo "$RLN_RELAY_ETH_CLIENT_ADDRESS" | grep -c "^https:") -eq 0 ]; then + echo "Invalid value, received '$RLN_RELAY_ETH_CLIENT_ADDRESS'" + exit 1 +fi + +echocol "...." +echocol "Double check you have some Eth Sepolia, at least 0.01Eth." +echocol "If not, you can use this faucet: https://www.infura.io/faucet/sepolia" +echocol "Now enter your SEPOLIA TESTNET private key in hex format 0a...1f without 0x prefix" +read ETH_TESTNET_KEY + +if [ -z "$ETH_TESTNET_KEY" ] \ + || [ $(echo -n "$ETH_TESTNET_KEY" | grep -c '^[0-9a-fA-F]\{64\}$' ) -ne 1 ]; then + echo "Invalid value, received '$ETH_TESTNET_KEY'" + exit 1 +fi + +echocol "...." +echocol "Generating a password for the RLN membership keystore file..." +RLN_RELAY_CRED_PASSWORD=$(< /dev/urandom tr -dc ',/.;:<>?!@#$%^&*()+\-_A-Z-a-z-0-9' | head -c${1:-16};echo;) + +echocol "...." +echocol "Selecting a size for DB..." +STORAGE_SIZE=$(./set_storage_retention.sh echo-value) + +if [ -z "$STORAGE_SIZE" ]; then + echo "Error encountered when estimating storage size, exiting" + exit 1 +fi + +echocol "...." +echocol "The following parameters will be saved to your .env file. Press ENTER to confirm or quit with CONTROL-C to abort:" +echo "RLN_RELAY_ETH_CLIENT_ADDRESS='$RLN_RELAY_ETH_CLIENT_ADDRESS' +ETH_TESTNET_KEY=$ETH_TESTNET_KEY +RLN_RELAY_CRED_PASSWORD='$RLN_RELAY_CRED_PASSWORD' +STORAGE_SIZE=$STORAGE_SIZE" +read foo + +echo "RLN_RELAY_ETH_CLIENT_ADDRESS='$RLN_RELAY_ETH_CLIENT_ADDRESS' +ETH_TESTNET_KEY=$ETH_TESTNET_KEY +RLN_RELAY_CRED_PASSWORD='$RLN_RELAY_CRED_PASSWORD' +STORAGE_SIZE=$STORAGE_SIZE" > ./.env + +SUDO="" +if ! docker info > /dev/null 2>&1; then + echocol "...." + echocol "'sudo' seems to be needed to run docker, your unix password will be asked" + SUDO="sudo" +fi + + +echocol "...." +echocol "Registering an RLN membership..." +if ! $SUDO ./register_rln.sh; then + echocol "###" + echocol "Failed to register RLN membership, usually due to high gas fee" + echocol "Double check you have enough Sepolia eth and run the following command:" + echocol "$SUDO ./register_rln.sh" + echocol "###" + exit 1 +fi + +echocol "...." +echocol "Starting your nwaku node... your password may be needed for sudo" +$SUDO docker-compose up -d \ No newline at end of file