diff --git a/bin/admin.sh b/bin/admin.sh index 5f443e96a3db88b841cdf5e25bf9ed94852dca81..a3c282349daea4c25b2f7276c9e2b61e24cfbe45 100755 --- a/bin/admin.sh +++ b/bin/admin.sh @@ -4,7 +4,7 @@ if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi source ${BFAHOME}/bin/libbfa.sh || exit 1 -defaultmode="fast" +defaultsyncmode="fast" function modefilter { @@ -20,6 +20,8 @@ function modefilter true } +function admin_syncmode +{ echo "Available synchronization modes:" echo " full : verify all blocks and all transactions since genesis (most secure)" echo " fast : verify all blocks but not all transactions (faster than full, but less certain)" @@ -32,7 +34,7 @@ echo "between speed and paranoia. You can change the setting, according to" echo "your needs." mode=$( cat ${BFANODEDIR}/syncmode 2>/dev/null || true ) -mode=${mode:-${defaultmode}} +mode=${mode:-${defaultsyncmode}} orgmode=$mode modefilter echo "Your current mode is set to ${mode}" @@ -53,12 +55,7 @@ then echo "fast mode, and revalidate everything in the entire blockchain." echo "This probably takes quite a long time and also requires downloading" echo "all blocks from the entire blockchain again." - REPLY= - while [ "$REPLY" != "y" -a "$REPLY" != "n" ] - do - read -p "Do you wish to delete all downloaded blocks and resynchronize? [yn]: " - REPLY=${REPLY,,} - done + yesno n "Do you wish to delete all downloaded blocks and resynchronize?" if [ "$REPLY" = "y" ] then if [ -r "${BFANODEDIR}/geth.pid" ] @@ -79,3 +76,52 @@ then echo "The startup.sh should restart your geth shortly." fi fi +} + +function admin_bootnode +{ + keyfile=${BFANETWORKDIR}/bootnode/key + echo "Only very few wants to actually run a boot node." + echo "If you have a keyfile for a bootnode, then you will" + echo "automatically start one, when restarting your system." + if [ -f $keyfile ] + then + echo "You are set up to run a boot node." + echo "Deleting your bootnode keyfile disables your bootnode." + yesno n "Do you want to delete your bootnode keyfile?" + if [ "$REPLY" = "y" ] + then + rm $keyfile + fi + pidfile=${BFANETWORKDIR}/bootnode/pid + if [ -r $pidfile ] + then + pid=`cat $pidfile` + kill -0 $pid && + echo "Terminating your bootnode." && + kill `cat $pidfile` || + true + fi + else + echo "You are not set up to run a boot node." + yesno n "Do you want to create a keyfile for a bootnode?" + if [ "$REPLY" = "y" ] + then + bootnode -genkey $keyfile + fi + echo "You can now start your bootnode by running start.sh" + fi +} + +case "$1" in + bootnode) + admin_bootnode + ;; + syncmode) + admin_syncmode + ;; + *) + echo Usage: `basename $0` "{bootnode|syncmode}" + trap '' ERR + exit 1 +esac diff --git a/bin/installbfa.sh b/bin/installbfa.sh index b58ef657389ee153cda5c52763dfba44285147cb..bc467f09b2db07acd0faf62fd8b4055add5ebeab 100755 --- a/bin/installbfa.sh +++ b/bin/installbfa.sh @@ -57,7 +57,7 @@ function web3install ) # nodejs package(s) that we need. echo 'require("web3")' | sudo --set-home -u bfa nodejs 2>/dev/null && return - info Installing nodejs module: web3 + info Installing nodejs module: web3 "(will show many warnings)" sudo --set-home -u bfa npm install web3 } diff --git a/bin/libbfa.sh b/bin/libbfa.sh index ec80500c0a2c36d28aeb79b5dede318854bfd38a..7a635eb8864762bc6b1ac206fbf4ec08c815b214 100644 --- a/bin/libbfa.sh +++ b/bin/libbfa.sh @@ -21,6 +21,22 @@ test -n "$BASH_VERSION" || test "$( caller 2>/dev/null | awk '{print $1}' )" != "0" || fatal "This file must be source(d), not executed." +function yesno +{ + local defreply=${1,,} + local yn=Yn + test "$defreply" = "n" && + yn=yN + shift + REPLY= + read -p "$* [${yn}]: " -n 1 -e + REPLY=${REPLY,,} + if [ "$REPLY" != "y" -a "$REPLY" != "n" ] + then + REPLY=$defreply + fi +} + function cleanup { if [ $# -gt 0 ]