forked from IntersectMBO/cardano-node-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-node.sh
250 lines (210 loc) · 6.72 KB
/
install-node.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
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/env bash
# Builds 'cardano-node' and 'cardano-cli' on Ubuntu or Fedora using Cabal and verifies
# successful installation.
#
# Please note: sudo is not used because user is root
# Please note: 'source ~/.bashrc' cmd is not used because Docker runs this script as subscript
# Versions
GHC_VERSION="9.6.3"
CABAL_VERSION="3.10.2.0"
LIBSODIUM_VERSION="dbb48cc"
SECP256K1_VERSION="ac83be33"
BLST_VERSION="v0.3.10"
echo ""
# Check that environment variables are correctly set up.
case "$GIT_OBJECT_TYPE" in
tag | commit)
:
;;
*)
>&2 printf "Please specify 'GIT_OBJECT_TYPE' on docker run.\ne.g. '-e GIT_OBJECT_TYPE=tag' or '-e GIT_OBJECT_TYPE=commit'"
exit 1
;;
esac
if [[ -z "${GIT_OBJECT}" ]]; then
>&2 printf "Please specify 'GIT_OBJECT' on docker run.\ne.g. '-e GIT_OBJECT=8.0.0' for tags, or '-e GIT_OBJECT=78wagy3aw87ef' for commits."
exit 1
fi
echo "Using git object '$GIT_OBJECT' of type '$GIT_OBJECT_TYPE'"
cd ~ || exit 1
# Set up ~/.local/bin
mkdir -p ~/.local/bin || exit 1
if [[ "$PATH" != *"~/.local/bin"* ]]; then
export PATH=~/.local/bin:"$PATH"
else
echo "'PATH' already contains ~/.local/bin"
fi
# Install dependencies
echo "Install dependencies"
if [[ "$(</etc/os-release)" == *"fedora"* ]]; then
echo "Running on Fedora"
yum update -y
yum install curl systemd-devel ncurses-devel ncurses-compat-libs which jq openssl-devel lmdb-devel -y
elif [[ "$(</etc/os-release)" == *"ubuntu"* ]]; then
echo "Running on Ubuntu"
apt-get update -y
apt-get install curl automake build-essential pkg-config libffi-dev libgmp-dev libssl-dev libtinfo-dev libsystemd-dev zlib1g-dev make g++ tmux git jq wget libncursesw5 libtool autoconf liblmdb-dev -y
else
>&2 echo "/etc/os-relase does not contain 'fedora' or 'ubuntu'"
>&2 cat /etc/os-release
exit 1
fi
# Install GHCup - the main installer for Haskell
echo "Install GHCup"
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 BOOTSTRAP_HASKELL_MINIMAL=1 BOOTSTRAP_HASKELL_ADJUST_BASHRC=P sh
# Source changes in order to use GHCup in current terminal session
# shellcheck source=/dev/null
source /root/.ghcup/env
# Download, unpack, install and update Cabal
echo "Download, unpack, install and update Cabal"
ghcup install cabal $CABAL_VERSION
ghcup set cabal $CABAL_VERSION
cabal update
if [[ "$(cabal --version)" != *"cabal-install version $CABAL_VERSION"* ]]; then
>&2 echo "cabal version '$(cabal --version)' is not '$CABAL_VERSION'"
exit 1
else
echo "cabal version '$CABAL_VERSION' is correct"
fi
# Download, unpack and install GHC
echo "Download and install GHC"
ghcup install ghc $GHC_VERSION
ghcup set ghc $GHC_VERSION
if [[ $(ghc --version) != *"version $GHC_VERSION"* ]]; then
>&2 echo "ghc version '$(ghc --version)' is not '$GHC_VERSION'"
exit 1
else
echo "ghc version '$GHC_VERSION' is correct"
fi
# Install Libsodium
echo "Install Libsodium"
mkdir -p ~/src || exit 1
cd ~/src || exit 1
git clone https://github.com/IntersectMBO/libsodium
cd libsodium || exit 1
git checkout "$LIBSODIUM_VERSION"
./autogen.sh
./configure
make
make install
export LD_LIBRARY_PATH="/usr/local/lib:${LD_LIBRARY_PATH}"
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH}"
# shellcheck source=/dev/null
source ~/.bashrc
# Install Secp256k1
echo "Install Secp256k1"
mkdir -p ~/src || exit 1
cd ~/src || exit 1
git clone https://github.com/bitcoin-core/secp256k1
cd secp256k1 || exit 1
git checkout "$SECP256K1_VERSION"
./autogen.sh
./configure --enable-module-schnorrsig --enable-experimental
make
make install
# Install BLST
echo "Install BLST"
mkdir -p ~/src || exit 1
cd ~/src || exit 1
git clone https://github.com/supranational/blst
cd blst || exit 1
git checkout "$BLST_VERSION"
./build.sh
cat > libblst.pc << EOF
prefix=/usr/local
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include
Name: libblst
Description: Multilingual BLS12-381 signature library
URL: https://github.com/supranational/blst
Version: 0.3.10
Cflags: -I\${includedir}
Libs: -L\${libdir} -lblst
EOF
cp libblst.pc /usr/local/lib/pkgconfig/
cp bindings/blst_aux.h bindings/blst.h bindings/blst.hpp /usr/local/include/
cp libblst.a /usr/local/lib
chmod u=rw,go=r /usr/local/{lib/{libblst.a,pkgconfig/libblst.pc},include/{blst.{h,hpp},blst_aux.h}}
# Download the source code for cardano-node
echo "Download the source code for cardano-node"
mkdir -p ~/src || exit 1
cd ~/src || exit 1
git clone https://github.com/IntersectMBO/cardano-node.git
cd cardano-node || exit 1
git fetch --all --recurse-submodules --tags
# Checkout with prechecks for git object and git object type
OBJ_TYPE="$(git cat-file -t "$GIT_OBJECT")"
if [[ "$OBJ_TYPE" != "commit" && "$OBJ_TYPE" != "tag" ]]; then
>&2 echo "'$OBJ_TYPE' does not refer to a commit/tag."
exit 1
fi
case "$GIT_OBJECT_TYPE" in
tag)
if [[ "$(git tag)" != *"$GIT_OBJECT"* ]]; then
>&2 echo "'$(git tag)' does not contain '$GIT_OBJECT'"
exit 1
fi
;;
commit)
:
;;
*)
exit 1
;;
esac
git checkout "$GIT_OBJECT"
GIT_REV=$(git rev-parse HEAD)
# Configure build options
echo "Configure build options"
echo "with-compiler: ghc-${GHC_VERSION}" >> cabal.project.local
# Build and install the node and cli
echo "Build and install the node and cli"
cabal update
cabal build all
cabal build cardano-cli
cp -p "$(./scripts/bin-path.sh cardano-node)" ~/.local/bin/
cp -p "$(./scripts/bin-path.sh cardano-cli)" ~/.local/bin/
# Verify installation
case "$GIT_OBJECT_TYPE" in
tag)
CARDANO_NODE_VERSION="$GIT_OBJECT"
if [[ "${CARDANO_NODE_VERSION:0-4}" == "-pre" ]]; then
CARDANO_NODE_VERSION="${GIT_OBJECT:0:-4}"
fi
echo "Verify 'cardano-cli' is installed"
if [[ "$(cardano-cli --version | tail -n 1)" == *"$GIT_REV"* ]]; then
cardano-cli --version
else
>&2 echo "'$(cardano-cli --version)' does not contain '$GIT_REV'"
exit 1
fi
echo "Verify 'cardano-node' is installed"
if [[ "$(cardano-node --version)" == *"$CARDANO_NODE_VERSION"* ]]; then
cardano-node --version
else
>&2 echo "'$(cardano-node --version)' does not contain '$CARDANO_NODE_VERSION'"
exit 1
fi
;;
commit)
echo "Verify 'cardano-cli' is installed"
if ! [[ "$(cardano-cli --version | tail -n 1)" == *"$GIT_REV"* ]]; then
>&2 echo "'$(cardano-cli --version)' failed"
exit 1
fi
echo "Verify 'cardano-node' is installed"
if ! [[ "$(cardano-node --version | tail -n 1)" == *"$GIT_REV"* ]]; then
>&2 echo "'$(cardano-node --version)' failed"
exit 1
fi
;;
*)
exit 1
;;
esac
# Succes message
printf "\nSuccess\n\n"
echo "You can use 'docker exec -it <container-id> /bin/bash' in a separate session to play in the environment."
echo "Press any key to stop the container."
read -r