diff --git a/scripts/starter.sh b/scripts/starter.sh index 477e4cf..507342d 100755 --- a/scripts/starter.sh +++ b/scripts/starter.sh @@ -39,7 +39,29 @@ prompt() { done } -trap 'final "$?"' EXIT +sanity_check() { + secret_seed=$(ghost key inspect --scheme="$1" "$2" | grep "Secret seed" | awk '{ print $3 }') + account_id=$(ghost key inspect --scheme="$1" "$2" | grep "Account ID" | awk '{ print $3 }') + + echo "[+] inspected account id for $3: $account_id" + num_keys=$(grep $account_id "$PROJECT_FOLDER/service/ghosties" | wc -l) + num_types=$(grep $account_id "$PROJECT_FOLDER/service/ghosties" | grep $3 | wc -l) + if [ ! $num_keys = 1 ] || [ ! $num_types = 1 ]; then + echo "[-] inspected account id not found on 'ghosties' file or wrong key type" + exit 1 + fi +} + +extract_seed() { + name_with_spaces=$(echo $1 | tr '-' ' ') + read -p "[?] path to the file with $name_with_spaces: (default: /etc/ghost/$1) " seed_path + seed_path="${seed_path:-/etc/ghost/$1}" + if [ ! -f $seed_path ]; then + echo "[-] path to $name_with_spaces is not valid" + fi + seed=$(cat $seed_path) + echo $seed +} help() { echo -e "Ghost Node Build automation tool. Helper for Ghost Node environment preparation.\n" @@ -59,6 +81,8 @@ help() { echo -e "-h, --help\n\tPrints help information." } +trap 'final "$?"' EXIT + clear echo " ____ _ _ _ _ _" echo " / ___| |__ ___ ___| |_ | \ | | ___ __| | ___" @@ -325,15 +349,17 @@ if [[ $ARGUMENTS = true ]]; then fi if [ $CHECK_KEYS = true ]; then - read -p "[?] path to the file with session key: (default: /etc/ghost/session-key) " seed_path - seed_path="${seed_path:-/etc/ghost/session-key}" - if [ ! -f $seed_path ]; then - echo "[-] path to session keys not valid" - exit 1 - fi - echo "[+] path $seed_path is valid" - seed=$(cat $seed_path) + seed=$(extract_seed "wallet-key") + sanity_check "sr25519" $seed "wallet" + echo "[+] local wallet key found in 'ghosties' with correct key type" + echo + seed=$(extract_seed "stash-key") + sanity_check "sr25519" $seed "stash" + echo "[+] local stash key from found in 'ghosties' with correct key type" + echo + + seed=$(extract_seed "session-key") if [ $INSERT_KEYS = true ]; then read -p "[?] JSON RPC endpoint to the node: (default: localhost:9945) " rpc_endpoint rpc_endpoint="${rpc_endpoint:-localhost:9945}" @@ -346,17 +372,7 @@ if [ $CHECK_KEYS = true ]; then scheme="ed25519" fi - secret_seed=$(ghost key inspect --scheme="$scheme" "$seed//$type" | grep "Secret seed" | awk '{ print $3 }') - account_id=$(ghost key inspect --scheme="$scheme" "$seed//$type" | grep "Account ID" | awk '{ print $3 }') - - echo "[+] inspected account id: $account_id" - num_keys=$(grep $account_id "$PROJECT_FOLDER/service/ghosties" | wc -l) - num_types=$(grep $account_id "$PROJECT_FOLDER/service/ghosties" | grep $type | wc -l) - if [ ! $num_keys = 1 ] || [ ! $num_types = 1 ]; then - echo "[-] inspected account id not found on 'ghosties' file or wrong key type" - exit 1 - fi - + sanity_check $scheme "$seed//$type" $type echo "[+] inspected account id found in 'ghosties' file with correct key type" if [ $INSERT_KEYS = true ]; then