Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
lephleg committed Feb 21, 2019
2 parents 12ca4bd + a95ae5c commit 759a791
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 40 deletions.
4 changes: 2 additions & 2 deletions docker-compose.letsencrypt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ services:
ports:
- "7075:7075/udp"
- "7075:7075"
- "127.0.0.1:7076:7076"
- "::1:7076:7076"
volumes:
- ./nano-node:/root/RaiBlocks
- ./nano-node:/root

nano-node-monitor:
image: nanotools/nanonodemonitor
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ services:
ports:
- "7075:7075/udp"
- "7075:7075"
- "127.0.0.1:7076:7076"
- "::1:7076:7076"
volumes:
- ./nano-node:/root/RaiBlocks
- ./nano-node:/root

nano-node-monitor:
image: nanotools/nanonodemonitor
Expand Down
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ The following flags are available when running the stack installer:
</tr>
</table>

### NANO Node CLI bash alias

NANO node runs inside the nano-node container. In order to execute commands from its [Command Line Interface](https://github.com/nanocurrency/raiblocks/wiki/Command-line-interface) you'll have to enter the container or execute them by using the following Docker command:

```
$ docker exec -it nano-node rai_node <command>
```

For convinience the following shorthand alias is set by the installer:

```
$ rai <command>
```

Both of the above formats are interchangeable.

## Examples

### **Install with SSL enabled**
Expand Down
126 changes: 90 additions & 36 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# VERSION
version='v4.0'

# OUTPUT VARS
red=`tput setaf 1`
green=`tput setaf 2`
Expand Down Expand Up @@ -28,6 +31,12 @@ done

echo $@ > settings

# PRINT INSTALLER DETAILS
[[ $quiet = 'false' ]] && echo "${green} ----------------------${reset}"
[[ $quiet = 'false' ]] && echo "${green}${bold} NANO Node Docker ${version}${reset}"
[[ $quiet = 'false' ]] && echo "${green} ----------------------${reset}"
[[ $quiet = 'false' ]] && echo ""

# VERIFY TOOLS INSTALLATIONS
docker -v &> /dev/null
if [ $? -ne 0 ]; then
Expand Down Expand Up @@ -59,25 +68,46 @@ fi
if [[ $fastSync = 'true' ]]; then

if [[ $quiet = 'false' ]]; then
printf "${yellow}Downloading latest ledger files for fast-syncing...${reset}\n"
printf "=> ${yellow}Downloading latest ledger files for fast-syncing...${reset}\n"
wget -O todaysledger.7z https://nanonode.ninja/api/ledger/download -q --show-progress

printf "${yellow}Unzipping and placing the files (takes a while)...${reset} "
7z x todaysledger.7z -o./nano-node -y &> /dev/null
printf "=> ${yellow}Unzipping and placing the files (takes a while)...${reset} "
7z x todaysledger.7z -o./nano-node/RaiBlocks -y &> /dev/null
rm todaysledger.7z
printf "${green}done.${reset}\n"
echo ""

else
wget -O todaysledger.7z https://nanonode.ninja/api/ledger/download -q
docker-compose stop nano-node &> /dev/null
7z x todaysledger.7z -o./nano-node -y &> /dev/null
7z x todaysledger.7z -o./nano-node/RaiBlocks -y &> /dev/null
rm todaysledger.7z
fi

fi

# DETERMINE IF THIS IS AN INITIAL INSTALL
[[ $quiet = 'false' ]] && echo "=> ${yellow}Checking initial status...${reset}"
[[ $quiet = 'false' ]] && echo ""

# check if node mounted directory exists
if [ -d "./nano-node" ]; then
# check if mounted directory follows the new /root structure
if [ ! -d "./nano-node/RaiBlocks" ]; then
if [ ! -d "./nano-node/Nano" ]; then
[[ $quiet = 'false' ]] && printf "${reset}Unsupported directory structure detected. Migrating files... "
mkdir ./nano-node/RaiBlocks
# move everything into subdirectory and suppress the error about itself
mv ./nano-node/* ./nano-node/RaiBlocks/ &> /dev/null
[[ $quiet = 'false' ]] && printf "${green}done.\n${reset}"
[[ $quiet = 'false' ]] && echo ""
fi
fi
fi

# SPIN UP THE APPROPRIATE STACK
[[ $quiet = 'false' ]] && echo "${yellow}Pulling images and spinning up containers...${reset}"
[[ $quiet = 'false' ]] && echo "=> ${yellow}Pulling images and spinning up containers...${reset}"
[[ $quiet = 'false' ]] && echo ""

docker network create nano-node-network &> /dev/null

Expand Down Expand Up @@ -121,59 +151,72 @@ if [ $? -ne 0 ]; then
fi

# CHECK NODE INITIALIZATION
[[ $quiet = 'false' ]] && printf "${yellow}Waiting for NANO node to fully initialize... "
[[ $quiet = 'false' ]] && echo ""
[[ $quiet = 'false' ]] && printf "=> ${yellow}Waiting for NANO node to fully initialize... "

isRpcLive="$(curl -s -d '{"action": "version"}' 127.0.0.1:7076 | grep "rpc_version")"
isRpcLive="$(curl -s -d '{"action": "version"}' [::1]:7076 | grep "rpc_version")"
while [ ! -n "$isRpcLive" ];
do
sleep 1s
isRpcLive="$(curl -s -d '{"action": "version"}' 127.0.0.1:7076 | grep "rpc_version")"
isRpcLive="$(curl -s -d '{"action": "version"}' [::1]:7076 | grep "rpc_version")"
done

[[ $quiet = 'false' ]] && printf "${green}done.${reset}\n"
[[ $quiet = 'false' ]] && printf "${green}done.${reset}\n\n"

# DETERMINE NODE VERSION
nodeExec="docker exec -it nano-node /usr/bin/rai_node"
eval "$nodeExec --version" &> /dev/null

# if rai_node doesn't exist, use nano_node
if [ $? -ne 0 ]; then
nodeExec="docker exec -it nano-node /usr/bin/nano_node"
fi

# SET BASH ALIASES FOR NODE CLI
if [ -f ~/.bash_aliases ]; then
alias=$(cat ~/.bash_aliases | grep 'nano');
if [[ ! $alias ]]; then
echo "alias nano='${nodeExec}'" >> ~/.bash_aliases;
source ~/.bashrc;
fi
else
echo "alias nano='${nodeExec}'" >> ~/.bash_aliases;
source ~/.bashrc;
fi

# WALLET SETUP
existedWallet="$(docker exec -it nano-node /usr/bin/rai_node --wallet_list | grep 'Wallet ID' | awk '{ print $NF}')"
existedWallet="$(${nodeExec} --wallet_list | grep 'Wallet ID' | awk '{ print $NF}')"

if [[ ! $existedWallet ]]; then
[[ $quiet = 'false' ]] && printf "${yellow}No wallet found. Generating a new one... ${reset}"
[[ $quiet = 'false' ]] && printf "=> ${yellow}No wallet found. Generating a new one... ${reset}"

walletId=$(docker exec -it nano-node /usr/bin/rai_node --wallet_create | tr -d '\r')
address=$(docker exec -it nano-node /usr/bin/rai_node --account_create --wallet=$walletId | awk '{ print $NF}')
walletId=$(${nodeExec} --wallet_create | tr -d '\r')
address="$(${nodeExec} --account_create --wallet=$walletId | awk '{ print $NF}')"

[[ $quiet = 'false' ]] && printf "${green}done.${reset}\n"
[[ $quiet = 'false' ]] && printf "${green}done.${reset}\n\n"
else
[[ $quiet = 'false' ]] && echo "${yellow}Existing wallet found.${reset}"
[[ $quiet = 'false' ]] && echo "=> ${yellow}Existing wallet found.${reset}"
[[ $quiet = 'false' ]] && echo ''

address="$(docker exec -it nano-node /usr/bin/rai_node --wallet_list | grep 'xrb_' | awk '{ print $NF}' | tr -d '\r')"
address="$(${nodeExec} --wallet_list | grep 'xrb_' | awk '{ print $NF}' | tr -d '\r')"
walletId=$(echo $existedWallet | tr -d '\r')

fi

if [[ $quiet = 'false' && $displaySeed = 'true' ]]; then
seed=$(docker exec -it nano-node /usr/bin/rai_node --wallet_decrypt_unsafe --wallet=$walletId | grep 'Seed' | awk '{ print $NF}')
fi

if [[ $quiet = 'false' ]]; then
echo "${yellow} -------------------------------------------------------------------------------------- ${reset}"
echo "${yellow} Node account address: ${green}$address${yellow} "
if [[ $displaySeed = 'true' ]]; then
echo "${yellow} Node wallet seed: ${red}${bold}$seed${reset}${yellow} "
fi
echo "${yellow} -------------------------------------------------------------------------------------- ${reset}"
seed=$(${nodeExec} --wallet_decrypt_unsafe --wallet=$walletId | grep 'Seed' | awk '{ print $NF}')
fi

# UPDATE MONITOR CONFIGS
if [ ! -f ./nano-node-monitor/config.php ]; then
[[ $quiet = 'false' ]] && echo "${yellow}No existing NANO Node Monitor config file found. Fetching a fresh copy...${reset}"
[[ $quiet = 'false' ]] && echo "=> ${yellow}No existing NANO Node Monitor config file found. Fetching a fresh copy...${reset}"
if [[ $quiet = 'false' ]]; then
docker-compose restart nano-node-monitor
else
docker-compose restart nano-node-monitor > /dev/null
fi
fi

[[ $quiet = 'false' ]] && printf "${yellow}Configuring NANO Node Monitor... ${reset}"
[[ $quiet = 'false' ]] && printf "=> ${yellow}Configuring NANO Node Monitor... ${reset}"

sed -i -e "s/\/\/ \$nanoNodeRPCIP.*;/\$nanoNodeRPCIP/g" ./nano-node-monitor/config.php
sed -i -e "s/\$nanoNodeRPCIP.*/\$nanoNodeRPCIP = 'nano-node';/g" ./nano-node-monitor/config.php
Expand All @@ -200,16 +243,27 @@ sed -i -e "s/\/\/ \$blockExplorer.*;/\$blockExplorer = 'meltingice';/g" ./nano-n
# remove any carriage returns may have been included by sed replacements
sed -i -e 's/\r//g' ./nano-node-monitor/config.php

[[ $quiet = 'false' ]] && printf "${green}done.${reset}\n"
[[ $quiet = 'false' ]] && printf "${green}done.${reset}\n\n"

if [[ $quiet = 'false' ]]; then
echo "${yellow} ---------------------------------------------------------------------"
echo "${green} ${bold}Congratulations! NANO Node Docker stack has been setup successfully!${reset}"
echo "${yellow} --------------------------------------------------------------------- ${reset}"
echo "${yellow} |======================================================================================| ${reset}"
echo "${green} ${bold}|Congratulations! NANO Node Docker stack has been setup successfully! |${reset}"
echo "${yellow} |======================================================================================| ${reset}"
echo "${yellow} |Node account address: ${green}$address${yellow}|"
if [[ $displaySeed = 'true' ]]; then
echo "${yellow} |Node wallet seed: ${red}${bold}$seed${reset}${yellow} |"
fi
echo "${yellow} |======================================================================================| ${reset}"

echo ""

if [[ $domain ]]; then
echo "${yellow}Open a browser and navigate to ${green}https://$domain${yellow} to check your monitor."
echo "${yellow} Open a browser and navigate to ${green}https://$domain${yellow} to check your monitor."
else
echo "${yellow}Open a browser and navigate to ${green}http://$ipAddress${yellow} to check your monitor."
echo "${yellow} Open a browser and navigate to ${green}http://$ipAddress${yellow} to check your monitor."
fi
echo "${yellow}You can further configure and personalize your monitor by editing the config file located in ${green}nano-node-monitor/config.php${yellow}.${reset}"
echo "${yellow} You can further configure and personalize your monitor by editing the config file located in ${green}nano-node-monitor/config.php${yellow}.${reset}"

echo ""

fi

0 comments on commit 759a791

Please sign in to comment.