Skip to content

Commit

Permalink
Add -n param to install_node.sh, update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
adamant-al committed Sep 25, 2021
1 parent dbb5af4 commit f08049c
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 48 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,31 @@ The manual describes API endpoints to manage accounts, transactions, chats, and

## Set up

- [How to run ADAMANT node (instructions for users)](https://medium.com/adamant-im/how-to-run-your-adamant-node-on-ubuntu-990e391e8fcc)
- [Installation script](./tools/install_node.sh)
[How to run ADAMANT node (instructions for users)](https://medium.com/adamant-im/how-to-run-your-adamant-node-on-ubuntu-990e391e8fcc). You can skip them if you are experienced Linux user.

## Requirements
### Requirements

- Ubuntu 18/20
- Ubuntu 18/20 (others are not tested)
- 2 GB RAM
- 50 GB disk space as on August 2021

### Installation script

For new droplets, use the [Installation script](./tools/install_node.sh), included in this repository, or run it from the ADAMANT website:

`sudo bash -c "$(wget -O - https://adamant.im/install_node.sh)"`

The script updates Ubuntu packages, creates user named adamant, installs PostgreSQL, Node.js and other necessary packages, sets up ADAMANT node, and optionally downloads up-to-date ADAMANT blockchain image.

Script parameters:

- `-b`: choose GitHub branch for node installation. Example: `-b dev`. Default is `master`.
- `-n`: choose `mainnet` or `testnet` network. Example: `-n testnet`. Default is `mainnet`.

F. e.,

`sudo bash -c "$(wget -O - https://adamant.im/install_node.sh)" -O -b dev -n testnet`

### Prerequisites

- Tool chain components — Used for compiling dependencies
Expand Down
126 changes: 82 additions & 44 deletions tools/install_node.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,75 @@
#!/usr/bin/env bash

branch="master"
while getopts 'b:' OPTION; do
network="mainnet"
username="adamant"
databasename="adamant_main"
configfile="config.json"
processname="adamant"
port="36666"

while getopts 'b:n:' OPTION; do
OPTARG=$(echo "$OPTARG" | xargs)
case "$OPTION" in
b)
branch="$OPTARG"
;;
n)
if [ "$OPTARG" == "testnet" ]
then
network="$OPTARG"
username="adamanttest"
databasename="adamant_test"
configfile="test/config.json"
processname="adamanttest"
port="36667"
elif [ "$OPTARG" != "mainnet" ]
then
printf "\nNetwork should be 'mainnet' or 'testnet'.\n\n"
exit 1
fi
;;
*)
printf "\nWrong parameters. Use '-b' for branch, '-t' for network.\n\n"
exit 1
;;
esac
done

printf "\n"
if [[ $branch != "master" ]]
then
printf "Note: You've choosed '%s' branch.\n" "$branch"
fi
printf "Welcome to the ADAMANT node installer v.1.3 for Ubuntu 18, 20. Make sure you got this file from adamant.im website or GitHub.\n"
printf "Welcome to the ADAMANT node installer v2.0 for Ubuntu 18, 20. Make sure you got this file from adamant.im website or GitHub.\n"
printf "This installer is the easiest way to run ADAMANT node. We still recommend to consult IT specialist if you are not familiar with Linux systems.\n"
printf "You can see full installation instructions on https://medium.com/adamant-im/how-to-run-your-adamant-node-on-ubuntu-990e391e8fcc\n"
printf "The installer will ask you to set database and user passwords during the installation.\n"
printf "Also, the system may ask to choose some parameters, like encoding, keyboard, and grub. Generally, you can leave them by default.\n\n"

read -r -p "WARNING! Running this script is recommended for new droplets ONLY. Existing data MAY BE DAMAGED. If you agree to continue, type \"yes\": " agreement
printf "Note: You've choosed '%s' network.\n" "$network"
printf "Note: You've choosed '%s' branch.\n" "$branch"
printf "\n"

read -r -p "WARNING! Running this script is recommended for new droplets. Existing data MAY BE DAMAGED. If you agree to continue, type \"yes\": " agreement
if [[ $agreement != "yes" ]]
then
printf "\nInstallation cancelled.\n\n"
exit 1
fi

printf "\nBlockchain image saves time on node sync but you must completely trust the image.\n"
printf "If you skip this step, your node will check every single transaction, which takes time (up for several days).\n"
read -r -p "Do you want to use the ADAMANT blockchain image to bootstrap a node? [Y/n]: " useimage
case $useimage in
[yY][eE][sS]|[yY]|[jJ]|'')
IMAGE=true
printf "\nI'll download blockchain image and your node will be on the actual height in a few minutes.\n\n"
;;
*)
IMAGE=false
printf "\nI'll sync your node from the beginning. It may take several days to raise up to the actual blockchain height.\n\n"
;;
esac
IMAGE=false
if [[ $network == "mainnet" ]]
then
printf "\nBlockchain image saves time on node sync but you must completely trust the image.\n"
printf "If you skip this step, your node will check every single transaction, which takes time (up for several days).\n"
read -r -p "Do you want to use the ADAMANT blockchain image to bootstrap a node? [Y/n]: " useimage
case $useimage in
[yY][eE][sS]|[yY]|[jJ]|'')
IMAGE=true
printf "\nI'll download blockchain image and your node will be on the actual height in a few minutes.\n\n"
;;
*)
printf "\nI'll sync your node from the beginning. It may take several days to raise up to the actual blockchain height.\n\n"
;;
esac
fi

hostname=$(cat "/etc/hostname")
if grep -q "$hostname" "/etc/hosts"
Expand All @@ -67,13 +95,13 @@ get_database_password () {
DB_PASSWORD="$(get_database_password)"

#User
printf "\n\nChecking if user 'adamant' exists…\n\n"
if [[ $(id -u adamant > /dev/null 2>&1; echo $?) = 1 ]]
printf "\n\nChecking if user '%s' exists…\n\n" "$username"
if [[ $(id -u "$username" > /dev/null 2>&1; echo $?) = 1 ]]
then
printf "Creating system user named 'adamant'…\n"
adduser --gecos "" adamant
sudo usermod -aG sudo adamant
printf "User 'adamant' has been created.\n\n"
printf "Creating system user named '%s'…\n" "$username"
adduser --gecos "" "$username"
sudo usermod -aG sudo "$username"
printf "User '%s' has been created.\n\n" "$username"
fi

#Packages
Expand All @@ -88,14 +116,14 @@ sudo apt install -y python build-essential curl automake autoconf libtool rpl mc
sudo service postgresql start

#Postgres
printf "\n\nCreating database 'adamant_main' and database user 'adamant'…\n\n"
printf "\n\nCreating database '%s' and database user '%s'…\n\n" "$databasename" "$username"
cd /tmp || echo "/tmp: No such directory"
sudo -u postgres psql -c "CREATE ROLE adamant LOGIN PASSWORD '${DB_PASSWORD}';"
sudo -u postgres psql -c "CREATE DATABASE adamant_main;"
sudo -u postgres psql -c "GRANT ALL on DATABASE adamant_main TO adamant;"
sudo -u postgres psql -c "CREATE ROLE ${username} LOGIN PASSWORD '${DB_PASSWORD}';"
sudo -u postgres psql -c "CREATE DATABASE ${databasename};"
sudo -u postgres psql -c "GRANT ALL on DATABASE ${databasename} TO ${username};"

#Run next commands as 'adamant' user
su - adamant <<EOSU
#Run next commands as user
su - "$username" <<EOSU
#NodeJS
printf "\n\nInstalling nvm & node.js…\n\n"
Expand All @@ -107,19 +135,19 @@ nvm i --lts=fermium
npm i -g pm2
#ADAMANT
printf "\n\nInstalling ADAMANT node. Cloning project repository from GitHub ('%s' branch)…\n\n" "$branch"
printf "\n\nInstalling ADAMANT '%s' node. Cloning project repository from GitHub ('%s' branch)…\n\n" "$network" "$branch"
git clone https://github.com/Adamant-im/adamant --branch $branch
cd adamant || { printf "\n\nUnable to enter node's directory 'adamant'. Something is wrong, halting.\n\n"; exit 1; }
npm i
#Setup node: set DB password in config.json
printf "\n\nSetting node's config…\n\n"
rpl -i -q '"password": "password",' "\"password\": \"${DB_PASSWORD}\"," config.json
rpl -i -q '"password": "password",' "\"password\": \"${DB_PASSWORD}\"," "$configfile"
#By default, node's API is available only from localhost
#rpl -i -q '"public": false,' '"public": true,' config.json
#rpl -i -q '"public": false,' '"public": true,' "$configfile"
# Download actual blockchain image
# Download actual blockchain image for 'mainnet' network
if [[ $IMAGE = true ]]
then
printf "\n\nDownloading actual blockchain image…\n\n"
Expand All @@ -132,16 +160,26 @@ then
rm db_backup.sql
fi
printf "\n\nAdding ADAMANT node to crontab for autostart after system reboot…\n\n"
crontab -l | { cat; echo "@reboot cd /home/adamant/adamant && pm2 start --name adamant app.js"; } | crontab -
printf "\n\nAdding ADAMANT '%s' node to crontab for autostart after system reboot…\n\n" "$network"
if [[ $network == "mainnet" ]]
then
crontab -l | { cat; echo "@reboot cd /home/adamant/adamant && pm2 start --name adamant app.js"; } | crontab -
else
crontab -l | { cat; echo "@reboot cd /home/adamanttest/adamant && pm2 start --name adamanttest app.js -- --config test/config.json --genesis test/genesisBlock.json"; } | crontab -
fi
printf "\n\nRunning ADAMANT node…\n\n"
pm2 start --name adamant app.js
printf "\n\nRunning ADAMANT '%s' node…\n\n" "$network"
if [[ $network == "mainnet" ]]
then
pm2 start --name adamant app.js
else
pm2 start --name adamanttest app.js -- --config test/config.json --genesis test/genesisBlock.json
fi
EOSU

printf "\n\nFinished ADAMANT node installation script. Executed in %s seconds.\n" "$SECONDS"
printf "Check your node status with 'pm2 show adamant' command.\n"
printf "Current node's height: 'curl http://localhost:36666/api/blocks/getHeight'\n"
printf "\n\nFinished ADAMANT '%s' node installation script. Executed in %s seconds.\n" "$network" "$SECONDS"
printf "Check your node status with 'pm2 show %s' command.\n" "$processname"
printf "Current node's height: 'curl http://localhost:%s/api/blocks/getHeight'\n" "$port"
printf "Thank you for supporting true decentralized ADAMANT Messenger.\n\n"
su - adamant
su - "$username"

0 comments on commit f08049c

Please sign in to comment.