forked from msg768/smartnode
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathinstall.sh
More file actions
203 lines (174 loc) · 6.37 KB
/
install.sh
File metadata and controls
203 lines (174 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
# install.sh
# Installs SmartNodes on Ubuntu 16.04 LTS x64 and Ubuntu 18.04 LTS x64
# ATTENTION: The anti-ddos part will disable http, https and dns ports.
if [ "$(whoami)" != "root" ]; then
echo "Script must be run as user: root"
exit -1
fi
while true; do
if [ -d ~/.smartcash ]; then
printf "~/.smartcash/ already exists! The installer will delete this folder. Continue anyway? (y/n) "
read REPLY
if [ ${REPLY} == "Y" ] || [ ${REPLY} == "y" ]; then
pID=$(ps -ef | grep smartcashd | grep -v grep | awk '{print $2}')
kill ${pID} > /dev/null 2>&1
rm -rf ~/.smartcash/
break
else
if [ ${REPLY} == "N" ] || [ ${REPLY} == "n" ]; then
exit
fi
fi
else
break
fi
done
# Warning that the script will reboot the server
# echo "WARNING: This script will reboot the server when it's finished."
# printf "Press Ctrl+C to cancel or Enter to continue: "
# read IGNORE
cd
# Changing the SSH Port to a custom number is a good security measure against DDOS attacks
printf "Custom SSH Port(Enter to ignore): "
read VARIABLE
_sshPortNumber=${VARIABLE:-22}
# Get a new privatekey by going to console >> debug and typing smartnode genkey
printf "SmartNode GenKey: "
read _nodePrivateKey
# The RPC node will only accept connections from your localhost
_rpcUserName=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 12 ; echo '')
# Choose a random and secure password for the RPC
_rpcPassword=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32 ; echo '')
# Get the IP address of your vps which will be hosting the smartnode
_nodeIpAddress=$(curl -s 4.icanhazip.com)
if [[ ${_nodeIpAddress} =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
external_ip_line="externalip=${_nodeIpAddress}:9678"
else
external_ip_line="#externalip=external_IP_goes_here:9678"
fi
# Make a new directory for smartcash daemon
mkdir ~/.smartcash/
touch ~/.smartcash/smartcash.conf
# Change the directory to ~/.smartcash
cd ~/.smartcash/
# download bootstrap
# apt-get install unzip -y
# wget https://smartcash.cc/txindexstrap.zip
# unzip txindexstrap.zip
# rm txindexstrap.zip
# Create the initial smartcash.conf file
echo "rpcuser=${_rpcUserName}
rpcpassword=${_rpcPassword}
rpcallowip=127.0.0.1
listen=1
server=1
daemon=1
maxconnections=64
smartnode=1
$external_ip_line
smartnodeprivkey=${_nodePrivateKey}
" > smartcash.conf
cd
# Install smartcashd using apt-get
apt-get update -y
apt-get install software-properties-common -y
add-apt-repository ppa:smartcash/ppa -y && apt update -y && apt install smartcashd -y && smartcashd
# Create a directory for smartnode's cronjobs and the anti-ddos script
rm -r smartnode
mkdir smartnode
# Change the directory to ~/smartnode/
cd ~/smartnode/
# Download the appropriate scripts
wget https://raw.githubusercontent.com/SmartCash/smartnode/master/makerun.sh
wget https://raw.githubusercontent.com/SmartCash/smartnode/master/checkdaemon.sh
wget https://raw.githubusercontent.com/SmartCash/smartnode/master/upgrade.sh
wget https://raw.githubusercontent.com/SmartCash/smartnode/master/clearlog.sh
# Create a cronjob for making sure smartcashd runs after reboot
if ! crontab -l | grep "@reboot smartcashd"; then
(crontab -l ; echo "@reboot smartcashd") | crontab -
fi
# Create a cronjob for making sure smartcashd is always running
if ! crontab -l | grep "~/smartnode/makerun.sh"; then
(crontab -l ; echo "*/5 * * * * ~/smartnode/makerun.sh") | crontab -
fi
# Create a cronjob for making sure the daemon is never stuck
if ! crontab -l | grep "~/smartnode/checkdaemon.sh"; then
(crontab -l ; echo "*/30 * * * * ~/smartnode/checkdaemon.sh") | crontab -
fi
# Create a cronjob for making sure smartcashd is always up-to-date
# if ! crontab -l | grep "~/smartnode/upgrade.sh"; then
# (crontab -l ; echo "0 0 */1 * * ~/smartnode/upgrade.sh") | crontab -
# fi
# Create a cronjob for clearing the log file
if ! crontab -l | grep "~/smartnode/clearlog.sh"; then
(crontab -l ; echo "0 0 */2 * * ~/smartnode/clearlog.sh") | crontab -
fi
# Give execute permission to the cron scripts
chmod 0700 ./makerun.sh
chmod 0700 ./checkdaemon.sh
chmod 0700 ./upgrade.sh
chmod 0700 ./clearlog.sh
# Change the SSH port
sed -i "s/[#]\{0,1\}[ ]\{0,1\}Port [0-9]\{2,\}/Port ${_sshPortNumber}/g" /etc/ssh/sshd_config
# Firewall security measures
apt install ufw -y
ufw disable
ufw allow 9678
ufw allow "$_sshPortNumber"/tcp
ufw limit "$_sshPortNumber"/tcp
ufw logging on
ufw default deny incoming
ufw default allow outgoing
ufw --force enable
# Create aliases for commonly use smartcash-cli commands to ~/.bash_alises
if [ -e ~/.bash_aliases ]
then
if grep -q "getinfo" ~/.bash_aliases
then
echo "Aliases already exist, not adding again..."
else
echo "Adding aliases for common smartcash-cli commands to ~/.bash_aliases"
echo "
alias getinfo='smartcash-cli getinfo'
alias nodestatus='smartcash-cli smartnode status'
alias syncstatus='smartcash-cli snsync status'
alias restartnode='smartcash-cli stop && sleep 5 && smartcashd'
" > ~/.bash_aliases
echo " getinfo for 'smartcash-cli getinfo'"
echo " nodestatus for 'smartcash-cli smartnode status'"
echo " syncstatus for 'smartcash-cli syncstatus'"
echo " restartnode for 'smartcash-cli stop && sleep 5 && smartcashd'"
echo " Please log out/in for these changes to take effect"
fi
else
echo "Adding aliases for common smartcash-cli commands to ~/.bash_aliases"
echo "
alias getinfo='smartcash-cli getinfo'
alias nodestatus='smartcash-cli smartnode status'
alias syncstatus='smartcash-cli snsync status'
alias restartnode='smartcash-cli stop && sleep 5 && smartcashd'
" > ~/.bash_aliases
echo " getinfo for 'smartcash-cli getinfo'"
echo " nodestatus for 'smartcash-cli smartnode status'"
echo " syncstatus for 'smartcash-cli syncstatus'"
echo " restartnode for 'smartcash-cli stop && sleep 5 && smartcashd'"
echo " Please log out/in for these changes to take effect"
fi
# Add swap
if [[ $(swapon -s | wc -l) -gt 1 ]] ; then
echo "Skipping swap addition"
else
echo "Attempting to add swap"
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab
fi
# Reboot the server
# reboot
# Since we not longer reboot here, reload the SSH config to active the
# custom port if selected
systemctl reload sshd