forked from bulwark-crypto/Bulwark-MN-Install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbulwarkupdate
executable file
·87 lines (71 loc) · 2.94 KB
/
bulwarkupdate
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
#!/bin/bash
TARBALLURL=$(curl -s https://api.github.com/repos/bulwark-crypto/bulwark/releases/latest | grep browser_download_url | grep -e "bulwark-node.*linux64" | cut -d '"' -f 4)
TARBALLNAME=$(curl -s https://api.github.com/repos/bulwark-crypto/bulwark/releases/latest | grep browser_download_url | grep -e "bulwark-node.*linux64" | cut -d '"' -f 4 | cut -d "/" -f 9)
BWKVERSION=$(curl -s https://api.github.com/repos/bulwark-crypto/bulwark/releases/latest | grep browser_download_url | grep -e "bulwark-node.*linux64" | cut -d '"' -f 4 | cut -d "/" -f 8)
LOCALVERSION=$(bulwark-cli --version | cut -d " " -f 6)
REMOTEVERSION=$(curl -s https://api.github.com/repos/bulwark-crypto/bulwark/releases/latest | jq -r ".tag_name")
if [[ "$LOCALVERSION" = "$REMOTEVERSION" ]]; then
echo "No update necessary."
exit 0
fi
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root."
exit 1
fi
USER=$(ps -o user= -p "$(pgrep bulwarkd)")
USERHOME=$(eval echo "~$USER")
echo "Downloading new version..."
wget "$TARBALLURL"
echo "Shutting down masternode..."
if [ -e /etc/systemd/system/bulwarkd.service ]; then
systemctl stop bulwarkd
else
su -c "bulwark-cli stop" "$USER"
fi
echo "Installing Bulwark $BWKVERSION..."
rm /usr/local/bin/bulwarkd /usr/local/bin/bulwark-cli
tar -xzvf "$TARBALLNAME" -C /usr/local/bin
rm "$TARBALLNAME"
if [ -e /usr/bin/bulwarkd ];then rm -rf /usr/bin/bulwarkd; fi
if [ -e /usr/bin/bulwark-cli ];then rm -rf /usr/bin/bulwark-cli; fi
if [ -e /usr/bin/bulwark-tx ];then rm -rf /usr/bin/bulwark-tx; fi
# Remove addnodes from bulwark.conf
sed -i '/^addnode/d' "$USERHOME/.bulwark/bulwark.conf"
# 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
echo "Restarting Bulwark daemon..."
if [ -e /etc/systemd/system/bulwarkd.service ]; then
systemctl disable bulwarkd
rm /etc/systemd/system/bulwarkd.service
fi
cat > /etc/systemd/system/bulwarkd.service << EOL
[Unit]
Description=Bulwarks's distributed currency daemon
After=network-online.target
[Service]
Type=forking
User=${USER}
WorkingDirectory=${USERHOME}
ExecStart=/usr/local/bin/bulwarkd -conf=${USERHOME}/.bulwark/bulwark.conf -datadir=${USERHOME}/.bulwark
ExecStop=/usr/local/bin/bulwark-cli -conf=${USERHOME}/.bulwark/bulwark.conf -datadir=${USERHOME}/.bulwark stop
Restart=on-failure
RestartSec=1m
StartLimitIntervalSec=5m
StartLimitInterval=5m
StartLimitBurst=3
[Install]
WantedBy=multi-user.target
EOL
sudo systemctl enable bulwarkd
sudo systemctl start bulwarkd
rm -f /usr/local/bin/bulwarkupdate
curl -o /usr/local/bin/bulwarkupdate https://raw.githubusercontent.com/bulwark-crypto/Bulwark-MN-Install/master/bulwarkupdate
chmod a+x /usr/local/bin/bulwarkupdate
if ! systemctl status bulwarkd | grep -q "active (running)"; then
echo "ERROR: Failed to start bulwarkd. Please contact support."
exit
fi
echo "Masternode is syncing. Masternode update completed."