diff --git a/.gitignore b/.gitignore index 2940230356173fcd64e606b5ee7bad556b4fa010..9370cfd457bf2963b7f43c1e1c0e470ae6ed98a5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,11 @@ */status cache */*cache -network*/node -network*/bootnode -network*/contracts/* +network/node +network/bootnode +network/contracts/* network/*.pid +test2network*/node +test2network*/bootnode +test2network*/contracts/* +test2network/*.pid diff --git a/bin/installbfa.sh b/bin/installbfa.sh index 1ff8ec3ed1388d9e870890d6c89adfa22799847b..cc1a2e2dd9d07136c61c3e77a13534dafbd8548e 100755 --- a/bin/installbfa.sh +++ b/bin/installbfa.sh @@ -49,16 +49,15 @@ function nodejsinstall function web3install { - ( - cd ~bfa - test -r package.json || - info Initialising nodejs. && - sudo --set-home -u bfa npm init -y - ) + test -r ~bfa/package.json || + info Initialising nodejs. && + sudo --set-home -u bfa npm init -y # nodejs package(s) that we need. echo 'require("web3")' | sudo --set-home -u bfa nodejs 2>/dev/null && return info Installing nodejs module: web3 "(will show many warnings)" sudo --set-home -u bfa npm install web3 + info Installing nodejs module: require + sudo --set-home -u bfa npm install require } function golanginstall @@ -146,36 +145,43 @@ function usersetup info Adding required user \"bfa\" adduser --disabled-password --gecos 'Blockchain Federal Argentina' bfa fi + cd ~bfa # If we're running inside a docker, this may already exist but # probably owned by root. Let's make sure things are proper. - chown -R bfa:bfa ~bfa - # cloning if not done already - if [ ! -d ~bfa/bfa ] + chown -R bfa:bfa . + # +} + +function userconfig +{ + if [ ! -e "${BFAHOME}/bin/env" ] + then + cp -p ${BFAHOME}/$envfile ${BFAHOME}/bin/env + fi + if [ $( expand < .bashrc | grep -E "source ${BFAHOME}/bin/env" | wc -l ) -eq 0 ] + then + info "Adding to automatically source ${BFAHOME}/bin/env via .bashrc" + echo "source ${BFAHOME}/bin/env" >> .bashrc + fi + # cloning if not done already, or just update (pull) + if [ ! -d "$BFAHOME" ] then # initial cloning - cd ~bfa - git clone https://gitlab.bfa.ar/blockchain/nucleo.git bfa + git clone https://gitlab.bfa.ar/blockchain/nucleo.git $BFAHOME + cd "$BFAHOME" else - # updating - cd ~bfa/bfa + cd "$BFAHOME" git pull fi - # - cd ~bfa - if [ $( expand < .bashrc | grep -E 'source .*bfa/bin/env' | wc -l ) -eq 0 ] - then - info Adding to automatically source \~bfa/bfa/bin/env via .bashrc - echo 'source ~/bfa/bin/env' >> .bashrc - fi - mkdir -p ~bfa/bfa/network + PATH=${PATH}:${BFAHOME}/bin } function cronit { - if [ $( ( crontab -u bfa -l 2>/dev/null || true ) | grep -E 'bfa/bin/cron.sh$' | wc -l ) -eq 0 ] + if [ $( ( crontab -u bfa -l 2>/dev/null || true ) | grep -E "$BFAHOME/bin/cron.sh" | wc -l ) -eq 0 ] then info Install crontab to start automatically upon reboot - (( crontab -u bfa -l 2>/dev/null || true ) ; echo '@reboot bfa/bin/cron.sh' ) | crontab -u bfa - + (( crontab -u bfa -l 2>/dev/null || true ) ; echo "@reboot $BFAHOME/bin/cron.sh" ) | crontab -u bfa - fi } @@ -184,7 +190,45 @@ function welcome info "(re)log in as user bfa" } +function setupquestions +{ + read -p "Donde quiere instalar (sera BFAHOME) [$( echo ~bfa/bfa )]? : " -t 60 BFAHOME + if [ "$BFAHOME" = "" ] + then + BFAHOME=$( echo ~bfa/bfa ) + fi + unset envfile + if [ ! -e "${BFAHOME}/bin/env" ] + then + REPLY= + while [ "$REPLY" != "1" -a "$REPLY" != "2" ] + do + echo "Quiere conectarse a la red BFA de produccion o prueba?" + echo "1. Produccion" + echo "2. Prueba (test2)" + read -p "Red: " -t 60 -n 1 + done + # Default to production + if [ "$REPLY" = "" ] + then + REPLY=1 + fi + case "$REPLY" in + 1) + envfile=network/env + ;; + 2) + envfile=test2network/env + ;; + *) + false + ;; + esac + fi +} +usersetup +setupquestions # Ubuntu necesita mas repos grep -q Ubuntu /etc/issue && apt-add-repository multiverse # @@ -192,7 +236,7 @@ apt update # development tools aptinstall dirmngr apt-transport-https curl git curl build-essential sudo aptinstall jq libjson-perl libwww-perl libclass-accessor-perl -usersetup +userconfig nodejsinstall web3install golanginstall diff --git a/bin/libbfa.sh b/bin/libbfa.sh index 1c216d57b2957442599426106a0c1b8f16ab535b..25de380968a63f1530832dc8ca3a2db51e5753f7 100644 --- a/bin/libbfa.sh +++ b/bin/libbfa.sh @@ -193,8 +193,8 @@ test -d "${BFANETWORKDIR}" || fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\" test -n "$BFANODEDIR" || BFANODEDIR="${BFANETWORKDIR}/node" if [ ! -d "${BFANODEDIR}" -o ! -d "${BFANODEDIR}/geth/chaindata" ] then - echo "Node is not initialised. Initialising with BFA genesis." - geth --cache 0 --datadir "${BFANODEDIR}" init "${BFAHOME}/src/genesis.json" + echo "Node is not initialised. Initialising with genesis." + geth --cache 0 --datadir "${BFANODEDIR}" init "${BFANETWORK}/genesis.json" fi # # netport diff --git a/src/genesis.json b/network/genesis.json similarity index 100% rename from src/genesis.json rename to network/genesis.json diff --git a/bin/env b/network/prod-env similarity index 100% rename from bin/env rename to network/prod-env diff --git a/test2network/aliases b/test2network/aliases new file mode 100644 index 0000000000000000000000000000000000000000..21b48625256d54e0123bda34e4e518af19f1ff0c --- /dev/null +++ b/test2network/aliases @@ -0,0 +1 @@ +0xbee0966bdc4568726ab3d3131b02e6255e29285d nic1 diff --git a/test2network/env b/test2network/env new file mode 100644 index 0000000000000000000000000000000000000000..e1d7ca13b02e4b516148b68523082cb145e18fdf --- /dev/null +++ b/test2network/env @@ -0,0 +1,4 @@ +export BFAHOME=${HOME}/bfa +export BFANETWORKID=55555000000 +export BFANETWORKDIR="${BFAHOME}/test2network" +PATH=${PATH}:${BFAHOME}/bin:${HOME}/bin diff --git a/test2network/genesis.json b/test2network/genesis.json new file mode 100644 index 0000000000000000000000000000000000000000..952ea60fbac5fc84c184d1cd21f9516e0a189ac4 --- /dev/null +++ b/test2network/genesis.json @@ -0,0 +1,18 @@ +{ + "config": { + "chainId": 99118822, + "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 4, + "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "clique": { "period": 5, "epoch": 30000 } + }, + "nonce": "0x0000000000000000", + "timestamp": "0x5ce54321", + "extraData": "0x6266612e6172207465737432206e657400000000000000000000000000000000bee0966bdc4568726ab3d3131b02e6255e29285d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gasLimit": "0xffeeddcc", "difficulty": "0x1", "number": "0x0", "gasUsed": "0x0", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "alloc": { + "bee0966bdc4568726ab3d3131b02e6255e29285d": { "balance": "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" } + } +}