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.nav.io
addnode=testnet2.nav.io
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

chmod +x install_navio.sh

Step 3: Run the Script

sudo ./install_navio.sh

Post-Installation

Check Service Status

sudo systemctl status naviod
sudo systemctl status navio-staker

Check the Logs

  • Daemon logs: /home/navio/.navio/testnet4/debug.log
  • Staker logs: /home/navio/.navio/testnet4/staker.log

Example:

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

How to Get Testnet Coins

Join our Discord and use /faucet in the #testnet channel.

How to Interact with the Daemon

Switch to the navio user:

sudo su - navio
navio-cli -testnet command

Or use:

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.
  • stakelock amount: Stake coins (minimum 10000).
  • stakeunlock amount: Unstake (must leave 10000 staked minimum).

Troubleshooting

  • Check Log Files: Look for error messages.
  • Check Service Status: Use systemctl status for both services.
  • Check Dependencies: Re-run script if anything failed.

For persistent issues, reach out to the Navio community or refer to project documentation.