Last active
July 13, 2022 17:15
-
-
Save glasgowm148/23d5f1a8b6b9bcab70c5d739e863debf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Shell script for installing Ergo Node under Unix. | |
# markglasgow@gmail.com - 29 November | |
# ------------------------------------------------------------------------- | |
# | |
#kill -9 $(lsof -t -i:9053) | |
#rm -rf .ergo/wallet | |
#rm -rf .ergo/state | |
########################################################################### | |
### Download the latest .jar file | |
########################################################################### | |
if [ -e *.jar ]; then | |
echo "- Node .jar is already downloaded" | |
else | |
echo "- Retrieving latest node release.." | |
LATEST_ERGO_RELEASE=$(curl -s "https://api.github.com/repos/ergoplatform/ergo/releases/latest" | awk -F '"' '/tag_name/{print $4}') | |
LATEST_ERGO_RELEASE_NUMBERS=$(echo ${LATEST_ERGO_RELEASE} | cut -c 2-) | |
ERGO_DOWNLOAD_URL=https://github.com/ergoplatform/ergo/releases/download/${LATEST_ERGO_RELEASE}/ergo-${LATEST_ERGO_RELEASE_NUMBERS}.jar | |
echo "- Downloading Latest known Ergo release: ${LATEST_ERGO_RELEASE}." | |
curl --silent -L ${ERGO_DOWNLOAD_URL} --output ergo.jar | |
fi | |
########################################################################### | |
### Prompt the user for a password and hash it using Blake2b | |
########################################################################### | |
read -p "- Please enter a password. This will be used to unlock your API: " input | |
export RAND=$(curl --location -g --request GET 'api.hashify.net/hash/BLAKE2B-256/hex?value='$input) | |
export blake_hash=${RAND[@]:10:66} | |
echo "blake hash is $blake_hash" | |
########################################################################### | |
### Write the config file with the generated hash | |
########################################################################### | |
echo "- Writing the config file" | |
echo " | |
ergo { | |
node { | |
mining = false | |
# Skip validation of transactions in the mainnet before block 417,792 (in v1 blocks). | |
# Block 417,792 is checkpointed by the protocol (so its UTXO set as well). | |
# The node still applying transactions to UTXO set and so checks UTXO set digests for each block. | |
skipV1TransactionsValidation = true | |
} | |
} | |
scorex { | |
restApi { | |
# Hex-encoded Blake2b256 hash of an API key. | |
# Should be 64-chars long Base16 string. | |
# below is the hash of the string 'hello' | |
# replace with your actual hash | |
apiKeyHash = "$blake_hash" | |
} | |
}" > ergo.conf | |
########################################################################### | |
### Run the server, the -Xmx3G flag specifies the JVM Heap size | |
### Change this depending on system specs. | |
########################################################################### | |
echo "- Running the server" | |
java -jar -Xmx3G ergo.jar --mainnet -c ergo.conf > server.log 2>&1 & | |
while ! curl --output /dev/null --silent --head --fail http://localhost:9053; do sleep 1 && echo -n '.'; done; # wait for node be ready with progress bar | |
echo "" | |
echo "- Node started." | |
########################################################################### | |
### This should open the browser (providing python is installed) | |
### At this stage you can check if your API key works as prompted. | |
########################################################################### | |
echo "Enter '$input' on 127.0.0.1:9053/panel under 'Set API key'" | |
sleep 2 | |
echo "" | |
echo "Please follow the next steps on docs.ergoplatform.org to initialise your wallet" | |
sleep 5 | |
python -mwebbrowser http://127.0.0.1:9053/panel | |
########################################################################### | |
### This method pulls the latest height and header height from /info | |
########################################################################### | |
get_heights(){ | |
HEIGHT=$(\ | |
curl --silent --output -X GET "http://localhost:9053/info" -H "accept: application/json" \ | |
| python -c "import sys, json; print json.load(sys.stdin)['parameters']['height']"\ | |
) | |
HEADERS_HEIGHT=$(\ | |
curl --silent --output -X GET "http://localhost:9053/info" -H "accept: application/json" \ | |
| python -c "import sys, json; print json.load(sys.stdin)['headersHeight']"\ | |
) | |
} | |
########################################################################### | |
### Get initial heights, then loop and show remaining blocks to user | |
########################################################################### | |
get_heights | |
while : | |
do | |
if [ $HEIGHT == 0 ]; | |
then | |
echo "- Go to http://127.0.0.1:9053/info (cmd+click) to view information about your node." | |
echo "- Sleeping for 10 minutes while the initial block headers are downloaded.." | |
sleep 600 | |
get_heights | |
echo "Header Height is currently at $HEADERS_HEIGHT" | |
elif (( $HEADERS_HEIGHT > $HEIGHT)); then | |
get_heights | |
echo "header_height is $HEADERS_HEIGHT and height is $HEIGHT" | |
REMAINDER=$(($HEADERS_HEIGHT - $HEIGHT)) | |
echo "$REMAINDER blocks remaining (refreshes once a minute" | |
sleep 60 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment