forked from YuraBakkar/Transcendence-Dynamic-Chain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lobohub.sh
344 lines (341 loc) · 12.3 KB
/
lobohub.sh
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#/bin/bash
cd ~
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
IP4COUNT=$(find /root/.transcendence_* -maxdepth 0 -type d | wc -l)
DELETED="$(cat /root/bin/deleted | wc -l)"
ALIASES="$(find /root/.transcendence_* -maxdepth 0 -type d | cut -c22-)"
face="$(lshw -C network | grep "logical name:" | sed -e 's/logical name:/logical name: /g' | awk '{print $3}' | head -n1)"
if [[ $(lsb_release -d) != *16.04* ]]; then
echo -e "${RED}You are not running Ubuntu 16.04. Installation is cancelled.${NC}"
exit 1
fi
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}$0 must be run as root.${NC}"
exit 1
fi
function configure_systemd() {
cat << EOF > /etc/systemd/system/transcendenced$ALIAS.service
[Unit]
Description=transcendenced$ALIAS service
After=network.target
[Service]
User=root
Group=root
Type=forking
#PIDFile=/root/.transcendence_$ALIAS/transcendenced.pid
ExecStart=/root/bin/transcendenced_$ALIAS.sh
ExecStop=/root/bin/transcendence-cli_$ALIAS.sh stop
Restart=always
PrivateTmp=true
TimeoutStopSec=60s
TimeoutStartSec=10s
StartLimitInterval=120s
StartLimitBurst=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
sleep 6
crontab -l > cron$ALIAS
echo "@reboot systemctl start transcendenced$ALIAS" >> cron$ALIAS
crontab cron$ALIAS
rm cron$ALIAS
systemctl start transcendenced$ALIAS.service
}
IP4=$(curl -s4 api.ipify.org)
perl -i -ne 'print if ! $a{$_}++' /etc/network/interfaces
if [ ! -f "/usr/local/bin/transcendenced" ]; then
DOSETUP="y"
else
DOSETUP="n"
fi
clear
echo -e "${RED}This script is not compatible with older versions of it by default. Use it on a fresh VPS or disable bind manually to enable backwards compatibility.${NC}"
echo ""
echo "1 - Create new nodes"
echo "2 - Remove an existing node"
echo "3 - List aliases"
echo "4 - Check for node errors"
echo "What would you like to do?"
read DO
echo ""
if [ $DO = "4" ]
then
echo $ALIASES > temp1
cat temp1 | grep -o '[^ |]*' > temp2
CN="$(cat temp2 | wc -l)"
rm temp1
let LOOP=0
while [ $LOOP -lt $CN ]; do
LOOP=$((LOOP+1))
CURRENT="$(sed -n "${LOOP}p" temp2)"
echo -e "${GREEN}${CURRENT}${NC}:"
sh /root/bin/transcendence-cli_${CURRENT}.sh masternode status | grep "message"
OFFSET="$(sh /root/bin/transcendence-cli_${CURRENT}.sh getinfo | grep "timeoffset")"
OFF1=${OFFSET:(-2)}
OFF=${OFF1:0:1}
if [ $OFF = "1" ]
then
echo "$OFFSET"
fi
done
rm temp2
fi
if [ $DO = "3" ]
then
echo -e "${GREEN}${ALIASES}${NC}"
echo ""
echo "1 - Create new nodes"
echo "2 - Remove an existing node"
echo "What would you like to do?"
read DO
echo ""
fi
if [ $DO = "2" ]
then
perl -i -ne 'print if ! $a{$_}++' /etc/monit/monitrc >/dev/null 2>&1
echo "Input the alias of the node that you want to delete"
read ALIASD
echo ""
echo -e "${GREEN}Deleting ${ALIASD}${NC}. Please wait."
## Removing service
systemctl stop transcendenced$ALIASD >/dev/null 2>&1
systemctl disable transcendenced$ALIASD >/dev/null 2>&1
rm /etc/systemd/system/transcendenced${ALIASD}.service >/dev/null 2>&1
systemctl daemon-reload >/dev/null 2>&1
systemctl reset-failed >/dev/null 2>&1
## Removing monit and directory
rm /root/.transcendence_$ALIASD -r >/dev/null 2>&1
sed -i "/${ALIASD}/d" .bashrc
crontab -l -u root | grep -v transcendenced$ALIASD | crontab -u root - >/dev/null 2>&1
source .bashrc
echo "1" >> /root/bin/deleted
echo -e "${ALIASD} Successfully deleted."
fi
if [ $DO = "1" ]
then
echo "1 - Easy mode"
echo "2 - Expert mode"
echo "Please select a option:"
read EE
echo ""
if [ $EE = "1" ]
then
MAXC="38"
fi
if [ $EE = "2" ]
then
echo ""
echo "Enter max connections value"
read MAXC
fi
if [ $DOSETUP = "y" ]
then
echo -e "Installing ${GREEN}Transcendence dependencies${NC}. Please wait."
apt-get update
apt-get -y upgrade
apt-get -y dist-upgrade
apt-get update
apt-get install -y zip unzip bc curl nano lshw gawk
echo -e "${RED}Creating swap. This may take a while.${NC}"
dd if=/dev/zero of=/var/swap.img bs=2048 count=1M
chmod 600 /var/swap.img
mkswap /var/swap.img
swapon /var/swap.img
free -m
echo "/var/swap.img none swap sw 0 0" >> /etc/fstab
cd /root
if [ ! -f Linux.zip ]
then
wget https://github.com/phoenixkonsole/transcendence/releases/download/v1.1.0.0/Linux.zip -O /root/Linux.zip
fi
unzip Linux.zip
chmod +x Linux/bin/*
mv Linux/bin/* /usr/local/bin
rm -rf Linux.zip Windows Linux Mac
apt-get install -y ufw
ufw allow ssh/tcp
ufw limit ssh/tcp
ufw logging on
echo "y" | ufw enable
ufw allow 22123
mkdir -p ~/bin
echo 'export PATH=~/bin:$PATH' > ~/.bash_aliases
source ~/.bashrc
echo ""
cd
sysctl vm.swappiness=10
sysctl vm.vfs_cache_pressure=200
echo 'vm.swappiness=10' | tee -a /etc/sysctl.conf
echo 'vm.vfs_cache_pressure=200' | tee -a /etc/sysctl.conf
fi
if [ ! -f Bootstrap.zip ]
then
wget https://aeros-os.org/Bootstrap1.zip -O /root/Bootstrap.zip
fi
gateway1=$(/sbin/route -A inet6 | grep -v ^fe80 | grep -v ^ff00 | grep -w "$face")
gateway2=${gateway1:0:26}
gateway3="$(echo -e "${gateway2}" | tr -d '[:space:]')"
if [[ $gateway3 = *"128"* ]]; then
gateway=${gateway3::-5}
fi
if [[ $gateway3 = *"64"* ]]; then
gateway=${gateway3::-3}
fi
MASK="/64"
echo -e "Telos nodes currently installed: ${GREEN}${IP4COUNT}${NC}, Telos nodes previously Deleted: ${GREEN}${DELETED}${NC}"
echo ""
if [ $IP4COUNT = "0" ]
then
echo -e "${RED}First node must be ipv4.${NC}"
let COUNTER=0
PORT=22123
RPCPORTT=22130
RPCPORT=$(($RPCPORTT+$COUNTER))
echo ""
echo "Enter alias for first node"
read ALIAS
CONF_DIR=~/.transcendence_$ALIAS
echo ""
echo "Enter masternode private key for node $ALIAS"
read PRIVKEY
if [ $EE = "2" ]
then
echo ""
echo "Enter port for $ALIAS"
read PORTD
fi
mkdir ~/.transcendence_$ALIAS
unzip Bootstrap.zip -d ~/.transcendence_$ALIAS >/dev/null 2>&1
echo '#!/bin/bash' > ~/bin/transcendenced_$ALIAS.sh
echo "transcendenced -daemon -conf=$CONF_DIR/transcendence.conf -datadir=$CONF_DIR "'$*' >> ~/bin/transcendenced_$ALIAS.sh
echo '#!/bin/bash' > ~/bin/transcendence-cli_$ALIAS.sh
echo "transcendence-cli -conf=$CONF_DIR/transcendence.conf -datadir=$CONF_DIR "'$*' >> ~/bin/transcendence-cli_$ALIAS.sh
echo '#!/bin/bash' > ~/bin/transcendence-tx_$ALIAS.sh
echo "transcendence-tx -conf=$CONF_DIR/transcendence.conf -datadir=$CONF_DIR "'$*' >> ~/bin/transcendence-tx_$ALIAS.sh
chmod 755 ~/bin/transcendence*.sh
mkdir -p $CONF_DIR
echo "rpcuser=user"`shuf -i 100000-10000000 -n 1` >> transcendence.conf_TEMP
echo "rpcpassword=pass"`shuf -i 100000-10000000 -n 1` >> transcendence.conf_TEMP
echo "rpcallowip=127.0.0.1" >> transcendence.conf_TEMP
echo "rpcport=$RPCPORT" >> transcendence.conf_TEMP
echo "listen=1" >> transcendence.conf_TEMP
echo "server=1" >> transcendence.conf_TEMP
echo "daemon=1" >> transcendence.conf_TEMP
echo "logtimestamps=1" >> transcendence.conf_TEMP
echo "maxconnections=$MAXC" >> transcendence.conf_TEMP
echo "masternode=1" >> transcendence.conf_TEMP
echo "dbcache=20" >> transcendence.conf_TEMP
echo "maxorphantx=5" >> transcendence.conf_TEMP
echo "maxmempool=100" >> transcendence.conf_TEMP
echo "" >> transcendence.conf_TEMP
echo "" >> transcendence.conf_TEMP
echo "bind=$IP4:$PORT" >> transcendence.conf_TEMP
echo "externalip=$IP4" >> transcendence.conf_TEMP
echo "masternodeaddr=$IP4:$PORT" >> transcendence.conf_TEMP
echo "masternodeprivkey=$PRIVKEY" >> transcendence.conf_TEMP
mv transcendence.conf_TEMP $CONF_DIR/transcendence.conf
echo ""
echo -e "Your ip is ${GREEN}$IP4:$PORT${NC}"
echo "alias ${ALIAS}_status=\"transcendence-cli -datadir=/root/.transcendence_${ALIAS} masternode status\"" >> .bashrc
echo "alias ${ALIAS}_stop=\"systemctl stop transcendenced$ALIAS\"" >> .bashrc
echo "alias ${ALIAS}_start=\"systemctl start transcendenced$ALIAS\"" >> .bashrc
echo "alias ${ALIAS}_config=\"nano /root/.transcendence_${ALIAS}/transcendence.conf\"" >> .bashrc
echo "alias ${ALIAS}_getinfo=\"transcendence-cli -datadir=/root/.transcendence_${ALIAS} getinfo\"" >> .bashrc
echo "alias ${ALIAS}_getpeerinfo=\"transcendence-cli -datadir=/root/.transcendence_${ALIAS} getpeerinfo\"" >> .bashrc
echo "alias ${ALIAS}_resync=\"/root/bin/transcendenced_${ALIAS}.sh -resync\"" >> .bashrc
echo "alias ${ALIAS}_reindex=\"/root/bin/transcendenced_${ALIAS}.sh -reindex\"" >> .bashrc
echo "alias ${ALIAS}_restart=\"systemctl restart transcendenced$ALIAS\"" >> .bashrc
## Config Systemctl
configure_systemd
fi
if [ $IP4COUNT != "0" ]
then
echo "How many ipv6 nodes do you want to install on this server?"
read MNCOUNT
let MNCOUNT=MNCOUNT+1
let MNCOUNT=MNCOUNT+IP4COUNT
let MNCOUNT=MNCOUNT+DELETED
let COUNTER=1
let COUNTER=COUNTER+IP4COUNT
let COUNTER=COUNTER+DELETED
while [ $COUNTER -lt $MNCOUNT ]; do
PORT=22123
RPCPORTT=22130
RPCPORT=$(($RPCPORTT+$COUNTER))
echo ""
echo "Enter alias for new node"
read ALIAS
CONF_DIR=~/.transcendence_$ALIAS
echo ""
echo "Enter masternode private key for node $ALIAS"
read PRIVKEY
echo "up /sbin/ip -6 addr add ${gateway}$COUNTER$MASK dev $face # $ALIAS" >> /etc/network/interfaces
/sbin/ip -6 addr add ${gateway}$COUNTER$MASK dev $face
mkdir ~/.transcendence_$ALIAS
unzip Bootstrap.zip -d ~/.transcendence_$ALIAS >/dev/null 2>&1
echo '#!/bin/bash' > ~/bin/transcendenced_$ALIAS.sh
echo "transcendenced -daemon -conf=$CONF_DIR/transcendence.conf -datadir=$CONF_DIR "'$*' >> ~/bin/transcendenced_$ALIAS.sh
echo '#!/bin/bash' > ~/bin/transcendence-cli_$ALIAS.sh
echo "transcendence-cli -conf=$CONF_DIR/transcendence.conf -datadir=$CONF_DIR "'$*' >> ~/bin/transcendence-cli_$ALIAS.sh
echo '#!/bin/bash' > ~/bin/transcendence-tx_$ALIAS.sh
echo "transcendence-tx -conf=$CONF_DIR/transcendence.conf -datadir=$CONF_DIR "'$*' >> ~/bin/transcendence-tx_$ALIAS.sh
chmod 755 ~/bin/transcendence*.sh
mkdir -p $CONF_DIR
echo "rpcuser=user"`shuf -i 100000-10000000 -n 1` >> transcendence.conf_TEMP
echo "rpcpassword=pass"`shuf -i 100000-10000000 -n 1` >> transcendence.conf_TEMP
echo "rpcallowip=127.0.0.1" >> transcendence.conf_TEMP
echo "rpcport=$RPCPORT" >> transcendence.conf_TEMP
echo "listen=1" >> transcendence.conf_TEMP
echo "server=1" >> transcendence.conf_TEMP
echo "daemon=1" >> transcendence.conf_TEMP
echo "logtimestamps=1" >> transcendence.conf_TEMP
echo "maxconnections=$MAXC" >> transcendence.conf_TEMP
echo "masternode=1" >> transcendence.conf_TEMP
echo "dbcache=20" >> transcendence.conf_TEMP
echo "maxorphantx=5" >> transcendence.conf_TEMP
echo "maxmempool=100" >> transcendence.conf_TEMP
echo "bind=[${gateway}$COUNTER]:$PORT" >> transcendence.conf_TEMP
echo "externalip=[${gateway}$COUNTER]" >> transcendence.conf_TEMP
echo "masternodeaddr=[${gateway}$COUNTER]:$PORT" >> transcendence.conf_TEMP
echo "masternodeprivkey=$PRIVKEY" >> transcendence.conf_TEMP
mv transcendence.conf_TEMP $CONF_DIR/transcendence.conf
echo ""
echo -e "Your ip is ${GREEN}[${gateway}$COUNTER]:$PORT${NC}"
echo "alias ${ALIAS}_status=\"transcendence-cli -datadir=/root/.transcendence_${ALIAS} masternode status\"" >> .bashrc
echo "alias ${ALIAS}_stop=\"systemctl stop transcendenced$ALIAS\"" >> .bashrc
echo "alias ${ALIAS}_start=\"systemctl start transcendenced$ALIAS\"" >> .bashrc
echo "alias ${ALIAS}_config=\"nano /root/.transcendence_${ALIAS}/transcendence.conf\"" >> .bashrc
echo "alias ${ALIAS}_getinfo=\"transcendence-cli -datadir=/root/.transcendence_${ALIAS} getinfo\"" >> .bashrc
echo "alias ${ALIAS}_getpeerinfo=\"transcendence-cli -datadir=/root/.transcendence_${ALIAS} getpeerinfo\"" >> .bashrc
echo "alias ${ALIAS}_resync=\"/root/bin/transcendenced_${ALIAS}.sh -resync\"" >> .bashrc
echo "alias ${ALIAS}_reindex=\"/root/bin/transcendenced_${ALIAS}.sh -reindex\"" >> .bashrc
echo "alias ${ALIAS}_restart=\"systemctl restart transcendenced$ALIAS\"" >> .bashrc
## Config Systemctl
configure_systemd
COUNTER=$((COUNTER+1))
done
fi
echo ""
echo -e "${RED}Please do not set maxconnections lower than 48 or your node may not receive rewards as often.${NC}"
echo ""
echo "Commands:"
echo "${ALIAS}_start"
echo "${ALIAS}_restart"
echo "${ALIAS}_status"
echo "${ALIAS}_stop"
echo "${ALIAS}_config"
echo "${ALIAS}_getinfo"
echo "${ALIAS}_getpeerinfo"
echo "${ALIAS}_resync"
echo "${ALIAS}_reindex"
fi
echo ""
echo "Made by lobo & xispita with the help of all Transcendence team "
echo "lobo's Transcendence Address for donations: GWe4v6A6tLg9pHYEN5MoAsYLTadtefd9o6"
echo "xispita's Transcendence Address for donations: GRDqyK7m9oTsXjUsmiPDStoAfuX1H7eSfh"
echo "Bitcoin Address for donations: 1NqYjVMA5DhuLytt33HYgP5qBajeHLYn4d"
exec bash
exit