-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhpb-upgrade
88 lines (73 loc) · 2.87 KB
/
hpb-upgrade
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
#!/bin/bash
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")
if [[ $EUID -eq 0 ]]
then
if [ $LOCAL = $REMOTE ]; then
echo "HPB Tools Up-to-date!"
elif [ $LOCAL = $BASE ]; then
read -r -p "There is a new version of hpb-tools available, update to it? [Y/n] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
git pull
fi
fi
echo "This script assumes you have installed ghpb in /opt/ghpb-bin and that you run it as a service (see https://github.com/Nicemanss/hpb-tools/blob/master/hpb-install )"
echo "To install a specific version, add the version at the end. Example: bash ./hpb-upgrade 1.0.2.3"
read -r -p "Are you sure you want to continue? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
if [ -d /opt/ghpb-bin ] && [ -f /etc/systemd/system/[email protected] ]
then
echo "Stopping ghpb service"
systemctl stop [email protected]
killall -9 ghpb
killall -9 iperf3
echo "Setting up temp directories"
if [ -d /root/hpb-temp ]
then
rm -rf /root/hpb-temp
fi
mkdir /root/hpb-temp
cd /root/hpb-temp
if [ -n "$1" ]; then
echo "Downloading version $1"
wget https://github.com/hpb-project/hpb-release/raw/master/bin/ghpb-v$1.tar.gz
tar xvzf ghpb-v$1.tar.gz
cp ghpb-v$1/* /opt/ghpb-bin/
else
echo "Building with latest commit."
echo "Downloading HPB source code"
git clone https://github.com/hpb-project/go-hpb
cd go-hpb
echo "Building release"
make all
echo "Copying binaries"
cp build/bin/* /opt/ghpb-bin/
fi
echo "Backing up keystore data"
mv /opt/ghpb-bin/node/data/keystore /opt/ghpb-bin/
echo "Clearing node data"
rm -rf /opt/ghpb-bin/node
echo "Initializing genesis block"
cd /opt/ghpb-bin/
wget -q https://raw.githubusercontent.com/hpb-project/hpb-release/master/config/gensis.json -O /opt/ghpb-bin/gensis.json
./ghpb --datadir node/data init gensis.json
echo "Restoring keystore data"
mv /opt/ghpb-bin/keystore /opt/ghpb-bin/node/data/
echo "Starting ghpb service"
systemctl start [email protected]
echo "Node started. Run /opt/ghpb-bin/ghpb attach http://127.0.0.1:8545 to attach to console"
echo "Cleaning temp directories"
rm -rf /root/hpb-temp
else
echo "/opt/ghpb-bin or /etc/systemd/system/[email protected] does not exist, exiting."
fi
else
echo "Exiting"
fi
else
echo "You must be root to run this"
fi