diff --git a/bin/installbfa.sh b/bin/installbfa.sh index f95aef8b1970b1da9a030cb36e2274cd57961783..39e5dfb1224e53d2c2feb828eb779be51779af0b 100755 --- a/bin/installbfa.sh +++ b/bin/installbfa.sh @@ -28,19 +28,16 @@ function info # Runs as the owner of the given directory, and in the given directory function runasownerof { - path=$1 - precmd= + local where=$1 precmd= shift 1 - pushd $path > /dev/null + pushd $where > /dev/null if [ $( stat --format=%u . ) -ne $UID ] then - precmd="sudo --preserve-env --set-home -u $( stat --format=%U . ) PATH=${PATH}" + precmd="sudo --preserve-env --shell --set-home --user=$( stat --format=%U . ) PATH=${PATH}" fi - unset path ${precmd} "$@" - rv=$? + local rv=$? popd > /dev/null - unset precmd return $rv } @@ -66,56 +63,7 @@ function nodejsinstall aptinstall nodejs info "Installing nodejs modules (will show many warnings)" runasownerof ${BFAHOME} npm install -} - -function golanginstall -{ - if [ ! -d /usr/local/go ] - then - info "Downloading package of go binaries." - mkdir -p ${NEW} - cd ${NEW} - local arch=$( uname -m ) - case "${arch}" in - x86_64) - arch=amd64 - ;; - *) - echo "We have no recipe for how to build on your \"${arch}\" platform." >&2 - exit 1 - ;; - esac - - #Download go*.linux-${ARCH}.tar.gz from https://golang.org/dl/ - golangurl=$( - curl -f https://golang.org/dl/ 2>/dev/null | - grep linux-${arch}.tar.gz | - grep downloadBox | - sed 's/.*href="//;s/".*//' | - head -1 - ) - name=$( basename $golangurl ) - if [ -r "$name" ] - then - # If we have the download, check if it is corrupt - tar -ztf "$name" >/dev/null 2>&1 || - rm -f "$name" - fi - if [ ! -r "$name" ] - then - curl -f -O $golangurl || - rm -f "$name" - fi - # Integrity checking the archive - tar -xzf "$name" - info "Unpacking $name into /usr/local" - tar -C /usr/local -xzf go*.tar.gz - fi - if [ $( expand < ~bfa/.bashrc | grep -E "^PATH=.*/usr/local/go/bin" | wc -l ) -eq 0 ] - then - echo "PATH=\${PATH}:/usr/local/go/bin" >> ~bfa/.bashrc - fi - export PATH=${PATH}:/usr/local/go/bin + runasownerof ${BFAHOME} npm audit fix } function gethinstall @@ -142,13 +90,14 @@ function gethinstall function initgenesis { ( + HOME=$( echo ~bfa ) source ${BFAHOME}/bin/env BFANETWORKDIR=${BFANETWORKDIR:-${BFAHOME}/network} BFANODEDIR=${BFANODEDIR:-${BFANETWORKDIR}/node} if [ ! -d "${BFANODEDIR}" -o ! -d "${BFANODEDIR}/geth/chaindata" ] then info "Node is not initialised. Initialising with genesis." - geth --networkid ${BFANETWORKID} --cache 0 --datadir "${BFANODEDIR}" init "${BFANETWORKDIR}/genesis.json" + runasownerof "${BFAHOME}" geth --networkid ${BFANETWORKID} --cache 0 --datadir "${BFANODEDIR}" init "${BFANETWORKDIR}/genesis.json" chown -R bfa:bfa ~bfa fi ) @@ -259,11 +208,10 @@ grep -q Ubuntu /etc/issue && apt-add-repository multiverse # apt update # development tools -aptinstall dirmngr apt-transport-https curl git curl build-essential sudo software-properties-common +aptinstall dirmngr apt-transport-https curl git curl build-essential sudo software-properties-common golang aptinstall jq libjson-perl libwww-perl libclass-accessor-perl userconfig nodejsinstall -golanginstall gethinstall initgenesis cronit