-
Notifications
You must be signed in to change notification settings - Fork 8
/
heimdall.sh
executable file
·240 lines (214 loc) · 7.55 KB
/
heimdall.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/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 heimdall-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="1.0.10"
newCLIVersion="1.0.10"
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" = "validator" ]; then
nodetype="$3"
elif [ "$3" = "archive" ]; then
echo "No option of archive node type in heimdall. Using default mode: $nodetype"
elif [ "$3" = "bootnode" ]; then
echo "No option of bootnode type in heimdall. Using default mode: $nodetype"
else
echo "Invalid node type: $3, choose from 'sentry' or 'validator'"
exit 1
fi
fi
if [[ $version > "0.3" ]]; then
tag=${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/heimdall/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="heimdall-v${tag}-amd64.deb"
profile="heimdall-${profileInfo}-all.deb"
else
binary="heimdall_v${tag}_linux_amd64.deb"
fi
elif command -v rpm &> /dev/null; then
type="rpm"
if [[ $version > "0.3" ]]; then
binary="heimdall-v${tag}.x86_64.rpm"
profile="heimdall-${profileInforpm}.noarch.rpm"
else
binary="heimdall_v${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="heimdall_v${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="heimdalld_v${tag}_linux_amd64.tar.gz"
fi
;;
Linux.aarch64)
if command -v dpkg &> /dev/null; then
type="deb"
if [[ $version > "0.3" ]]; then
binary="heimdall-v${tag}-arm64.deb"
profile="heimdall-${profileInfo}-all.deb"
else
binary="heimdall_v${tag}_linux_arm64.deb"
fi
elif command -v rpm &> /dev/null; then
type="rpm"
if [[ $version > "0.3" ]]; then
binary="heimdall-v${tag}.aarch64.rpm"
profile="heimdall-${profileInforpm}.noarch.rpm"
else
binary="heimdall_v${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="heimdall_v${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="heimdalld_v${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="heimdalld_v${tag}_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="heimdalld_v${tag}_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 heimdall 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 heimdall 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}/heimdalld" /usr/local/bin/heimdalld || oops "failed to copy heimdalld binary to '/usr/local/bin/heimdalld'"
sudo cp "${unpack}/heimdallcli" /usr/local/bin/heimdallcli || oops "failed to copy heimdallcli binary to '/usr/local/bin/heimdallcli'"
if [ "$version" \< "$newCLIVersion" ]; then
sudo cp "${unpack}/bridge" /usr/local/bin/bridge || oops "failed to copy bridge binary to '/usr/local/bin/bridge'"
fi
elif [ $type = "deb" ]; then
echo "Uninstalling any existing old binary ..."
sudo dpkg -r heimdall
sudo dpkg -r heimdalld
echo "Installing $package ..."
sudo dpkg -i $package
if [ ! -z "$profilePackage" ] && sudo [ ! -d /var/lib/heimdall/config ]; then
sudo dpkg -i $profilePackage
fi
elif [ $type = "rpm" ]; then
echo "Uninstalling any existing old binary ..."
sudo rpm -e heimdall
echo "Installing $package ..."
sudo rpm -i --force $package
if [ ! -z "$profilePackage" ] && sudo [ ! -d /var/lib/heimdall/config ]; then
sudo rpm -i --force $profilePackage
fi
elif [ $type = "apk" ]; then
echo "Installing $package ..."
sudo apk add --allow-untrusted $package
fi
if [ "$version" \< "$newCLIVersion" ]; then
echo "Checking bridge version ..."
bridge version || oops "something went wrong"
fi
echo "Checking heimdalld version ..."
/usr/bin/heimdalld version || oops "something went wrong"
echo "heimdall has been installed successfully!"
} # End of wrapping