From fa4b25a2e9070ff6f6584be5cf706e7464c93844 Mon Sep 17 00:00:00 2001
From: Robert Martin-Legene <robert@nic.ar>
Date: Wed, 26 Sep 2018 17:39:14 -0300
Subject: [PATCH] grep -v does not return a reliable return code?

---
 bin/installbfa.sh |   2 +-
 bin/libbfa.sh     | 106 +++++++++++++++++++++-------------------------
 2 files changed, 49 insertions(+), 59 deletions(-)

diff --git a/bin/installbfa.sh b/bin/installbfa.sh
index 906aa40..31dac3b 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 e775551..cb2743c 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
-- 
GitLab