-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall.sh
202 lines (168 loc) · 6.22 KB
/
install.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
#!/bin/bash
################################################
# Script by François YoYae GINESTE - 03/04/2018
# For monoeciCore V0.12.2.3
# https://monoeci.io/tutorial-masternode/
################################################
LOG_FILE=/tmp/install.log
decho () {
echo `date +"%H:%M:%S"` $1
echo `date +"%H:%M:%S"` $1 >> $LOG_FILE
}
error() {
local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
echo "Error on or near line ${parent_lineno}; exiting with status ${code}"
exit "${code}"
}
trap 'error ${LINENO}' ERR
clear
cat <<'FIG'
__ __ _
| \/ | ___ _ __ ___ ___ ___(_)
| |\/| |/ _ \| '_ \ / _ \ / _ \/ __| |
| | | | (_) | | | | (_) | __/ (__| |
|_| |_|\___/|_| |_|\___/ \___|\___|_|
FIG
# Check for systemd
systemctl --version >/dev/null 2>&1 || { decho "systemd is required. Are you using Ubuntu 16.04?" >&2; exit 1; }
# Check if executed as root user
if [[ $EUID -ne 0 ]]; then
echo -e "This script has to be run as \033[1mroot\033[0m user"
exit 1
fi
#print variable on a screen
decho "Make sure you double check before hitting enter !"
read -e -p "User that will run Monoeci core /!\ case sensitive /!\ : " whoami
if [[ "$whoami" == "" ]]; then
decho "WARNING: No user entered, exiting !!!"
exit 3
fi
if [[ "$whoami" == "root" ]]; then
decho "WARNING: user root entered? It is recommended to use a non-root user, exiting !!!"
exit 3
fi
read -e -p "Server IP Address : " ip
if [[ "$ip" == "" ]]; then
decho "WARNING: No IP entered, exiting !!!"
exit 3
fi
read -e -p "Masternode Private Key (e.g. 3bsTPBdDf3USqoAAnHmfmSyHqZ4fACkUDNezE7ZVKQyxEKiy8MK # THE KEY YOU GENERATED EARLIER) : " key
if [[ "$key" == "" ]]; then
decho "WARNING: No masternode private key entered, exiting !!!"
exit 3
fi
read -e -p "(Optional) Install Fail2ban? (Recommended) [Y/n] : " install_fail2ban
read -e -p "(Optional) Install UFW and configure ports? (Recommended) [Y/n] : " UFW
decho "Updating system and installing required packages."
# update package and upgrade Ubuntu
apt-get -y update >> $LOG_FILE 2>&1
# Add Berkely PPA
decho "Installing bitcoin PPA..."
apt-get -y install software-properties-common >> $LOG_FILE 2>&1
apt-add-repository -y ppa:bitcoin/bitcoin >> $LOG_FILE 2>&1
apt-get -y update >> $LOG_FILE 2>&1
# Install required packages
decho "Installing base packages and dependencies..."
apt-get -y install sudo >> $LOG_FILE 2>&1
apt-get -y install wget >> $LOG_FILE 2>&1
apt-get -y install git >> $LOG_FILE 2>&1
apt-get -y install unzip >> $LOG_FILE 2>&1
apt-get -y install virtualenv >> $LOG_FILE 2>&1
apt-get -y install python-virtualenv >> $LOG_FILE 2>&1
apt-get -y install pwgen >> $LOG_FILE 2>&1
if [[ ("$install_fail2ban" == "y" || "$install_fail2ban" == "Y" || "$install_fail2ban" == "") ]]; then
decho "Optional installs : fail2ban"
cd ~
apt-get -y install fail2ban >> $LOG_FILE 2>&1
systemctl enable fail2ban >> $LOG_FILE 2>&1
systemctl start fail2ban >> $LOG_FILE 2>&1
fi
if [[ ("$UFW" == "y" || "$UFW" == "Y" || "$UFW" == "") ]]; then
decho "Optional installs : ufw"
apt-get -y install ufw >> $LOG_FILE 2>&1
ufw allow ssh/tcp >> $LOG_FILE 2>&1
ufw allow sftp/tcp >> $LOG_FILE 2>&1
ufw allow 24156/tcp >> $LOG_FILE 2>&1
ufw allow 24157/tcp >> $LOG_FILE 2>&1
ufw default deny incoming >> $LOG_FILE 2>&1
ufw default allow outgoing >> $LOG_FILE 2>&1
ufw logging on >> $LOG_FILE 2>&1
ufw --force enable >> $LOG_FILE 2>&1
fi
decho "Create user $whoami (if necessary)"
#desactivate trap only for this command
trap '' ERR
getent passwd $whoami > /dev/null 2&>1
if [ $? -ne 0 ]; then
trap 'error ${LINENO}' ERR
adduser --disabled-password --gecos "" $whoami >> $LOG_FILE 2>&1
else
trap 'error ${LINENO}' ERR
fi
#Create monoeci.conf
decho "Setting up monoeci Core"
#Generating Random Passwords
user=`pwgen -s 16 1`
password=`pwgen -s 64 1`
echo 'Creating monoeci.conf...'
mkdir -p /home/$whoami/.monoeciCore/
cat << EOF > /home/$whoami/.monoeciCore/monoeci.conf
rpcuser=$user
rpcpassword=$password
rpcallowip=127.0.0.1
listen=1
server=1
daemon=1
maxconnections=24
masternode=1
masternodeprivkey=$key
externalip=$ip
EOF
chown -R $whoami:$whoami /home/$whoami
#Install Moneoci Daemon
echo 'Downloading daemon...'
cd
wget https://github.com/monacocoin-net/monoeci-core/releases/download/v0.12.2.3/monoeciCore-0.12.2.3-linux64.tar.gz >> $LOG_FILE 2>&1
sudo tar xvf monoeciCore-0.12.2.3-linux64.tar.gz >> $LOG_FILE 2>&1
sudo cp monoecid /usr/bin/ >> $LOG_FILE 2>&1
sudo cp monoeci-cli /usr/bin/ >> $LOG_FILE 2>&1
sudo cp monoeci-tx /usr/bin/ >> $LOG_FILE 2>&1
rm monoeciCore-0.12.2.3-linux64.tar.gz monoecid monoeci-cli monoeci-tx >> $LOG_FILE 2>&1
#Run monoecid as selected user
sudo -H -u $whoami bash -c 'monoecid' >> $LOG_FILE 2>&1
echo 'Monoeci Core prepared and lunched'
sleep 10
#Setting up coin
decho "Setting up sentinel"
echo 'Downloading sentinel...'
#Install Sentinel
git clone https://github.com/monacocoin-net/sentinel.git /home/$whoami/sentinel >> $LOG_FILE 2>&1
chown -R $whoami:$whoami /home/$whoami/sentinel >> $LOG_FILE 2>&1
cd /home/$whoami/sentinel
echo 'Setting up dependencies...'
sudo -H -u $whoami bash -c 'virtualenv ./venv' >> $LOG_FILE 2>&1
sudo -H -u $whoami bash -c './venv/bin/pip install -r requirements.txt' >> $LOG_FILE 2>&1
#Deploy script to keep daemon alive
cat << EOF > /home/$whoami/monoecidkeepalive.sh
until monoecid; do
echo "Monoecid crashed with error $?. Restarting.." >&2
sleep 1
done
EOF
chmod +x /home/$whoami/monoecidkeepalive.sh
chown $whoami:$whoami /home/$whoami/monoecidkeepalive.sh
#Setup crontab
echo "@reboot sleep 30 && /home/$whoami/monoecidkeepalive.sh" >> newCrontab
echo "* * * * * cd /home/$whoami/sentinel && ./venv/bin/python bin/sentinel.py >/dev/null 2>&1" >> newCrontab
crontab -u $whoami newCrontab >> $LOG_FILE 2>&1
rm newCrontab >> $LOG_FILE 2>&1
decho "Starting your masternode"
echo ""
echo "Now, you need to finally start your masternode in the following order: "
echo "1- Go to your windows/mac wallet and modify masternode.conf as required, then restart and from the Masternode tab"
echo "2- Select the newly created masternode and then click on start-alias."
echo "3- Once completed, please return to VPS and wait for the wallet to be synced."
echo "4- Then you can try the command 'monoeci-cli masternode status' to get the masternode status."
su $whoami