-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxit-mn-multisetup_1.sh
178 lines (150 loc) · 6.1 KB
/
xit-mn-multisetup_1.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
#!/bin/bash
# A shell script written to automate the ittrium Masternode Setup Process
#esp yellow could be hard to read for users with a bright terminal background
#others could get only the \033[00;32m output
USECOLOR=FALSE
if [ "$USECOLOR" = "TRUE" ]
then
Green=$(echo '\033[00;32m')
Cyan=$(echo '\033[00;36m')
RED=$(echo '\033[00;31m')
YELLOW=$(echo '\033[00;33m')
fi
#if the directory .ittrium exists skip the initial setup
if [ ! -d ~/.ittrium ]
then
#Upgrading is most of the time a good idea, but if the user isn't in the sudoers list it will fail
#and running as root should be discouraged
echo "${Green}Im Starting to update!"
sudo apt update
echo "${Green}I've Finished updating! Now I need to upgrade."
sudo apt upgrade -y
echo "${Green}I've finished upgrading! Now I need to install dependencies"
sudo apt-get install nano unzip git -y
echo "${Green}I've finished installing dependencies! Now I'll make folders and download the wallet."
wget https://github.com/IttriumCore/ittrium/releases/download/v2.1.0/ittrium-v2.1.0-linux64.tar.gz
tar -xzvf ittrium-v2.1.0-linux64.tar.gz
chmod +x ittriumd
chmod +x ittrium-cli
./ittriumd -daemon
sleep 5
./ittrium-cli stop
echo
echo
echo "${Green}I've finished making folders and downloading the wallet! Now I'll create your ittrium.conf file."
cd ~/.ittrium/
touch ~/.ittrium/ittrium.conf
touch ~/.ittrium/masternode.conf
echo "rpcallowip=127.0.0.1" >> ~/.ittrium/ittrium.conf
# sleep 5
# echo "${Green}Enter an RPC username (It doesn't matter really what it is, just try to make it secure)"
# read username
# /dev/urandom generates better passwords than the usual user input does
username=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w16 | head -n1)
echo "rpcuser=$username" >> ~/.ittrium/ittrium.conf
# echo "${Green}Enter an RPC password(It doesn't matter really what it is, just try to make it secure)"
# read password
# /dev/urandom generates better passwords than the usual user input does
password=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w32 | head -n1)
echo "rpcpassword=$password" >> ~/.ittrium/ittrium.conf
echo "server=1" >> ~/.ittrium/ittrium.conf
echo "listen=1" >> ~/.ittrium/ittrium.conf
echo "staking=1" >> ~/.ittrium/ittrium.conf
echo "port=39993" >> ~/.ittrium/ittrium.conf
echo "masternode=1" >> ~/.ittrium/ittrium.conf
echo "${Green}What is the Global IP of your VPS? I'll put this into your config file for you because I'm so nice."
echo "If you want to use IPV6 enclose the address in [...] like [1b83:123:422d:badb:eef:bad:beef:1234]"
echo "Possible addresses would be:"
#list the IPs for some convenience
echo
ip a|grep 'scope global'
echo
read -p 'IP: ' VPSip
echo
echo "masternodeaddr=$VPSip:39993" >> ~/.ittrium/ittrium.conf
echo "bind=$VPSip:39993" >> ~/.ittrium/ittrium.conf
echo "externalip=$VPSip:39993" >> ~/.ittrium/ittrium.conf
echo "${Green}What is your masternode genkey? I'll put this into your config file."
echo "${Green}(You can get this key by opening your local wallets Debug-console and typing: masternode genkey)"
echo
read -p 'mnprivkey: ' genkey
echo "masternodeprivkey=$genkey" >> ~/.ittrium/ittrium.conf
echo
echo "${YELLOW}Okay, it looks like you are all set. Let's startup the daemon!"
echo
cd ~/
./ittriumd -daemon
exit 0
else
#the initial setup was already done ask if a new MN with the same IP should be generated
echo "The initial setup was already done."
echo "${Green}Do you want to setup a new MasterNode on the same IP?"
read -p '(y)es or (n)o? ' answer
if [ "$answer" != "${answer#[Nn]}" ] ;then
#no exit
exit 0
else
#yes
echo
echo "Generating a new datadir for the new MasterNode."
#count the number of already installed .ittrium directorys
declare -i nnodes
nnodes=$(ls 2>/dev/null -d .ittrium* | wc -l)
#stop the aerium-daemon before copying the datadir
if [ -e ~/.ittrium/ittriumd.pid ]
then
./ittrium-cli stop
sleep 1
restart=TRUE
fi
nnodes=$nnodes+1
newdirname=(.ittrium$nnodes)
cp -r ~/.ittrium ~/$newdirname
#restart the ittriumd
if [ "$restart" = "TRUE" ]
then
./ittriumd -daemon
fi
cd $newdirname
mv ittrium.conf ittrium0.conf
touch ittrium.conf
declare -i rpcp
rpcp=50369+$nnodes
echo "rpcallowip=127.0.0.1" >> ittrium.conf
echo "bind=127.0.0.$nnodes" >> ittrium.conf
username=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w32 | head -n1)
echo "rpcuser=$username" >> ittrium.conf
password=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w32 | head -n1)
echo "rpcpassword=$password" >> ittrium.conf
echo "rpcport=$rpcp" >> ittrium.conf
echo "server=1" >> ittrium.conf
echo "listen=1" >> ittrium.conf
echo "staking=1" >> ittrium.conf
echo "masternode=1" >> ittrium.conf
eip=$(grep externalip ittrium0.conf)
echo $eip >> ittrium.conf
echo
echo "${Green}What is your masternode genkey? I'll put this into your config file."
echo "${Green}(You can get this key by opening your local wallets Debug-console and typing: masternode genkey)"
read -p 'mnprivkey: ' genkey
echo "masternodeprivkey=$genkey" >> ittrium.conf
rm ittrium0.conf
cd ~/
#create two scripts for an easy startup and access to the new MasterNode
#for about 2-5 MNs this approach should work
#for more i would suggest to create a $HOME/bin directory and copy all scripts there (ubuntu would have it already in its user $PATH)
#and add a script which takes the MN-number as argument, not one script for every MN.
touch "ittriumd$nnodes"
echo "#!/bin/bash" >> "ittriumd$nnodes"
echo "~/ittriumd -datadir=$HOME/.ittrium$nnodes -daemon" >> "ittriumd$nnodes"
chmod 770 "ittriumd$nnodes"
touch "ittrium$nnodes-cli"
echo "#!/bin/bash" >> "ittriumd$nnodes-cli"
echo "~/ittrium-cli -datadir=$HOME/.ittrium$nnodes -rpcport=$rpcp \$@" >> "ittrium$nnodes-cli"
chmod 770 "ittrium$nnodes-cli"
echo
echo "You can start your new MasterNode daemon with ./ittriumd$nnodes."
echo "To get its status use: ./ittrium$nnodes-cli masternode status."
echo "To stop the daemon use: ./ittrium$nnodes-cli stop."
fi
fi