Skip to content
Snippets Groups Projects
Commit d35d659e authored by Robert Martin-Legene's avatar Robert Martin-Legene
Browse files

Simplifying installation script

parent bdc11652
No related branches found
No related tags found
No related merge requests found
...@@ -21,40 +21,15 @@ function info ...@@ -21,40 +21,15 @@ function info
echo '***' 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 # For getting a recent nodejs
function nodejs_pre function nodejsinstall
{ {
info nodejs info nodejs
# Nodejs software repository PGP key # Nodejs software repository PGP key
if [ `apt-key export ${NODEJSPGP} 2>&1 | wc -l` -le 50 ] if [ `apt-key export ${NODEJSPGP} 2>&1 | wc -l` -le 50 ]
then then
yesno n Add nodejs software repository PGP key && info Add nodejs software repository PGP key
apt-key adv --keyserver keyserver.ubuntu.com --recv ${NODEJSPGP} apt-key adv --keyserver keyserver.ubuntu.com --recv ${NODEJSPGP}
fi fi
local file=/etc/apt/sources.list.d/nodesource.list local file=/etc/apt/sources.list.d/nodesource.list
if [ ! -r "$file" ] if [ ! -r "$file" ]
...@@ -64,26 +39,28 @@ function nodejs_pre ...@@ -64,26 +39,28 @@ function nodejs_pre
info And now updating the software package list. info And now updating the software package list.
apt update apt update
fi fi
aptinstall nodejs npm # nodejs also provides npm
aptinstall nodejs
} }
function nodejs_post function web3install
{ {
info Initialising nodejs. (
test -r "package.json" || cd ~bfa
npm init -y test -r package.json ||
info Initialising nodejs. &&
sudo -u bfa npm init -y
)
# nodejs package(s) that we need. # nodejs package(s) that we need.
nodejs -e 'require("web3")' 2>/dev/null && return echo 'require("web3")' | sudo -u bfa nodejs 2>/dev/null && return
yesno n Installing nodejs module: web3 info Installing nodejs module: web3
npm install web3 sudo -u bfa npm install web3
} }
function golang_pre function golanginstall
{ {
unset installedusrlocalgo
if [ ! -d /usr/local/go ] if [ ! -d /usr/local/go ]
then then
installedusrlocalgo=1
info Downloading package of go binaries. info Downloading package of go binaries.
mkdir -p ~/new mkdir -p ~/new
cd ~/new cd ~/new
...@@ -126,7 +103,7 @@ function golang_pre ...@@ -126,7 +103,7 @@ function golang_pre
PATH=${PATH}:/usr/local/go/bin PATH=${PATH}:/usr/local/go/bin
} }
function geth_pre function gethinstall
{ {
mkdir -p ~/new mkdir -p ~/new
cd ~/new cd ~/new
...@@ -136,19 +113,13 @@ function geth_pre ...@@ -136,19 +113,13 @@ function geth_pre
cd ~/new/go-ethereum cd ~/new/go-ethereum
info Running git pull to ensure that the local go-ethereum repo is up-to-date. info Running git pull to ensure that the local go-ethereum repo is up-to-date.
git pull git pull
} #
function geth_compile
{
cd ~/new/go-ethereum cd ~/new/go-ethereum
info Compiling geth info Compiling geth
make geth make all &&
} echo Ignore that last line, if it tells you to run geth now.
function geth_post
{
mkdir -p ~bfa/bin 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 chown -R bfa:bfa ~bfa
} }
...@@ -165,9 +136,9 @@ function aptinstall ...@@ -165,9 +136,9 @@ function aptinstall
function usersetup function usersetup
{ {
if echo ~bfa | grep -qvE '^/' && yesno n Add required user \"bfa\" if ! id bfa >/dev/null 2>&1
then then
info Adding BFA user \"bfa\". info Add required user \"bfa\"
adduser --disabled-password --gecos 'Blockchain Federal Argentina' bfa adduser --disabled-password --gecos 'Blockchain Federal Argentina' bfa
fi fi
cd ~bfa cd ~bfa
...@@ -177,7 +148,7 @@ function usersetup ...@@ -177,7 +148,7 @@ function usersetup
git clone https://gitlab.bfa.ar/blockchain/nucleo.git bfa git clone https://gitlab.bfa.ar/blockchain/nucleo.git bfa
fi fi
# updating # updating
cd bfa cd ~bfa/bfa
git pull git pull
# #
cd ~bfa cd ~bfa
...@@ -188,40 +159,27 @@ function usersetup ...@@ -188,40 +159,27 @@ function usersetup
fi 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 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 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 - ( crontab -u bfa -l ; echo '@reboot bfa/bin/cron.sh' ) | crontab -u bfa -
fi fi
} }
function welcome function welcome
{ {
echo info "(re)log in as user bfa"
echo "(re)log in as user bfa"
} }
# development tools # development tools
aptinstall dirmngr apt-transport-https curl git curl build-essential aptinstall dirmngr apt-transport-https curl git curl build-essential
nodejs_pre
usersetup usersetup
nodejs_post nodejsinstall
golang_pre web3install
geth_pre golanginstall
geth_compile gethinstall
geth_post
golang_post
cronit cronit
welcome welcome
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment