-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhpb-install
186 lines (159 loc) · 6.9 KB
/
hpb-install
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
#!/bin/bash
if [[ $EUID -eq 0 ]]
then
read -r -p "This script will install hpb in /opt/hpb-bin, and delete any existing installation. Make sure UDP/TCP 30303 and 30403 are forwarded to the server. Are you sure you want to continue? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]
then
# LATESTVERSION=`curl -s https://api.github.com/repos/hpb-project/go-hpb/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")'`
KERNELVERSION=`uname -r`
# Check that user is running Ubuntu 16.04
REQUIREDVERSION="1604"
RUNNINGVERSION=$( lsb_release -r | awk '{ print $2 }' | sed 's/[.]//' )
if [ "$RUNNINGVERSION" == "$REQUIREDVERSION" ]
then
echo -n "Enter your KEYSTORE and press [ENTER]: "
read KEYSTORE
if [[ -z "$KEYSTORE" ]]; then
printf '%s\n' "No input for Keystore entered"
exit 1
fi
echo -n "Enter your WALLET ADDRESS and press [ENTER]: "
read WALLET
if [[ -z "$WALLET" ]]; then
printf '%s\n' "No input for Wallet Address entered"
exit 1
fi
echo -n "Enter your WALLET PASSWORD and press [ENTER]: "
read WALLETPASSWORD
if [[ -z "$WALLETPASSWORD" ]]; then
printf '%s\n' "No input for Wallet Password entered"
exit 1
fi
# Install necessary tools
echo "Installing required tools (build-essential, git, golang-1.9, unzip and ukuu)"
add-apt-repository -y ppa:teejee2008/ppa
apt-get update
apt-get install -y build-essential git golang-1.9 unzip ukuu
apt-get upgrade -y
if [ "$KERNELVERSION" != "4.18.10-041810-generic" ]
then
echo "Installing Kernel 4.18.10"
ukuu --install v4.18.10
fi
echo "Checking for existing installation"
if [ -d /root/hpb-temp ]
then
rm -rf /root/hpb-temp
fi
if [ -d /opt/ghpb-bin ]
then
rm -rf /opt/ghpb-bin
fi
if [ -f /etc/systemd/system/[email protected] ]
then
systemctl stop [email protected]
systemctl disable [email protected]
rm -rf /etc/systemd/system/[email protected]
fi
echo "Killing any currently running ghpb"
killall -9 ghpb
killall -9 iperf3
echo "Creating directories"
mkdir /root/hpb-temp
mkdir /opt/ghpb-bin
echo "Entering /root/hpb-temp/"
cd /root/hpb-temp
NTPVERSION=`ntpdate -v |cut -d " " -f6 | cut -d "@" -f1`
if [ "$NTPVERSION" != "4.2.8p12" ]
then
echo "Downloading, installing and running NTP"
wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p12.tar.gz
if [ `md5sum ntp-4.2.8p12.tar.gz | cut -d " " -f1` == "1522d66574bae14abb2622746dad2bdc" ]
then
tar zxf ntp-4.2.8p12.tar.gz
cd ntp-4.2.8p12/
./configure && make -j8 && make install
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
ntpdate cn.pool.ntp.org
hwclock --systohc
else
echo "MD5 Sums for NTP does not match! Exiting installer to avoid potential security breach."
exit 1
fi
fi
if grep -Fxq "export GOPATH=/usr/share/go-1.9" /etc/profile
then
echo "GO already configured in /etc/profile, skipping."
else
echo "Setting up GO Paths"
echo 'export GOPATH=/usr/share/go-1.9' >> /etc/profile
echo 'export GOROOT=/usr/lib/go-1.9' >> /etc/profile
echo 'export PATH=$GOROOT/bin:$GOPATH/bin:$PATH' >> /etc/profile
echo 'export GOPATH=/usr/share/go-1.9' >> /etc/bash.bashrc
echo 'export GOROOT=/usr/lib/go-1.9' >> /etc/bash.bashrc
echo 'export PATH=$GOROOT/bin:$GOPATH/bin:$PATH' >> /etc/bash.bashrc
source /etc/profile
source /etc/bash.bashrc
fi
# echo "Downloading HPB $LATESTVERSION"
# wget https://github.com/hpb-project/go-hpb/archive/$LATESTVERSION.zip
# unzip $LATESTVERSION.zip
# cd go-hpb-$LATESTVERSION
echo "Downloading HPB source code"
git clone https://github.com/hpb-project/go-hpb
cd go-hpb
echo "Building release"
make all
cp build/bin/* /opt/ghpb-bin
echo "Init the genesis block"
cd /opt/ghpb-bin
wget https://raw.githubusercontent.com/hpb-project/hpb-release/master/config/gensis.json
./ghpb --datadir node/data init gensis.json
echo "Setting up keystore"
mkdir /opt/ghpb-bin/node/data/keystore
echo $KEYSTORE > /opt/ghpb-bin/node/data/keystore/keystore
echo "Setting up wallet password"
echo $WALLETPASSWORD > /opt/ghpb-bin/pwd
echo "Creating ghpb service file"
cat <<EOF > /etc/systemd/system/[email protected]
[Unit]
Description=HPB
Requires=network.target
[Service]
Type=simple
User=%I
ExecStart=/opt/ghpb-bin/ghpb --datadir /opt/ghpb-bin/node/data --networkid 100 --port 3004 --unlock $WALLET --password /opt/ghpb-bin/pwd --verbosity 3 --rpc --rpcport 8545 --rpcapi hpb,web3,admin,txpool,debug,personal,net,miner,prometheus --mine
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
echo "Enabling ghpb service to start at boot"
systemctl enable [email protected]
echo "Clearing temp directories"
rm -rf /root/hpb-temp
if [ "$KERNELVERSION" != "4.18.10-041810-generic" ]
then
# Show information message to user
echo "After reboot in 10 seconds, you can access the console by typing: /opt/ghpb-bin/ghpb attach http://127.0.0.1:8545 \n
In the console:\n
Check your peers by typing: net \n
Verify you are mining by typing: hpb.mining \n
Start mining if it's not doing so by typing miner.start()"
sleep 10
# Reboot machine
reboot
else
echo "Starting GHPB"
systemctl start [email protected]
sleep 3
echo "Type the following to attach to the ghpb console: /opt/ghpb-bin/ghpb attach http://127.0.0.1:8545"
fi
else
echo "You must run Ubuntu 16.04 "
fi
else
echo "Exiting".
fi
else
echo "You must be root to run this"
fi