├── LICENSE ├── README.md ├── checkdaemon.sh ├── clearlog.sh ├── install.sh ├── makerun.sh ├── patches ├── patch-0.1.sh ├── patch-0.2.sh ├── patch-0.3.sh └── patch-0.4.sh └── upgrade.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Markus GH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SmartNode 2 | ### Bash installer to install SmartNodes on Ubuntu 16.04 LTS x64 and Ubuntu 18.04 LTS x64. 3 | 4 | #### This shell script comes with 4 cronjobs: 5 | 1. Make sure the daemon is always running: `makerun.sh` 6 | 2. Make sure the daemon is never stuck: `checkdaemon.sh` 7 | 3. Make sure smartcash is always up-to-date: `upgrade.sh` 8 | 4. Clear the log file every other day: `clearlog.sh` 9 | 10 | #### On the client-side, use your node-client (formerly known as wallet) and click "Create Smartnode." Input an alias of your choosing, your server's IP address, select a collateral TX and copy/write down your SmartNodeKey. 11 | 12 | #### Login to your vps as root, download the install.sh file and then run it, enter the SmartNodeKey you got above when asked for SmartNode GenKey: 13 | ``` 14 | wget https://rawgit.com/smartcash/smartnode/master/install.sh 15 | bash ./install.sh 16 | ``` 17 | 18 | #### Run the node-client (formerly known as wallet), go to SmartNodes tab, choose your node and click "start alias" at the bottom. 19 | 20 | #### You're good to go now. BEE $SMART! https://smartcash.cc 21 | -------------------------------------------------------------------------------- /checkdaemon.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # checkdaemon.sh 3 | # Make sure the daemon is not stuck. 4 | # Add the following to the crontab (i.e. crontab -e) 5 | # */30 * * * * ~/smartnode/checkdaemon.sh 6 | 7 | previousBlock=$(cat ~/smartnode/blockcount) 8 | currentBlock=$(smartcash-cli getblockcount) 9 | 10 | smartcash-cli getblockcount > ~/smartnode/blockcount 11 | 12 | if [ "$previousBlock" == "$currentBlock" ]; then 13 | smartcash-cli stop 14 | sleep 10 15 | smartcashd 16 | fi 17 | -------------------------------------------------------------------------------- /clearlog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # clearlog.sh 3 | # Clear debug.log every other day 4 | # Add the following to the crontab (i.e. crontab -e) 5 | # 0 0 */2 * * ~/smartnode/clearlog.sh 6 | 7 | /bin/date > ~/.smartcash/debug.log 8 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # install.sh 3 | # Installs SmartNodes on Ubuntu 16.04 LTS x64 and Ubuntu 18.04 LTS x64 4 | # ATTENTION: The anti-ddos part will disable http, https and dns ports. 5 | 6 | if [ "$(whoami)" != "root" ]; then 7 | echo "Script must be run as user: root" 8 | exit -1 9 | fi 10 | 11 | while true; do 12 | if [ -d ~/.smartcash ]; then 13 | printf "~/.smartcash/ already exists! The installer will delete this folder. Continue anyway? (y/n) " 14 | read REPLY 15 | if [ ${REPLY} == "Y" ] || [ ${REPLY} == "y" ]; then 16 | pID=$(ps -ef | grep smartcashd | grep -v grep | awk '{print $2}') 17 | kill ${pID} > /dev/null 2>&1 18 | rm -rf ~/.smartcash/ 19 | break 20 | else 21 | if [ ${REPLY} == "N" ] || [ ${REPLY} == "n" ]; then 22 | exit 23 | fi 24 | fi 25 | else 26 | break 27 | fi 28 | done 29 | 30 | # Warning that the script will reboot the server 31 | # echo "WARNING: This script will reboot the server when it's finished." 32 | # printf "Press Ctrl+C to cancel or Enter to continue: " 33 | # read IGNORE 34 | 35 | cd 36 | # Changing the SSH Port to a custom number is a good security measure against DDOS attacks 37 | printf "Custom SSH Port(Enter to ignore): " 38 | read VARIABLE 39 | _sshPortNumber=${VARIABLE:-22} 40 | 41 | # Get a new privatekey by going to console >> debug and typing smartnode genkey 42 | printf "SmartNode GenKey: " 43 | read _nodePrivateKey 44 | 45 | # The RPC node will only accept connections from your localhost 46 | _rpcUserName=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 12 ; echo '') 47 | 48 | # Choose a random and secure password for the RPC 49 | _rpcPassword=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32 ; echo '') 50 | 51 | # Get the IP address of your vps which will be hosting the smartnode 52 | _nodeIpAddress=$(curl -s 4.icanhazip.com) 53 | if [[ ${_nodeIpAddress} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then 54 | external_ip_line="externalip=${_nodeIpAddress}:9678" 55 | else 56 | external_ip_line="#externalip=external_IP_goes_here:9678" 57 | fi 58 | 59 | # Make a new directory for smartcash daemon 60 | mkdir ~/.smartcash/ 61 | touch ~/.smartcash/smartcash.conf 62 | 63 | # Change the directory to ~/.smartcash 64 | cd ~/.smartcash/ 65 | 66 | # download bootstrap 67 | # apt-get install unzip -y 68 | # wget https://smartcash.cc/txindexstrap.zip 69 | # unzip txindexstrap.zip 70 | # rm txindexstrap.zip 71 | 72 | # Create the initial smartcash.conf file 73 | echo "rpcuser=${_rpcUserName} 74 | rpcpassword=${_rpcPassword} 75 | rpcallowip=127.0.0.1 76 | listen=1 77 | server=1 78 | daemon=1 79 | maxconnections=64 80 | smartnode=1 81 | $external_ip_line 82 | smartnodeprivkey=${_nodePrivateKey} 83 | " > smartcash.conf 84 | cd 85 | 86 | # Install smartcashd using apt-get 87 | apt-get update -y 88 | apt-get install software-properties-common -y 89 | add-apt-repository ppa:smartcash/ppa -y && apt update -y && apt install smartcashd -y && smartcashd 90 | 91 | # Create a directory for smartnode's cronjobs and the anti-ddos script 92 | rm -r smartnode 93 | mkdir smartnode 94 | 95 | # Change the directory to ~/smartnode/ 96 | cd ~/smartnode/ 97 | 98 | # Download the appropriate scripts 99 | wget https://raw.githubusercontent.com/SmartCash/smartnode/master/makerun.sh 100 | wget https://raw.githubusercontent.com/SmartCash/smartnode/master/checkdaemon.sh 101 | wget https://raw.githubusercontent.com/SmartCash/smartnode/master/upgrade.sh 102 | wget https://raw.githubusercontent.com/SmartCash/smartnode/master/clearlog.sh 103 | 104 | # Create a cronjob for making sure smartcashd runs after reboot 105 | if ! crontab -l | grep "@reboot smartcashd"; then 106 | (crontab -l ; echo "@reboot smartcashd") | crontab - 107 | fi 108 | 109 | # Create a cronjob for making sure smartcashd is always running 110 | if ! crontab -l | grep "~/smartnode/makerun.sh"; then 111 | (crontab -l ; echo "*/5 * * * * ~/smartnode/makerun.sh") | crontab - 112 | fi 113 | 114 | # Create a cronjob for making sure the daemon is never stuck 115 | if ! crontab -l | grep "~/smartnode/checkdaemon.sh"; then 116 | (crontab -l ; echo "*/30 * * * * ~/smartnode/checkdaemon.sh") | crontab - 117 | fi 118 | 119 | # Create a cronjob for making sure smartcashd is always up-to-date 120 | # if ! crontab -l | grep "~/smartnode/upgrade.sh"; then 121 | # (crontab -l ; echo "0 0 */1 * * ~/smartnode/upgrade.sh") | crontab - 122 | # fi 123 | 124 | # Create a cronjob for clearing the log file 125 | if ! crontab -l | grep "~/smartnode/clearlog.sh"; then 126 | (crontab -l ; echo "0 0 */2 * * ~/smartnode/clearlog.sh") | crontab - 127 | fi 128 | 129 | # Give execute permission to the cron scripts 130 | chmod 0700 ./makerun.sh 131 | chmod 0700 ./checkdaemon.sh 132 | chmod 0700 ./upgrade.sh 133 | chmod 0700 ./clearlog.sh 134 | 135 | # Change the SSH port 136 | sed -i "s/[#]\{0,1\}[ ]\{0,1\}Port [0-9]\{2,\}/Port ${_sshPortNumber}/g" /etc/ssh/sshd_config 137 | 138 | # Firewall security measures 139 | apt install ufw -y 140 | ufw disable 141 | ufw allow 9678 142 | ufw allow "$_sshPortNumber"/tcp 143 | ufw limit "$_sshPortNumber"/tcp 144 | ufw logging on 145 | ufw default deny incoming 146 | ufw default allow outgoing 147 | ufw --force enable 148 | 149 | # Create aliases for commonly use smartcash-cli commands to ~/.bash_alises 150 | if [ -e ~/.bash_aliases ] 151 | then 152 | if grep -q "getinfo" ~/.bash_aliases 153 | then 154 | echo "Aliases already exist, not adding again..." 155 | else 156 | echo "Adding aliases for common smartcash-cli commands to ~/.bash_aliases" 157 | echo " 158 | alias getinfo='smartcash-cli getinfo' 159 | alias nodestatus='smartcash-cli smartnode status' 160 | alias syncstatus='smartcash-cli snsync status' 161 | alias restartnode='smartcash-cli stop && sleep 5 && smartcashd' 162 | " > ~/.bash_aliases 163 | echo " getinfo for 'smartcash-cli getinfo'" 164 | echo " nodestatus for 'smartcash-cli smartnode status'" 165 | echo " syncstatus for 'smartcash-cli syncstatus'" 166 | echo " restartnode for 'smartcash-cli stop && sleep 5 && smartcashd'" 167 | echo " Please log out/in for these changes to take effect" 168 | fi 169 | 170 | else 171 | echo "Adding aliases for common smartcash-cli commands to ~/.bash_aliases" 172 | echo " 173 | alias getinfo='smartcash-cli getinfo' 174 | alias nodestatus='smartcash-cli smartnode status' 175 | alias syncstatus='smartcash-cli snsync status' 176 | alias restartnode='smartcash-cli stop && sleep 5 && smartcashd' 177 | " > ~/.bash_aliases 178 | echo " getinfo for 'smartcash-cli getinfo'" 179 | echo " nodestatus for 'smartcash-cli smartnode status'" 180 | echo " syncstatus for 'smartcash-cli syncstatus'" 181 | echo " restartnode for 'smartcash-cli stop && sleep 5 && smartcashd'" 182 | echo " Please log out/in for these changes to take effect" 183 | fi 184 | 185 | # Add swap 186 | if [[ $(swapon -s | wc -l) -gt 1 ]] ; then 187 | echo "Skipping swap addition" 188 | else 189 | echo "Attempting to add swap" 190 | fallocate -l 4G /swapfile 191 | chmod 600 /swapfile 192 | mkswap /swapfile 193 | swapon /swapfile 194 | cp /etc/fstab /etc/fstab.bak 195 | echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab 196 | fi 197 | 198 | # Reboot the server 199 | # reboot 200 | 201 | # Since we not longer reboot here, reload the SSH config to active the 202 | # custom port if selected 203 | systemctl reload sshd 204 | -------------------------------------------------------------------------------- /makerun.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # makerun.sh 3 | # Make sure smartcashd is always running. 4 | # Add the following to the crontab (i.e. crontab -e) 5 | # */5 * * * * ~/smartnode/makerun.sh 6 | 7 | if ps -A | grep smartcashd > /dev/null 8 | then 9 | exit 10 | else 11 | smartcashd & 12 | fi 13 | -------------------------------------------------------------------------------- /patches/patch-0.1.sh: -------------------------------------------------------------------------------- 1 | # Change the directory to ~/smartnode 2 | cd ~/smartnode 3 | 4 | # Download the new crontjob 5 | wget https://raw.githubusercontent.com/SmartCash/smartnode/master/clearlog.sh 6 | 7 | # Create a cronjob for clearing the log file 8 | if ! crontab -l | grep "~/smartnode/clearlog.sh"; then 9 | (crontab -l ; echo "0 0 */2 * * ~/smartnode/clearlog.sh") | crontab - 10 | fi 11 | 12 | # Give execute permission to the cron script 13 | chmod 0700 ./clearlog.sh 14 | 15 | ./clearlog.sh 16 | -------------------------------------------------------------------------------- /patches/patch-0.2.sh: -------------------------------------------------------------------------------- 1 | #Attention: There is an issue with the update.sh cronjob which is kind of good because an update 2 | # requires a manual start so it's betteri f you update manually. Only run this patch if you want to update automatically. 3 | # This patch will fix the issue with update.sh cronjob and will then upgrade your node using the ppa. 4 | 5 | # Check smartcash is running every 5 minutes instead of 1 minute 6 | crontab -l | sed 's/.*makerun.sh/\*\/5 \* \* \* \* ~\/smartnode\/makerun.sh/g' | crontab - 7 | 8 | # Check if upgrade is available every two hours 9 | crontab -l | sed 's/.*upgrade.sh/0 *\/2 \* \* \* ~\/smartnode\/upgrade.sh/g' | crontab - 10 | 11 | # Add a cronjob to start smartcash after reboot 12 | if ! crontab -l | grep "@reboot smartcashd"; then 13 | (crontab -l ; echo "@reboot smartcashd") | crontab - 14 | fi 15 | 16 | # Update the makerun.sh and upgrade.sh shell scripts 17 | cd ~/smartnode 18 | wget https://raw.githubusercontent.com/SmartCash/smartnode/master/makerun.sh -O makerun.sh 19 | wget https://raw.githubusercontent.com/SmartCash/smartnode/master/upgrade.sh -O upgrade.sh 20 | 21 | ./upgrade.sh 22 | -------------------------------------------------------------------------------- /patches/patch-0.3.sh: -------------------------------------------------------------------------------- 1 | # The anti-ddos script was not working properly so decided to remove it 2 | cd 3 | cd smartnode 4 | rm anti-ddos.sh 5 | 6 | # New security measures using ufw 7 | _sshPortNumber=$(grep "^[#]\{0,1\}[ ]\{0,1\}Port [0-9]\{2,\}" /etc/ssh/sshd_config | awk '{print $2}') 8 | apt install ufw -y 9 | ufw disable 10 | ufw allow 9678 11 | ufw allow "$_sshPortNumber"/tcp 12 | ufw limit "$_sshPortNumber"/tcp 13 | ufw logging on 14 | ufw default deny incoming 15 | ufw default allow outgoing 16 | ufw --force enable 17 | -------------------------------------------------------------------------------- /patches/patch-0.4.sh: -------------------------------------------------------------------------------- 1 | // Change directory 2 | cd 3 | cd smartnode 4 | 5 | // Update upgrade.sh to disable automatic updates 6 | wget https://raw.githubusercontent.com/SmartCash/smartnode/master/upgrade.sh -O upgrade.sh 7 | -------------------------------------------------------------------------------- /upgrade.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # upgrade.sh 3 | # Make sure smartcash is up-to-date 4 | # Add the following to the crontab (i.e. crontab -e) 5 | # 0 0 */1 * * ~/smartnode/upgrade.sh 6 | 7 | # apt update 8 | 9 | # if apt list --upgradable | grep -v grep | grep smartcashd > /dev/null 10 | # then 11 | # smartcash-cli stop && sleep 10 12 | # rm ~/.smartcash/peers.* 13 | # apt install smartcashd -y && smartcashd& 14 | # else 15 | # exit 16 | # fi 17 | --------------------------------------------------------------------------------