From 9277a3b1d362e3977f6a892cf1b8932939125cd1 Mon Sep 17 00:00:00 2001 From: Lukas Kozak Date: Sun, 16 Jun 2019 19:11:34 +0200 Subject: [PATCH 1/5] Change mystatus scripts Optimized the script, ready for new features to be added Signed-off-by: Lukas Kozak --- scripts/mystatus.sh | 131 ++++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 59 deletions(-) diff --git a/scripts/mystatus.sh b/scripts/mystatus.sh index 3cb300ca7..95f2592ea 100644 --- a/scripts/mystatus.sh +++ b/scripts/mystatus.sh @@ -1,75 +1,88 @@ -#!/bin/bash +#!/usr/bin/env bash -function usage -{ - cat< Date: Sun, 16 Jun 2019 19:26:54 +0200 Subject: [PATCH 2/5] Fix variable name Signed-off-by: Lukas Kozak --- scripts/mystatus.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/mystatus.sh b/scripts/mystatus.sh index 95f2592ea..63bfa756c 100644 --- a/scripts/mystatus.sh +++ b/scripts/mystatus.sh @@ -32,7 +32,6 @@ valid_ip () { } status_report () { - # Block heights heightStatus=$(tac latest/validator*.log | grep -Eom1 '"myHeight":[0-9]+' | cut -d: -f2) lengthOfChain=$(tac latest/validator*.log | grep -Eom1 '"otherHeight":[0-9]+' | cut -d: -f2) @@ -45,7 +44,7 @@ status_report () { # Check validity of IP if ! valid_ip $ip; then - echo "NO valid public IP found: $PUB_IP" + echo "NO valid public IP found: $ip" exit 2 fi From 38ee71a2a9b576ad2c7d498eba2f108efa9de1e4 Mon Sep 17 00:00:00 2001 From: Lukas Kozak Date: Sun, 16 Jun 2019 21:11:28 +0200 Subject: [PATCH 3/5] Add address check for foundational nodes Added address check against foundationals.go. --- scripts/mystatus.sh | 68 +++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/scripts/mystatus.sh b/scripts/mystatus.sh index 63bfa756c..39f77362c 100644 --- a/scripts/mystatus.sh +++ b/scripts/mystatus.sh @@ -7,10 +7,10 @@ Usage: $0 [option] command Option: -h print this help -Monitor Help: - Actions: - 1. status - Generates a status report of your node + 1. health - Generates a status report of your node + 2. address - Checks if your wallet is registered in the FN list + 3. all - Does all above EOT } @@ -31,13 +31,17 @@ valid_ip () { return $stat } -status_report () { +health_report () { # Block heights heightStatus=$(tac latest/validator*.log | grep -Eom1 '"myHeight":[0-9]+' | cut -d: -f2) + [ -z $heightStatus ] && heightStatus=Unknown + lengthOfChain=$(tac latest/validator*.log | grep -Eom1 '"otherHeight":[0-9]+' | cut -d: -f2) + [ -z $lengthOfChain ] && lengthOfChain=Unknown # Shard number my_shard=$(grep -Eom1 "shardID\"\:[0-9]+" latest/validator*.log | cut -d: -f2) + [ -z $my_shard ] && lengthOfChain=Unknown # Public IP ip=$(dig -4 @resolver1.opendns.com ANY myip.opendns.com +short) @@ -50,18 +54,33 @@ status_report () { # Number of bingos bingos=$(grep -c "BINGO" ./latest/validator*log) + [ -z bingos ] && bingos=0 #echo "Your Node Version : " + echo -e "\n====== HEALTH ======\n" LD_LIBRARY_PATH=$(pwd) ./harmony -version echo "Current Length of Chain:" $lengthOfChain echo "Your Sync Status:" $heightStatus echo "Your Shard:" $my_shard echo "Your IP:" $ip - echo "Total Blocks Received After Syncing:" $bingos - echo "Your Rewards:" + echo "Total Blocks Received After Syncing:" $bingos ./wallet.sh balances } +address_report () { + filename=$(find .hmy/keystore -maxdepth 1 -type f | head -n1) + address_field=$(grep -o '"address":"[a-z0-9]*' "${filename}") + base16=$(cut -d\" -f4 <<< "${address_field}") + bech32=$(./wallet.sh format --address 0x${base16} | head -n1 | awk -F: '{print $2}' | awk '{$1=$1}1') + curl -s https://raw.githubusercontent.com/harmony-one/harmony/master/internal/genesis/foundational.go | grep -qom1 "${bech32}" + echo -e "\n====== ADDRESS ======\n" + if [ $? -eq 0 ]; then + echo "SUCCESS: "${bech32}" FOUND in our foundational list!" + else + echo "FAILURE: "${bech32}" NOT FOUND in our foundational list, check if you have the right keyfile." + fi +} + #####Main##### while getopts "h" opt; do @@ -74,14 +93,29 @@ while getopts "h" opt; do done shift $(($OPTIND-1)) -[ $# -eq 0 -o $# -gt 1 ] && usage && exit 1 - -case "$1" in - status) - status_report - ;; - *) - usage; - exit 1 - ;; -esac \ No newline at end of file +[ $# -eq 0 -o $# -gt 2 ] && usage && exit 1 + +while :; do + case "$1" in + health) + health_report + shift + ;; + address) + address_report + shift + ;; + all) + address_report + health_report + shift + ;; + '') + exit 0 + ;; + *) + usage + exit 1 + ;; + esac +done From a0b470f181ac589dfcbdfe8c86a3fb04d73c85c0 Mon Sep 17 00:00:00 2001 From: Lukas Kozak Date: Sun, 16 Jun 2019 21:30:34 +0200 Subject: [PATCH 4/5] Fix to allow more commands to be allowed at once --- scripts/mystatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mystatus.sh b/scripts/mystatus.sh index 39f77362c..b2a4bae51 100644 --- a/scripts/mystatus.sh +++ b/scripts/mystatus.sh @@ -93,7 +93,7 @@ while getopts "h" opt; do done shift $(($OPTIND-1)) -[ $# -eq 0 -o $# -gt 2 ] && usage && exit 1 +[ $# -eq 0 ] && usage && exit 1 while :; do case "$1" in From 1106f2a16036ae2a30c48ed2f90fd0ba364568b6 Mon Sep 17 00:00:00 2001 From: Lukas Kozak Date: Tue, 18 Jun 2019 00:45:34 +0200 Subject: [PATCH 5/5] Empty commit --- scripts/mystatus.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mystatus.sh b/scripts/mystatus.sh index b2a4bae51..12ba7c3a5 100644 --- a/scripts/mystatus.sh +++ b/scripts/mystatus.sh @@ -91,7 +91,7 @@ while getopts "h" opt; do ;; esac done -shift $(($OPTIND-1)) +shift $(($OPTIND - 1)) [ $# -eq 0 ] && usage && exit 1