diff --git a/bin/installbfa.sh b/bin/installbfa.sh index 906aa401693add2762cb732c161cd2743e3db5a3..31dac3b5c2429024342237dce8a2106a09bc7ed6 100755 --- a/bin/installbfa.sh +++ b/bin/installbfa.sh @@ -165,7 +165,7 @@ function usersetup function cronit { - if crontab -u bfa -l 2>/dev/null | expand | grep -qvE '^@reboot +bfa/bin/cron.sh$' + if [ $( crontab -u bfa -l 2>/dev/null | expand | grep -E 'bfa/bin/cron.sh$' | wc -l ) -eq 0 ] then info Install crontab to start automatically upon reboot ( crontab -u bfa -l ; echo '@reboot bfa/bin/cron.sh' ) | crontab -u bfa - diff --git a/bin/libbfa.sh b/bin/libbfa.sh index e7755513f0545353aeae76ec4ea1a9f749865071..cb2743ce6d3d036fef819734add1634e8fc3b2f8 100644 --- a/bin/libbfa.sh +++ b/bin/libbfa.sh @@ -16,11 +16,6 @@ test -n "$BASH_VERSION" || test "$( caller 2>/dev/null | awk '{print $1}' )" != "0" || fatal "This file must be source(d), not executed." -function stderr -{ - echo "$@" >&2 -} - function cleanup { if [ $# -gt 0 ] @@ -148,58 +143,53 @@ function contractSendTx ############### # bfainit # - test -n "${BFAHOME}" -a \ - -d "${BFAHOME}" || - fatal "\$BFAHOME in your environment must point to a directory." - # - # BFANETWORKID - test -n "${BFANETWORKID}" || BFANETWORKID=47525974938 - # - # BFANETWORKDIR - test -n "${BFANETWORKDIR}" || BFANETWORKDIR="${BFAHOME}/network" - mkdir -p "${BFANETWORKDIR}" - test -d "${BFANETWORKDIR}" || fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\") not found." - # - # BFANODEDIR - test -n "$BFANODEDIR" || BFANODEDIR="${BFANETWORKDIR}/node" - if [ ! -d "${BFANODEDIR}" ] - then - echo "Node directory not found. Initialising a new node." - geth --datadir ${BFANODEDIR} init ${BFAHOME}/src/genesis.json - fi - if [ ! -d "${BFANODEDIR}/geth/chaindata" ] - then - echo "Node is not initialised. Initialising with BFA genesis." - geth --datadir "${BFANODEDIR}" init "${BFAHOME}/src/genesis.json" - fi - # - # netport - netport=30303 - if [ -r "${BFANODEDIR}/netport" ] - then - netport=$( cat ${BFANODEDIR}/netport ) - test $? = 0 - fi - # - # rpcport - rpcport=8545 - if [ -r "${BFANODEDIR}/rpcport" ] +test -n "${BFAHOME}" -a \ + -d "${BFAHOME}" || + fatal "\$BFAHOME in your environment must point to a directory." +# +# BFANETWORKID +test -n "${BFANETWORKID}" || BFANETWORKID=47525974938 +# +# BFANETWORKDIR +test -n "${BFANETWORKDIR}" || BFANETWORKDIR="${BFAHOME}/network" +mkdir -p "${BFANETWORKDIR}" +test -d "${BFANETWORKDIR}" || fatal "\$BFANETWORKDIR (\"${BFANETWORKDIR}\") not found." +# +# BFANODEDIR +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" +fi +# +# netport +netport=30303 +if [ -r "${BFANODEDIR}/netport" ] +then + netport=$( cat ${BFANODEDIR}/netport ) + test $? = 0 +fi +# +# rpcport +rpcport=8545 +if [ -r "${BFANODEDIR}/rpcport" ] +then + rpcport=$( cat ${BFANODEDIR}/rpcport ) + test $? = 0 +fi +# +# BFAACCOUNT +if [ -z "$BFAACCOUNT" ] +then + if [ ! -d "${BFANODEDIR}/keystore" ] then - rpcport=$( cat ${BFANODEDIR}/rpcport ) - test $? = 0 - fi - # - # BFAACCOUNT - if [ -z "$BFAACCOUNT" ] - then - if [ ! -d "${BFANODEDIR}/keystore" ] - then - echo "No accounts found. Creating a new one (they are free)." - geth --cache 0 --datadir ${BFANODEDIR} --password /dev/null account new - fi - BFAACCOUNT=$( - ls -1dl "${BFANODEDIR}"/keystore/*--* 2>/dev/null | - head -1 | - sed 's/.*--//' - ) + echo "No accounts found. Creating a new one (they are free)." + geth --cache 0 --datadir ${BFANODEDIR} --password /dev/null account new fi + BFAACCOUNT=$( + ls -1d "${BFANODEDIR}"/keystore/*--* 2>/dev/null | + head -1 | + sed 's/.*--//' + ) +fi