forked from CommerciumBlockchain/masternode-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
part2_linux_vps_setup.sh
192 lines (146 loc) · 5.86 KB
/
part2_linux_vps_setup.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
#!/bin/bash
# Automatic Commercium Masternodes setup (part 2. VPS masternode setup)
# Dependencies: wget
# (c) Commercium. 2020
version="0.4"
COMMERCIUMCONFIGDIR=~/.commercium
COMMERCIUMDAEMONDIR=~/commercium-v3
COMMERCIUMCONFIG=$COMMERCIUMCONFIGDIR/commercium.conf
COMMERCIUMMASTERNODECONFIG=$COMMERCIUMCONFIGDIR/cmasternode.conf
clear
printf "Before you begin. Follow instuction about how to setup masternodes at your local wallet (part 1). You can find this documentation here:\n\n https://github.com/CommerciumBlockchain/masternode-scripts\n\n"
printf "Confirm that you are alredy have NODEKEY to setup your VPS masternode.\n"
while true; do
read -p "Do you wish to install Commercium daemon now? " yn
case $yn in
[Yy]* ) echo ""; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
# libgomp1 check
GOMPAVAILABLE=`ldconfig -p | grep libgomp`
if [ -z "$GOMPAVAILABLE" ];
then
echo "[-] libgomp1 not exists at your system."
echo "[!] Commercium daemon depends on libgomp1 !"
# not root/non root mode
if [ "$EUID" -ne 0 ];
then
echo
echo "[!] NON ROOT MODE DETECTED! You are running this script at user mode. It's okey! Right now open new terminal window and install libgomp1 MANNUALLY AS ROOT with following command:"
echo
echo "sudo apt-get libgomp1 -y"
echo
read -p "Please, confirm! Manual installation done? Press any key to confirm and continue"
echo
else
echo "[+] Trying to install libgomp1 automatically"
apt-get install libgomp1 -y
fi
fi
# end libgomp install
ARCHIVENAME=commercium-v3.tar.gz
# install commercium daemon
if [ ! -e $HOME/commercium-v3.tar.gz ];
then
printf "Now we will download and install Commercoum deamon to current user home directory: $HOME!\n"
echo
cd $HOME
wget https://github.com/CommerciumBlockchain/Commercium/releases/download/v3.0.0/commercium-v3.tar.gz
fi
if [ ! -e $HOME/$ARCHIVENAME ];
then
echo "Error downloading commercium wallet linux archive."
exit
fi
echo "[+] Commercium successfully downloaded and stored at user home: $HOME "
if [ ! -e $HOME/commercium-fetch-params ];
then
printf "Now download fetch-params script to: $HOME!\n"
echo
cd $HOME
wget https://github.com/CommerciumBlockchain/Commercium/releases/download/v3.0.0/commercium-fetch-params
fi
if [ ! -e $HOME/commercium-fetch-params ];
then
echo "Error downloading fetchparams."
exit
fi
echo "[+] Fetchparams downloaded and stored at: $HOME "
# extract
echo "[+] extracting files to: $COMMERCIUMCONFIGDIR\n"
tar zxvf $ARCHIVENAME
# Config & dir
if [ ! -d "$COMMERCIUMCONFIGDIR" ]; then
mkdir $COMMERCIUMCONFIGDIR
fi
echo "[+] writing commercium.conf config file: $COMMERCIUMCONFIG"
if [ ! -e $COMMERCIUMCONFIG ];
then
USERNAMERAND=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo ''`
PASSWORDRAND=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo ''`
read -p "Now please enter/copy&paste your NODEKEY from Part 1 setup instructions: " NODEKEY
cat <<EOF > $COMMERCIUMCONFIG
txindex=1
daemon=1
rpcuser=$USERNAMERAND
rpcpassword=$PASSWORDRAND
masternode=1
masternodeprivkey=$NODEKEY
EOF
else
echo
read -n1 -r -p 'Commercium config file already exists.. Press any key to open it in nano editor. Edit it manually or Ctrl-X at next step to exit if config was successfully writen before' key
nano $COMMERCIUMCONFIG
fi
# Fetch Params
echo
if [ ! -e $HOME/sapling-spend.params ] || [ ! -e $HOME/sprout-proving.key ] || [ ! -e $HOME/sapling-output.params ] || [ ! -e $HOME/sprout-groth16.params ];
then
#$COMMERCIUMDAEMONDIR/fetch-params.sh
bash $HOME/commercium-fetch-params
fi
# Start commercium daemon
$COMMERCIUMDAEMONDIR/commerciumd
#
# check daemon running by user confirmation?
#
read -n1 -r -p 'Lets make sure no errors appear on the screen above and Commercium daemon running... Press any key to confirm or exit with Ctrl-C (solve this issue manually and then restart the script)' key
# Wallet Sync
currentblock="$($COMMERCIUMDAEMONDIR/commercium-cli getblockcount)"
highestblock="$(wget -nv -qO - https://api.commercium.net/api/getblockcount)"
while [ "$highestblock" != "$currentblock" ]
do
clear
highestblock="$(wget -nv -qO - https://api.commercium.net/api/getblockcount)"
currentblock="$($COMMERCIUMDAEMONDIR/commercium-cli getblockcount)"
echo "Comparing block heights to ensure server is fully synced";
echo "Highest: $highestblock";echo "Currently at: $currentblock";
echo "Checking again in 60 seconds... The install will continue once it's synced.";echo
echo "Last 6 lines of the log for error checking...";
echo "===============";
tail -6 ~/.commercium/debug.log
echo "===============";
echo "Network unreachable errors can be normal. Just ensure the current block height is rising over time...";
sleep 20
done
# Sync done
read -n1 -r -p 'Your blockchain is now synced... Press any key to continue' key
# Finishing touches
echo "Now need to activate masternode."
printf "Following command at LOCAL wallet will activate your mastermode: commercium-cli.exe startmasternode all missing\n\n"
read -n1 -r -p 'Open your local wallet, go to command line shell and activate your masternode Press any key to continue' key
read -n1 -r -p 'Wait a few minutes for your masternode to start... Press any key to continue' key
ans=`$COMMERCIUMDAEMONDIR/commercium-cli masternode debug`
if [[ $ans == *"successfully"* ]]; then
echo "[+] Masternode successfully started..."
echo "[+] Congratulations!"
exit
else
echo "[-] Masternode NOT started..."
echo "[-] Something goes wrong. Maybe request help at Commercium discord or ..."
printf "[-] Check your masternode status with following command manually and try to fix it: \ncommercium-cli masternode debug\n"
printf "[-] Correct response from this command is: \"Masternode successfully started\". Then you’re finished.\n"
fi
exit