diff --git a/README.md b/README.md index 25a373f8..7290e3d0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tools/install_node.sh b/tools/install_node.sh index c7d9ea74..fc5e2846 100644 --- a/tools/install_node.sh +++ b/tools/install_node.sh @@ -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" @@ -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 @@ -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 <