-
Notifications
You must be signed in to change notification settings - Fork 8
/
bor.sh
executable file
·225 lines (200 loc) · 6.81 KB
/
bor.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
{ # Prevent execution if this script was only partially downloaded
set -e
oops() {
echo "$0:" "$@" >&2
exit 1
}
umask 0022
tmpDir="$(mktemp -d -t bor-temp-dir-XXXXXXXXXXX || \
oops "Can't create temporary directory for downloading files")"
cleanup() {
rm -rf "$tmpDir"
}
trap cleanup EXIT INT QUIT TERM
require_util() {
command -v "$1" > /dev/null 2>&1 ||
oops "you do not have '$1' installed, which I need to $2"
}
version="0.3.0"
network="mainnet"
nodetype="sentry"
# Help function -h
helpFunction()
{
echo ""
echo "Usage: $0 [version [network [nodetype]]]"
echo -e "\tversion: Version of Heimdall to install. Default: $version"
echo -e "\tnetwork: Network to install. Default: $network"
echo -e "\tnodetype: Type of node configuration to install. Default: $nodetype"
exit 1 # Exit script after printing help
}
while getopts ":h" option; do
case $option in
h) # display Help
helpFunction
exit;;
\?) # Invalid option
echo "Error: Invalid option"
exit;;
esac
done
if [ ! -z "$1" ]; then
version="$1"
if [ "${version:0:1}" = "v" ]; then
version=${version:1}
fi
fi
if [ ! -z "$2" ]; then
if [ "$2" = "mainnet" ] || [ "$2" = "amoy" ]; then
network="$2"
else
echo "Invalid network: $2, choose from 'mainnet' or 'amoy'"
exit 1
fi
fi
if [ ! -z "$3" ]; then
if [ "$3" = "sentry" ] || [ "$3" = "pbss-$2-sentry" ] || [ "$3" = "validator" ] || [ "$3" = "pbss-$2-validator" ] || [ "$3" = "archive" ] || [ "$3" = "bootnode" ]; then
nodetype="$3"
else
echo "Invalid node type: $3, choose from 'sentry', 'pbss-$2-sentry', 'validator', 'pbss-$2-validator', 'archive', or 'bootnode'"
exit 1
fi
fi
if [[ $version > "0.3" ]]; then
tag=v${version}
profileInfo=${network}-${nodetype}-config_v${version}
profileInforpm=${network}-${nodetype}-config-v${version}
else
echo "Version is less than 0.3, ignoring network and node type"
tag=${version}
fi
baseUrl="https://github.com/maticnetwork/bor/releases/download/v${version}"
echo $baseUrl
case "$(uname -s).$(uname -m)" in
Linux.x86_64)
if command -v dpkg &> /dev/null; then
type="deb"
if [[ $version > "0.3" ]]; then
binary="bor-${tag}-amd64.deb"
profile="bor-${profileInfo}-all.deb"
else
binary="bor_${tag}_linux_amd64.deb"
fi
elif command -v rpm &> /dev/null; then
type="rpm"
if [[ $version > "0.3" ]]; then
binary="bor-${tag}.x86_64.rpm"
profile="bor-${profileInforpm}.noarch.rpm"
else
binary="bor_${tag}_linux_amd64.rpm"
fi
elif command -v apk &> /dev/null; then
if [[ $version > "0.3" ]]; then
oops "sorry, there is no binary distribution for your platform"
fi
type="apk"
binary="bor_${tag}_linux_amd64.apk"
else
if [[ $version > "0.3" ]]; then
oops "sorry, there is no binary distribution for your platform"
fi
type="tar.gz"
binary="bor_${tag}_linux_amd64.tar.gz"
fi
;;
Linux.aarch64)
if command -v dpkg &> /dev/null; then
type="deb"
if [[ $version > "0.3" ]]; then
binary="bor-${tag}-arm64.deb"
profile="bor-${profileInfo}-all.deb"
else
binary="bor_${tag}_linux_arm64.deb"
fi
elif command -v rpm &> /dev/null; then
type="rpm"
if [[ $version > "0.3" ]]; then
binary="bor-${tag}.aarch64.rpm"
profile="bor-${profileInforpm}.noarch.rpm"
else
binary="bor_${tag}_linux_arm64.rpm"
fi
elif command -v apk &> /dev/null; then
if [[ $version > "0.3" ]]; then
oops "sorry, there is no binary distribution for your platform"
fi
type="apk"
binary="bor_${tag}_linux_arm64.apk"
else
if [[ $version > "0.3" ]]; then
oops "sorry, there is no binary distribution for your platform"
fi
type="tar.gz"
binary="bor_${tag}_linux_arm64.tar.gz"
fi
;;
Darwin.x86_64)
if [[ $version > "0.3" ]]; then
oops "sorry, there is no binary distribution for your platform"
fi
type="tar.gz"
binary="bor_${version}_darwin_amd64.tar.gz"
;;
Darwin.arm64|Darwin.aarch64)
if [[ $version > "0.3" ]]; then
oops "sorry, there is no binary distribution for your platform"
fi
type="tar.gz"
binary="bor_${version}_darwin_arm64.tar.gz"
;;
*) oops "sorry, there is no binary distribution for your platform";;
esac
url="${baseUrl}/${binary}"
package=$tmpDir/$binary
if command -v curl > /dev/null 2>&1; then
fetch() { curl -L "$1" -o "$2"; }
elif command -v wget > /dev/null 2>&1; then
fetch() { wget "$1" -O "$2"; }
else
oops "you don't have wget or curl installed, which I need to download the binary package"
fi
echo "downloading bor binary package for $system from '$url' to '$tmpDir'..."
fetch "$url" "$package" || oops "failed to download '$url'"
# Check if profile is not empty
if [ ! -z "$profile" ] && [[ "$version" > "0.3" ]]; then
profileUrl="${baseUrl}/${profile}"
profilePackage=$tmpDir/$profile
echo "downloading bor profile package for $system from '$profileUrl' to '$tmpDir'..."
fetch "$profileUrl" "$profilePackage" || oops "failed to download '$profileUrl'"
fi
if [ $type = "tar.gz" ]; then
require_util tar "unpack the binary package"
unpack=$tmpDir/unpack
mkdir -p "$unpack"
tar -xzf "$package" -C "$unpack" || oops "failed to unpack '$package'"
sudo cp "${unpack}/bor" /usr/local/bin/bor || oops "failed to copy bor binary to '/usr/local/bin/bor'"
elif [ $type = "deb" ]; then
echo "Uninstalling any existing old binary ..."
sudo dpkg -r bor
echo "Installing $package ..."
sudo dpkg -i $package
if [ ! -z "$profilePackage" ] && sudo [ ! -f /var/lib/bor/config.toml ]; then
sudo dpkg -i $profilePackage
fi
elif [ $type = "rpm" ]; then
echo "Uninstalling any existing old binary ..."
sudo rpm -e bor
echo "Installing $package ..."
sudo rpm -i --force $package
if [ ! -z "$profilePackage" ] && sudo [ ! -f /var/lib/bor/config.toml ]; then
sudo rpm -i --force $profilePackage
fi
elif [ $type = "apk" ]; then
echo "Installing $package ..."
sudo apk add --allow-untrusted $package
fi
echo "Checking bor version ..."
/usr/bin/bor version || oops "something went wrong"
echo "bor has been installed successfully!"
} # End of wrapping