-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxit-mn-update.sh
133 lines (110 loc) · 3.55 KB
/
xit-mn-update.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
#!/bin/bash
TARBALLURL='https://github.com/IttriumCore/ittrium/releases/download/untagged-8f6b9e1321cbc31580e1/ittrium-v2.0.2-linux64.tar.gz'
TARBALLNAME='ittrium-v2.0.2-linux64.tar.gz'
XITVERSION='v2.0.2'
USER=$(ps -o user= -p "$(pgrep ittriumd)")
USERHOME=$(eval echo "~$USER")
function showbanner() {
echo "This script will update your masternode to version $XITVERSION"
read -rp "Press Ctrl-C to abort or any other key to continue. " -n1 -s
clear
}
function permission() {
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root."
exit 1
fi
}
function download() {
echo "Downloading new version..."
wget "$TARBALLURL"
}
function close() {
echo "Shutting down masternode..."
if [ -e /etc/systemd/system/ittrium.service ]; then
systemctl stop ittrium.service
else
su -c "ittrium-cli stop" "$USER"
fi
}
function update() {
echo "Installing Ittrium $XITVERSION..."
rm /usr/local/bin/ittriumd /usr/local/bin/ittrium-cli /usr/local/bin/ittrium-tx /usr/local/bin/ittrium-qt
tar -xzvf "$TARBALLNAME" -C /usr/local/bin
rm "$TARBALLNAME"
if [ -e /usr/bin/ittriumd ];then rm -rf /usr/bin/ittriumd; fi
if [ -e /usr/bin/ittrium-cli ];then rm -rf /usr/bin/ittrium-cli; fi
if [ -e /usr/bin/ittrium-tx ];then rm -rf /usr/bin/ittrium-tx; fi
if [ -e /usr/bin/ittrium-qt ];then rm -rf /usr/bin/ittrium-qt; fi
# Add Fail2Ban memory hack if needed
if ! grep -q "ulimit -s 256" /etc/default/fail2ban; then
echo "ulimit -s 256" | sudo tee -a /etc/default/fail2ban
systemctl restart fail2ban
fi
}
function restart() {
echo "Restarting Ittrium daemon..."
if [ -e /etc/systemd/system/ittrium.service ]; then
systemctl disable ittrium.service
rm /etc/systemd/system/ittrium.service
fi
}
function check() {
cat > /etc/systemd/system/ittrium.service << EOL
[Unit]
Description=Ittriums's distributed currency daemon
After=network.target
[Service]
Type=forking
User=${USER}
WorkingDirectory=${USERHOME}
ExecStart=/usr/local/bin/ittriumd -conf=${USERHOME}/.ittrium/ittrium.conf -datadir=${USERHOME}/.ittrium
ExecStop=/usr/local/bin/ittrium-cli -conf=${USERHOME}/.ittrium/ittrium.conf -datadir=${USERHOME}/.ittrium stop
Restart=on-failure
RestartSec=1m
StartLimitIntervalSec=5m
StartLimitInterval=5m
StartLimitBurst=3
[Install]
WantedBy=multi-user.target
EOL
sudo systemctl enable ittrium.service
sudo systemctl start ittrium.service
sleep 10
clear
if ! systemctl status ittrium.service | grep -q "active (running)"; then
echo "ERROR: Failed to start ittriumd. Please contact support."
exit
fi
}
##### Main #####
clear
showbanner
permission
download
close
update
restart
check
echo "Waiting for wallet to load..."
until su -c "ittrium-cli getinfo 2>/dev/null | grep -q \"version\"" "$USER"; do
sleep 1;
echo "Your masternode is syncing. Please wait for this process to finish."
echo "This can take up to a few hours. Do not close this window."
echo ""
until su -c "ittrium-cli mnsync status 2>/dev/null | grep '\"IsBlockchainSynced\": true' > /dev/null" "$USER"; do
echo -ne "Current block: $(su -c "ittrium-cli getblockcount" "$USER")\\r"
sleep 1
done
clear
cat << EOL
Now, you need to start your masternode. If you haven't already, please add this
node to your masternode.conf now, restart and unlock your desktop wallet, go to
the Masternodes tab, select your new node and click "Start Alias."
EOL
read -rp "Press Enter to continue after you've done that. " -n1 -s
clear
su -c "ittrium-cli masternode status" "$USER"
cat << EOL
Masternode update completed.
EOL