-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_node
More file actions
176 lines (153 loc) · 4.92 KB
/
setup_node
File metadata and controls
176 lines (153 loc) · 4.92 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
#!/bin/bash
TMP_FOLDER=$(mktemp -d)
CONFIG_FILE='solidus.conf'
CONFIGFOLDER='/root/.solidus'
COIN_DAEMON='solidusd'
COIN_CLI='solidus-cli'
COIN_PATH='/usr/local/bin/'
COIN_NAME='solidus'
COIN_PORT=8200
RPC_PORT=8300
NODEIP=$(curl -s4 icanhazip.com)
BLUE="\033[0;34m"
YELLOW="\033[0;33m"
CYAN="\033[0;36m"
PURPLE="\033[0;35m"
RED='\033[0;31m'
GREEN="\033[0;32m"
NC='\033[0m'
MAG='\e[1;35m'
function configure_systemd() {
cat << EOF > /etc/systemd/system/$COIN_NAME.service
[Unit]
Description=$COIN_NAME service
After=network.target
[Service]
User=root
Group=root
Type=forking
#PIDFile=$CONFIGFOLDER/$COIN_NAME.pid
ExecStart=$COIN_PATH$COIN_DAEMON -daemon -conf=$CONFIGFOLDER/$CONFIG_FILE -datadir=$CONFIGFOLDER
ExecStop=-$COIN_PATH$COIN_CLI -conf=$CONFIGFOLDER/$CONFIG_FILE -datadir=$CONFIGFOLDER stop
Restart=always
PrivateTmp=true
TimeoutStopSec=60s
TimeoutStartSec=10s
StartLimitInterval=120s
StartLimitBurst=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
sleep 3
systemctl start $COIN_NAME.service
systemctl enable $COIN_NAME.service >/dev/null 2>&1
if [[ -z "$(ps axo cmd:100 | egrep $COIN_DAEMON)" ]]; then
echo -e "${RED}$COIN_NAME is not running${NC}, please investigate. You should start by running the following commands as root:"
echo -e "${GREEN}systemctl start $COIN_NAME.service"
echo -e "systemctl status $COIN_NAME.service"
echo -e "less /var/log/syslog${NC}"
exit 1
fi
}
function create_config() {
mkdir $CONFIGFOLDER >/dev/null 2>&1
RPCUSER=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w10 | head -n1)
RPCPASSWORD=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w22 | head -n1)
cat << EOF > $CONFIGFOLDER/$CONFIG_FILE
rpcuser=$RPCUSER
rpcpassword=$RPCPASSWORD
rpcport=$RPC_PORT
rpcallowip=127.0.0.1
listen=1
server=1
daemon=1
port=$COIN_PORT
EOF
}
function create_key() {
echo -e "${YELLOW}Enter your ${RED}$COIN_NAME Masternode GEN Key${NC}."
read -e COINKEY
if [[ -z "$COINKEY" ]]; then
$COIN_PATH$COIN_DAEMON -daemon
sleep 30
if [ -z "$(ps axo cmd:100 | grep $COIN_DAEMON)" ]; then
echo -e "${RED}$COIN_NAME server couldn not start. Check /var/log/syslog for errors.{$NC}"
exit 1
fi
COINKEY=$($COIN_PATH$COIN_CLI createmasternodekey)
if [ "$?" -gt "0" ];
then
echo -e "${RED}Wallet not fully loaded. Please wait 30 seconds and I will try again to generate a key. Do not press any buttons.${NC}"
sleep 30
COINKEY=$($COIN_PATH$COIN_CLI createmasternodekey)
fi
$COIN_PATH$COIN_CLI stop
fi
}
function update_config() {
sed -i 's/daemon=1/daemon=0/' $CONFIGFOLDER/$CONFIG_FILE
cat << EOF >> $CONFIGFOLDER/$CONFIG_FILE
logintimestamps=1
maxconnections=256
#bind=$NODEIP
masternode=1
externalip=$NODEIP:$COIN_PORT
masternodeprivkey=$COINKEY
EOF
}
function enable_firewall() {
echo -e "Installing and setting up firewall to allow ingress on port ${GREEN}$COIN_PORT${NC}"
ufw allow $COIN_PORT/tcp comment "$COIN_NAME MN port" >/dev/null
ufw allow ssh comment "SSH" >/dev/null 2>&1
ufw limit ssh/tcp >/dev/null 2>&1
ufw default allow outgoing >/dev/null 2>&1
echo "y" | ufw enable >/dev/null 2>&1
}
function get_ip() {
declare -a NODE_IPS
for ips in $(netstat -i | awk '!/Kernel|Iface|lo/ {print $1," "}')
do
NODE_IPS+=($(curl --interface $ips --connect-timeout 2 -s4 icanhazip.com))
done
if [ ${#NODE_IPS[@]} -gt 1 ]
then
echo -e "${GREEN}More than one IP. Please type 0 to use the first IP, 1 for the second and so on...${NC}"
INDEX=0
for ip in "${NODE_IPS[@]}"
do
echo ${INDEX} $ip
let INDEX=${INDEX}+1
done
read -e choose_ip
NODEIP=${NODE_IPS[$choose_ip]}
else
NODEIP=${NODE_IPS[0]}
fi
}
function important_information() {
echo
echo -e "${BLUE}================================================================================================================================${NC}"
echo -e "${GREEN}$COIN_NAME Masternode is up and running listening on port${NC} ${PURPLE}$COIN_PORT${NC}."
echo -e "${GREEN}Configuration file is: ${NC}${RED}$CONFIGFOLDER/$CONFIG_FILE${NC}"
echo -e "${GREEN}Start: ${NC}${RED}systemctl start $COIN_NAME.service${NC}"
echo -e "${GREEN}Stop: ${NC}${RED}systemctl stop $COIN_NAME.service${NC}"
echo -e "${GREEN}Node_IP: ${NC}${RED}$NODEIP:$COIN_PORT${NC}"
echo -e "${YELLOW}Usage Commands:${NC}"
echo -e "${GREEN}solidus-cli getmasternodestatus${NC}"
echo -e "${GREEN}solidus-cli getinfo${NC}"
echo -e "${BLUE}================================================================================================================================${NC}"
}
function setup_node() {
get_ip
create_config
create_key
update_config
enable_firewall
important_information
configure_systemd
}
echo -e ">>> ${YELLOW}Ensure your Desktop Wallet address has 1000 SLDS and its started before running this script.${NC}"
echo -e ">>> ${YELLOW}Have your wallet address ready in hand${NC}"
echo
echo -e ">>> ${GREEN}Once all ready, Run a command : "setup_node"${NC}"