diff --git a/scripts/init.sh b/scripts/init.sh index 949bd35..d34ab8e 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -20,26 +20,6 @@ PWD="$(pwd)" CONSTELLATION_NODES=$(cat ../data/constellation-nodes.json) STATIC_NODES=$(cat ../data/static-nodes.json) -update_constellation_nodes() { - NODE_IP="$1" - CONSTELLATION_PORT="$2" - URL=", - \"http://$NODE_IP:$CONSTELLATION_PORT/\" -]" - CONSTELLATION_NODES=${CONSTELLATION_NODES::-2} - CONSTELLATION_NODES="$CONSTELLATION_NODES$URL" - echo "$CONSTELLATION_NODES" > ~/alastria-node/data/constellation-nodes.json -} - -update_static_nodes() { - ENODE=", - \"$1\" -]" - STATIC_NODES=${STATIC_NODES::-2} - STATIC_NODES="$STATIC_NODES$ENODE" - echo "$STATIC_NODES" > ~/alastria-node/data/static-nodes.json -} - generate_conf() { #define parameters which are passed in. NODE_IP="$1" @@ -87,7 +67,7 @@ verbosity = 2 EOF } -echo "[*] Cleaning up temporary data directories" +echo "[*] Cleaning up temporary data directories." rm -rf ~/alastria mkdir -p ~/alastria/data/{keystore,geth,constellation} mkdir -p ~/alastria/data/constellation/{data,keystore} @@ -101,21 +81,28 @@ geth --datadir ~/alastria/data init ~/alastria-node/data/genesis.json cd ~/alastria/data/geth bootnode -genkey nodekey ENODE_KEY=$(bootnode -nodekey nodekey -writeaddress) -echo "ENODE -> ${ENODE_KEY}" +echo "ENODE -> 'enode://${ENODE_KEY}@${CURRENT_HOST_IP}:21000?raftport=41000'" cd ~ -update_static_nodes "enode://${ENODE_KEY}@${CURRENT_HOST_IP}:21000?raftport=41000" -cp ~/alastria-node/data/static-nodes.json ~/alastria/data/static-nodes.json +if [[ "$CURRENT_HOST_IP" == "52.56.69.220" ]]; then + cp ~/alastria-node/data/static-nodes.json ~/alastria/data/static-nodes.json + cp ~/alastria-node/data/static-nodes.json ~/alastria/data/permissioned-nodes.json +fi echo " Por favor, introduzca como contraseƱa 'Passw0rd'." geth --datadir ~/alastria/data account new -echo "[*] Initializing Constellation node" -update_constellation_nodes "${CURRENT_HOST_IP}" "9000" +echo "[*] Initializing Constellation node." generate_conf "${CURRENT_HOST_IP}" "9000" "$CONSTELLATION_NODES" "${PWD}" > ~/alastria/data/constellation/constellation.conf cd ~/alastria/data/constellation/keystore cat ~/alastria/data/passwords.txt | constellation-node --generatekeys=node echo "______" cd ~ +echo "[*] Initialization was completed successfully." +echo " " +echo " Update DIRECTORY.md from alastria-node repository and send a Pull Request." +echo " The network administrator will send a RAFT_ID file. It will be stored in '~/alastria/data/' directory." +echo " " + set +u set +e diff --git a/scripts/start.sh b/scripts/start.sh index da336a1..4fe470d 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -2,7 +2,20 @@ set -u set -e -NETID=963252369 +CURRENT_HOST_IP="$(dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null || curl -s --retry 2 icanhazip.com)" + +if [[ ! -f ~/alastria/data/RAFT_ID && "$CURRENT_HOST_IP" != "52.56.69.220" ]]; then + echo "[*] The node don't have ~/alastria/data/RAFT_ID file, please:" + echo " " + echo " Update DIRECTORY.md from alastria-node repository and send a Pull Request." + echo " The network administrator will send a RAFT_ID file. It will be stored in '~/alastria/data/' directory." + echo " " + exit +fi +echo "DONE" +exit + +NETID=963262369 GLOBAL_ARGS="--networkid $NETID --raft --rpc --rpcaddr 0.0.0.0 --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum,raft" _TIME=$(date +%Y%m%d%H%M%S) @@ -13,10 +26,13 @@ sleep 6 echo "[*] Starting quorum node" PRIVATE_CONFIG=~/alastria/data/constellation/constellation.conf -if ( [ $# -ne 1 ] ); then - nohup geth --datadir ~/alastria/data $GLOBAL_ARGS --rpcport 22000 --port 21000 --raftport 41000 --password ~/alastria/data/passwords.txt 2>> ~/alastria/logs/quorum_"${_TIME}".log & +if [ -f ~/alastria/data/RAFT_ID ]; then + mapfile -t RAFT_ID <~/alastria/data/RAFT_ID + nohup geth --datadir ~/alastria/data $GLOBAL_ARGS --permissioned --rpcport 22000 --port 21000 --raftport 41000 --raftjoinexisting $RAFT_ID 2>> ~/alastria/logs/quorum_"${_TIME}".log & else - nohup geth --datadir ~/alastria/data $GLOBAL_ARGS --rpcport 22000 --port 21000 --raftport 41000 --unlock 0 --password ~/alastria/data/passwords.txt 2>> ~/alastria/logs/quorum_"${_TIME}".log & + if [[ "$CURRENT_HOST_IP" == "52.56.69.220" ]]; then + nohup geth --datadir ~/alastria/data $GLOBAL_ARGS --permissioned --rpcport 22000 --port 21000 --raftport 41000 --unlock 0 --password ~/alastria/data/passwords.txt 2>> ~/alastria/logs/quorum_"${_TIME}".log & + fi fi set +u