diff --git a/bin/installbfa.sh b/bin/installbfa.sh index a6f821aea786d042a32266d2962b5fa0566e2131..3601ecd11333836722404715a3d8cfc7173fafea 100755 --- a/bin/installbfa.sh +++ b/bin/installbfa.sh @@ -21,40 +21,15 @@ function info echo '***' } -function yesno -{ - local defval=$1 - shift - local yn="yN" - test "${defval,,}" = "y" && - yn="Yn" - REPLY= - while [ "${REPLY}" != "y" -a "${REPLY}" != "n" ] - do - read -s -n 1 -p "${*}? [${yn}]: " - test -z "${REPLY}" && - REPLY=${defval:0:1} - REPLY=${REPLY,,} - test "$REPLY" != "y" -a "$REPLY" != "n" && - REPLY= - done - echo $REPLY - if [ "$REPLY" = "n" ] - then - return 1 - fi - return 0 -} - # For getting a recent nodejs -function nodejs_pre +function nodejsinstall { info nodejs # Nodejs software repository PGP key if [ `apt-key export ${NODEJSPGP} 2>&1 | wc -l` -le 50 ] then - yesno n Add nodejs software repository PGP key && - apt-key adv --keyserver keyserver.ubuntu.com --recv ${NODEJSPGP} + info Add nodejs software repository PGP key + apt-key adv --keyserver keyserver.ubuntu.com --recv ${NODEJSPGP} fi local file=/etc/apt/sources.list.d/nodesource.list if [ ! -r "$file" ] @@ -64,26 +39,28 @@ function nodejs_pre info And now updating the software package list. apt update fi - aptinstall nodejs npm + # nodejs also provides npm + aptinstall nodejs } -function nodejs_post +function web3install { - info Initialising nodejs. - test -r "package.json" || - npm init -y + ( + cd ~bfa + test -r package.json || + info Initialising nodejs. && + sudo -u bfa npm init -y + ) # nodejs package(s) that we need. - nodejs -e 'require("web3")' 2>/dev/null && return - yesno n Installing nodejs module: web3 - npm install web3 + echo 'require("web3")' | sudo -u bfa nodejs 2>/dev/null && return + info Installing nodejs module: web3 + sudo -u bfa npm install web3 } -function golang_pre +function golanginstall { - unset installedusrlocalgo if [ ! -d /usr/local/go ] then - installedusrlocalgo=1 info Downloading package of go binaries. mkdir -p ~/new cd ~/new @@ -126,7 +103,7 @@ function golang_pre PATH=${PATH}:/usr/local/go/bin } -function geth_pre +function gethinstall { mkdir -p ~/new cd ~/new @@ -136,19 +113,13 @@ function geth_pre cd ~/new/go-ethereum info Running git pull to ensure that the local go-ethereum repo is up-to-date. git pull -} - -function geth_compile -{ + # cd ~/new/go-ethereum info Compiling geth - make geth -} - -function geth_post -{ + make all && + echo Ignore that last line, if it tells you to run geth now. mkdir -p ~bfa/bin - cp -vp ~/new/go-ethereum/build/bin/geth ~bfa/bin/ + cp -vp ~/new/go-ethereum/build/bin/{geth,bootnode,abigen,ethkey,puppeth,rlpdump,wnode,swarm,swarm-smoke} ~bfa/bin/ chown -R bfa:bfa ~bfa } @@ -165,9 +136,9 @@ function aptinstall function usersetup { - if echo ~bfa | grep -qvE '^/' && yesno n Add required user \"bfa\" + if ! id bfa >/dev/null 2>&1 then - info Adding BFA user \"bfa\". + info Add required user \"bfa\" adduser --disabled-password --gecos 'Blockchain Federal Argentina' bfa fi cd ~bfa @@ -177,7 +148,7 @@ function usersetup git clone https://gitlab.bfa.ar/blockchain/nucleo.git bfa fi # updating - cd bfa + cd ~bfa/bfa git pull # cd ~bfa @@ -188,40 +159,27 @@ function usersetup fi } -function golang_post -{ - if [ -n "${installedusrlocalgo}" ] - then - yesno n Remove unneeded go installation /usr/local/go && - rm -rf /usr/local/go - fi -} - function cronit { - if crontab -u bfa -l | expand | grep -qvE '^@reboot +bfa/bin/cron.sh$' + if crontab -u bfa -l 2>/dev/null | expand | grep -qvE '^@reboot +bfa/bin/cron.sh$' then - yesno n Install crontab to start automatically upon reboot || return + info Install crontab to start automatically upon reboot ( crontab -u bfa -l ; echo '@reboot bfa/bin/cron.sh' ) | crontab -u bfa - fi } function welcome { - echo - echo "(re)log in as user bfa" + info "(re)log in as user bfa" } # development tools aptinstall dirmngr apt-transport-https curl git curl build-essential -nodejs_pre usersetup -nodejs_post -golang_pre -geth_pre -geth_compile -geth_post -golang_post +nodejsinstall +web3install +golanginstall +gethinstall cronit welcome