Installation Guide

Prerequisites

  • A server or virtual machine running a Debian-based Linux distribution (e.g., Ubuntu).
  • Sudo privileges on the server.
  • Internet connection for downloading dependencies.

Script Description

The provided script automates the following tasks:

  1. Installs necessary dependencies.
  2. Creates a dedicated user (navio).
  3. Clones the Navio repository.
  4. Builds the Navio project from source.
  5. Creates a default configuration file.
  6. Creates a wallet.
  7. Sets up systemd service files for both the Navio daemon and the staker.
  8. Enables and starts the services.

Installation Steps

Step 1: Download the Script

First, copy the following script and save it as a file called install_navio.sh in your server.

The Script

#!/bin/bash

# Function to install necessary dependencies
install_dependencies() {
    sudo apt-get update
    sudo apt-get install -y \
        build-essential \
        libtool \
        autotools-dev \
        automake \
        pkg-config \
        libssl-dev \
        libevent-dev \
        bsdmainutils \
        libboost-system-dev \
        libboost-filesystem-dev \
        libboost-chrono-dev \
        libboost-test-dev \
        libboost-thread-dev \
        libminiupnpc-dev \
        libzmq3-dev \
        libsqlite3-dev \
        git \
        software-properties-common
}

# Function to create a dedicated user
create_user() {
    sudo useradd -m -s /bin/bash navio
}

# Function to clone the repository
clone_repository() {
    if [ -d /home/navio/navio-core ]; then
        cd /home/navio/navio-core || exit
        sudo -u navio git pull origin master
    else
        sudo -u navio git clone https://github.com/nav-io/navio-core.git /home/navio/navio-core
        cd /home/navio/navio-core || exit
    fi
}

# Function to build the project
build_navio() {
    sudo -u navio ./autogen.sh
    sudo -u navio ./configure
    sudo -u navio make -j$(nproc)
    sudo make install
}

# Function to create a default configuration file
create_default_config() {
    sudo -u navio mkdir -p /home/navio/.navio
    sudo -u navio bash -c 'cat << EOF > /home/navio/.navio/navio.conf
server=1
listen=1
testnet=1
rpcuser=user
rpcpassword=password

[test]
addnode=testnet-navio.nav.community
rpcuser=user
rpcpassword=password
EOF'
    sudo chown -R navio:navio /home/navio/.navio
}

# Function to create a wallet
create_wallet() {
    sudo -u navio /home/navio/navio-core/src/navio-wallet -blsct -chain=test -wallet=wallet create
}

# Function to create systemd service file for naviod
create_naviod_service_file() {
    sudo bash -c 'cat << EOF > /etc/systemd/system/naviod.service
[Unit]
Description=Navio Daemon
After=network.target

[Service]
ExecStart=/usr/local/bin/naviod -conf=/home/navio/.navio/navio.conf
User=navio
Group=navio
Restart=always
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF'
}

# Function to create systemd service file for navio-staker
create_navio_staker_service_file() {
    sudo bash -c 'cat << EOF > /etc/systemd/system/navio-staker.service
[Unit]
Description=Navio Staker
After=network.target

[Service]
ExecStart=/usr/local/bin/navio-staker -testnet -wallet=wallet
User=navio
Group=navio
Restart=always
RestartSec=10s
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF'
}

# Function to enable and start services
enable_and_start_services() {
    sudo systemctl daemon-reload
    sudo systemctl enable naviod
    sudo systemctl start naviod
    sudo systemctl enable navio-staker
    sudo systemctl start navio-staker
}

# Main function to execute the script
main() {
    install_dependencies
    create_user
    clone_repository
    build_navio
    create_default_config
    create_wallet
    create_naviod_service_file
    create_navio_staker_service_file
    enable_and_start_services
    echo "Navio daemon and staker installation and setup complete."
}

main

Step 2: Make the Script Executable

Make sure the script has executable permissions.

chmod +x install_navio.sh

Step 3: Run the Script

Execute the script with sudo to ensure it has the necessary permissions.

sudo ./install_navio.sh

Post-Installation

Check Service Status

After the installation, check the status of the Navio daemon and staker services to ensure they are running correctly.

sudo systemctl status naviod
sudo systemctl status navio-staker

Check the Logs

  • The logs for the daemon are located in /home/navio/.navio/testnet3/debug.log.
  • The logs for the staker are located in /home/navio/.navio/testnet3/staker.log.

To view the logs, you can use the cat, less, or tail commands. For example:

cat /home/navio/.navio/testnet3/debug.log

How to Get Testnet Coins

Join our Discord at http://discord.gg/Rjy3RVxDjC and use the command /faucet in the #testnet channel.

How to Interact with the Daemon

You need to run navio-cli -testnet command as the navio user. You can switch to the navio user or use sudo:

To switch to the navio user:

sudo su - navio

Then run the command:

navio-cli -testnet command

Alternatively, run the command directly with sudo:

sudo -u navio navio-cli -testnet command

Available Commands

  • getnewaddress: Shows an address to receive coins.
  • getbalance: Shows the wallet balance
  • sendtoblsctaddress address amount: Send coins to an address.
  • stakelock amount: Stake an amount of coins (minimum is 10000).
  • stakeunlock amount: Remove from staking (the remaining staking should be 10000 at a minimum).

Troubleshooting

If you encounter any issues, consider the following steps:

  • Check the Log File: Review the log files for detailed error messages.
  • Verify Service Status: Ensure the services are running using systemctl status naviod and systemctl status navio-staker.
  • Check Dependencies: Make sure all dependencies are installed properly. Re-run the script to ensure no steps were missed.

If you continue to face issues, you can seek support from the Navio community or refer to the project's documentation and forums.