From 1d29e10bfcc13b94a4f35f4b620ab57bbbfd3390 Mon Sep 17 00:00:00 2001 From: piotrMocz Date: Wed, 2 Nov 2022 12:43:12 +0100 Subject: [PATCH 1/2] Introduce the no_prompts option --- README.md | 1 + run_node.sh | 83 +++++++++++++++++++++++++++++++++++++++ scripts/run_node.sh | 95 +++++++-------------------------------------- scripts/update.sh | 12 ++++-- 4 files changed, 107 insertions(+), 84 deletions(-) diff --git a/README.md b/README.md index f94b760..f9b9d62 100644 --- a/README.md +++ b/README.md @@ -47,4 +47,5 @@ The script allows you to customize the run in several ways, as listed below: * `--archivist`: (as described above) run the node as an archivist instead of a validator * `--name`: (as described above) set the name of the node. If you omit this option, one will be generated for you but it's not encouraged. * `--stash_account`: provide `AccountId` of the stash account linked to your validator node. If you run as validator, then this argument is mandatory. +* `--no_prompts`: skip all prompts and use the default choices: useful for setups involving a supervisor like systemd. diff --git a/run_node.sh b/run_node.sh index 1d025a7..88645dc 100755 --- a/run_node.sh +++ b/run_node.sh @@ -2,6 +2,89 @@ set -eo pipefail +Help() +{ + echo "Run the aleph-node as either a validator or an archivist." + echo "Syntax: ./run_node.sh [-- ] [--]" + echo + echo "options:" + echo "archivist Run the node as an archivist (the default is to run as a validator)" + echo "stash_account Stash account of your validator: optional but recommended, if you're re-running the script." + echo "n | name Set the node's name." + echo "d | data_dir Specify the directory where all the chain data will be stored (default: ~/.alephzero)." + echo "mainnet Join the mainnet (by default the script will join testnet)." + echo "i | image Specify the Docker image to use" + echo "build_only Do not run after the setup." + echo "sync_from_genesis Perform a full sync instead of downloading the backup." + echo "no_prompts Auto-select the default value in all cases instead of prompting." + echo "help Print this help." + echo + echo "Example usage:" + echo "./run_node.sh --name my-aleph-node --mainnet --stash_account 5CeeD3MGHCvZecJkvfJVzYvYkoPtw9pTVvskutXAUtZtjcYa" + echo + echo "or, shorter:" + echo "./run_node.sh --n my-aleph-node --mainnet --stash_account 5CeeD3MGHCvZecJkvfJVzYvYkoPtw9pTVvskutXAUtZtjcYa" + echo +} + + + + +# The defaults +export NAME="aleph-node-$(xxd -l "16" -p /dev/urandom | tr -d " \n" ; echo)" +export BASE_PATH="/data" +export HOST_BASE_PATH="${HOME}/.alephzero" +export DB_SNAPSHOT_FILE="db_backup.tar.gz" +export DB_SNAPSHOT_URL="https://db.test.azero.dev/latest.html" +export MAINNET_DB_SNAPSHOT_URL="https://db.azero.dev/latest.html" +export DB_SNAPSHOT_PATH="chains/testnet/" # testnet by default +export CHAINSPEC_FILE="testnet_chainspec.json" +export PROMPTS=true + +while [[ $# -gt 0 ]]; do + case "$1" in + -h | --help) # display Help + Help + exit;; + --archivist) # Run as an archivist + export ARCHIVIST=true + shift;; + -n | --name) # Enter a name + export NAME="$2" + shift 2;; + -d | --data_dir) # Choose the data directory + export HOST_BASE_PATH="$2" + shift 2;; + --mainnet) # Join the mainnet + export DB_SNAPSHOT_PATH="chains/mainnet/" + export CHAINSPEC_FILE="mainnet_chainspec.json" + export DB_SNAPSHOT_URL="${MAINNET_DB_SNAPSHOT_URL}" + shift;; + -i | --image) # Enter a base path + export ALEPH_IMAGE="$2" + export PULL_IMAGE=false + shift 2;; + --build_only) + export BUILD_ONLY=true + shift;; + --sync_from_genesis) + export SYNC=true + shift;; + --stash_account) + export STASH_ACCOUNT=$2 + shift 2;; + --no_prompts) + export PROMPTS=false + shift;; + -* | --* ) + echo "Warning: unrecognized option: $1" + exit;; + *) + echo "Unrecognized command" + Help + exit;; + esac +done ./scripts/update.sh diff --git a/scripts/run_node.sh b/scripts/run_node.sh index 54e8086..acac7bc 100755 --- a/scripts/run_node.sh +++ b/scripts/run_node.sh @@ -2,85 +2,6 @@ set -eo pipefail -Help() -{ - echo "Run the aleph-node as either a validator or an archivist." - echo "Syntax: ./run_node.sh [-- ] [--]" - echo - echo "options:" - echo "archivist Run the node as an archivist (the default is to run as a validator)" - echo "stash_account Stash account of your validator: optional but recommended, if you're re-running the script." - echo "n | name Set the node's name." - echo "d | data_dir Specify the directory where all the chain data will be stored (default: ~/.alephzero)." - echo "mainnet Join the mainnet (by default the script will join testnet)." - echo "i | image Specify the Docker image to use" - echo "build_only Do not run after the setup." - echo "sync_from_genesis Perform a full sync instead of downloading the backup." - echo "help Print this help." - echo - echo "Example usage:" - echo "./run_node.sh --name my-aleph-node --mainnet --stash_account 5CeeD3MGHCvZecJkvfJVzYvYkoPtw9pTVvskutXAUtZtjcYa" - echo - echo "or, shorter:" - echo "./run_node.sh --n my-aleph-node --mainnet --stash_account 5CeeD3MGHCvZecJkvfJVzYvYkoPtw9pTVvskutXAUtZtjcYa" - echo -} - - - - -# The defaults -NAME="aleph-node-$(xxd -l "16" -p /dev/urandom | tr -d " \n" ; echo)" -BASE_PATH="/data" -HOST_BASE_PATH="${HOME}/.alephzero" -DB_SNAPSHOT_FILE="db_backup.tar.gz" -DB_SNAPSHOT_URL="https://db.test.azero.dev/latest.html" -MAINNET_DB_SNAPSHOT_URL="https://db.azero.dev/latest.html" -DB_SNAPSHOT_PATH="chains/testnet/" # testnet by default -CHAINSPEC_FILE="testnet_chainspec.json" - - -while [[ $# -gt 0 ]]; do - case "$1" in - -h | --help) # display Help - Help - exit;; - --archivist) # Run as an archivist - ARCHIVIST=true - shift;; - -n | --name) # Enter a name - NAME="$2" - shift 2;; - -d | --data_dir) # Choose the data directory - HOST_BASE_PATH="$2" - shift 2;; - --mainnet) # Join the mainnet - DB_SNAPSHOT_PATH="chains/mainnet/" - CHAINSPEC_FILE="mainnet_chainspec.json" - DB_SNAPSHOT_URL="${MAINNET_DB_SNAPSHOT_URL}" - shift;; - -i | --image) # Enter a base path - ALEPH_IMAGE="$2" - PULL_IMAGE=false - shift 2;; - --build_only) - BUILD_ONLY=true - shift;; - --sync_from_genesis) - SYNC=true - shift;; - --stash_account) - STASH_ACCOUNT=$2 - shift 2;; - -* | --* ) - echo "Warning: unrecognized option: $1" - exit;; - *) - echo "Unrecognized command" - Help - exit;; - esac -done ALEPH_VERSION=$(cat env/version) @@ -91,9 +12,15 @@ then echo "If you wish to customize the directory, select 'n' and re-run the script" echo "with the '--data_dir' argument." echo "Do you want to continue? [Y/n]" - read -r CONT + + if [[ "$PROMPTS" = true ]] + then + read -r CONT + else + CONT='y' + fi - if [[ "$CONT" == 'n' ]] + if [[ "$CONT" -eq 'n' ]] then echo "Please re-run the script, supplying the '--data_dir' argument, exiting." exit 0 @@ -173,6 +100,12 @@ echo 'Performing session key checks...' if [[ -z "${STASH_ACCOUNT}" ]] then + if [[ "$PROMPTS" = false ]] + then + echo "Skipping the session keys check." + exit 0 + fi + echo "Stash account not provided. This is ok if you're running the script for the first time but recommended for subsequent runs." read -p "Are you sure you want to skip the session keys check? [y/N]" -r -n 1 echo "" diff --git a/scripts/update.sh b/scripts/update.sh index c1ae360..639860f 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -4,9 +4,15 @@ git remote update RES=$(git status -uno | grep behind) if [ $? -eq 0 ]; then - echo "Newer version available, would you like to update? [y/N]" - read -r UPDATE - if [[ "${UPDATE}" != 'y' ]] + echo "Newer version available, would you like to update? [Y/n]" + if [[ "$PROMPTS" = true ]] + then + read -r UPDATE + else + UPDATE='y' + fi + + if [[ "${UPDATE}" -eq 'n' ]] then echo "Skipping the update. You can still do it manually using git." exit 0 From 2d9982a24dd99351c181e571adf2468c7b50f49b Mon Sep 17 00:00:00 2001 From: piotrMocz Date: Fri, 4 Nov 2022 15:57:52 +0100 Subject: [PATCH 2/2] Review feedback --- scripts/run_node.sh | 4 ++-- scripts/update.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/run_node.sh b/scripts/run_node.sh index acac7bc..890ec17 100755 --- a/scripts/run_node.sh +++ b/scripts/run_node.sh @@ -15,12 +15,12 @@ then if [[ "$PROMPTS" = true ]] then - read -r CONT + read -r -n 1 CONT else CONT='y' fi - if [[ "$CONT" -eq 'n' ]] + if [[ "$CONT" = 'n' ]] then echo "Please re-run the script, supplying the '--data_dir' argument, exiting." exit 0 diff --git a/scripts/update.sh b/scripts/update.sh index 639860f..dd888c3 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -7,12 +7,12 @@ if [ $? -eq 0 ]; then echo "Newer version available, would you like to update? [Y/n]" if [[ "$PROMPTS" = true ]] then - read -r UPDATE + read -r -n 1 UPDATE else UPDATE='y' fi - if [[ "${UPDATE}" -eq 'n' ]] + if [[ "${UPDATE}" = 'n' ]] then echo "Skipping the update. You can still do it manually using git." exit 0