This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
forked from Flax-Network/flax-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·310 lines (283 loc) · 10.8 KB
/
install.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!/bin/bash
set -o errexit
USAGE_TEXT="\
Usage: $0 [-adh]
-a automated install, no questions
-d install development dependencies
-h display this help and exit
"
usage() {
echo "${USAGE_TEXT}"
}
PACMAN_AUTOMATED=
EXTRAS=
while getopts adh flag
do
case "${flag}" in
# automated
a) PACMAN_AUTOMATED=--noconfirm;;
# development
d) EXTRAS=${EXTRAS}dev,;;
h) usage; exit 0;;
*) echo; usage; exit 1;;
esac
done
UBUNTU=false
DEBIAN=false
if [ "$(uname)" = "Linux" ]; then
#LINUX=1
if command -v apt-get >/dev/null; then
OS_ID=$(lsb_release -is)
if [ "$OS_ID" = "Debian" ]; then
DEBIAN=true
else
UBUNTU=true
fi
fi
fi
# Check for non 64 bit ARM64/Raspberry Pi installs
if [ "$(uname -m)" = "armv7l" ]; then
echo ""
echo "WARNING:"
echo "The Flax Blockchain requires a 64 bit OS and this is 32 bit armv7l"
echo "For more information, see"
echo "https://github.com/Flax-Network/flax-blockchain/wiki/Raspberry-Pi"
echo "Exiting."
exit 1
fi
# Get submodules
git submodule update --init mozilla-ca
UBUNTU_PRE_20=0
UBUNTU_20=0
UBUNTU_21=0
UBUNTU_22=0
if $UBUNTU; then
LSB_RELEASE=$(lsb_release -rs)
# In case Ubuntu minimal does not come with bc
if ! command -v bc > /dev/null 2>&1; then
sudo apt install bc -y
fi
# Mint 20.04 responds with 20 here so 20 instead of 20.04
if [ "$(echo "$LSB_RELEASE<20" | bc)" = "1" ]; then
UBUNTU_PRE_20=1
elif [ "$(echo "$LSB_RELEASE<21" | bc)" = "1" ]; then
UBUNTU_20=1
elif [ "$(echo "$LSB_RELEASE<22" | bc)" = "1" ]; then
UBUNTU_21=1
else
UBUNTU_22=1
fi
fi
install_python3_and_sqlite3_from_source_with_yum() {
CURRENT_WD=$(pwd)
TMP_PATH=/tmp
# Preparing installing Python
echo 'yum groupinstall -y "Development Tools"'
sudo yum groupinstall -y "Development Tools"
echo "sudo yum install -y openssl-devel openssl libffi-devel bzip2-devel wget"
sudo yum install -y openssl-devel openssl libffi-devel bzip2-devel wget
echo "cd $TMP_PATH"
cd "$TMP_PATH"
# Install sqlite>=3.37
# yum install sqlite-devel brings sqlite3.7 which is not compatible with flax
echo "wget https://www.sqlite.org/2022/sqlite-autoconf-3370200.tar.gz"
wget https://www.sqlite.org/2022/sqlite-autoconf-3370200.tar.gz
tar xf sqlite-autoconf-3370200.tar.gz
echo "cd sqlite-autoconf-3370200"
cd sqlite-autoconf-3370200
echo "./configure --prefix=/usr/local"
# '| stdbuf ...' seems weird but this makes command outputs stay in single line.
./configure --prefix=/usr/local | stdbuf -o0 cut -b1-"$(tput cols)" | sed -u 'i\\o033[2K' | stdbuf -o0 tr '\n' '\r'; echo
echo "make -j$(nproc)"
make -j"$(nproc)" | stdbuf -o0 cut -b1-"$(tput cols)" | sed -u 'i\\o033[2K' | stdbuf -o0 tr '\n' '\r'; echo
echo "sudo make install"
sudo make install | stdbuf -o0 cut -b1-"$(tput cols)" | sed -u 'i\\o033[2K' | stdbuf -o0 tr '\n' '\r'; echo
# yum install python3 brings Python3.6 which is not supported by flax
cd ..
echo "wget https://www.python.org/ftp/python/3.9.11/Python-3.9.11.tgz"
wget https://www.python.org/ftp/python/3.9.11/Python-3.9.11.tgz
tar xf Python-3.9.11.tgz
echo "cd Python-3.9.11"
cd Python-3.9.11
echo "LD_RUN_PATH=/usr/local/lib ./configure --prefix=/usr/local"
# '| stdbuf ...' seems weird but this makes command outputs stay in single line.
LD_RUN_PATH=/usr/local/lib ./configure --prefix=/usr/local | stdbuf -o0 cut -b1-"$(tput cols)" | sed -u 'i\\o033[2K' | stdbuf -o0 tr '\n' '\r'; echo
echo "LD_RUN_PATH=/usr/local/lib make -j$(nproc)"
LD_RUN_PATH=/usr/local/lib make -j"$(nproc)" | stdbuf -o0 cut -b1-"$(tput cols)" | sed -u 'i\\o033[2K' | stdbuf -o0 tr '\n' '\r'; echo
echo "LD_RUN_PATH=/usr/local/lib sudo make altinstall"
LD_RUN_PATH=/usr/local/lib sudo make altinstall | stdbuf -o0 cut -b1-"$(tput cols)" | sed -u 'i\\o033[2K' | stdbuf -o0 tr '\n' '\r'; echo
cd "$CURRENT_WD"
}
# Manage npm and other install requirements on an OS specific basis
if [ "$(uname)" = "Linux" ]; then
#LINUX=1
if [ "$UBUNTU_PRE_20" = "1" ]; then
# Ubuntu
echo "Installing on Ubuntu pre 20.*."
sudo apt-get update
# distutils must be installed as well to avoid a complaint about ensurepip while
# creating the venv. This may be related to a mis-check while using or
# misconfiguration of the secondary Python version 3.7. The primary is Python 3.6.
sudo apt-get install -y python3.7-venv python3.7-distutils openssl
elif [ "$UBUNTU_20" = "1" ]; then
echo "Installing on Ubuntu 20.*."
sudo apt-get update
sudo apt-get install -y python3.8-venv openssl
elif [ "$UBUNTU_21" = "1" ]; then
echo "Installing on Ubuntu 21.*."
sudo apt-get update
sudo apt-get install -y python3.9-venv openssl
elif [ "$UBUNTU_22" = "1" ]; then
echo "Installing on Ubuntu 22.* or newer."
sudo apt-get update
sudo apt-get install -y python3.10-venv openssl
elif [ "$DEBIAN" = "true" ]; then
echo "Installing on Debian."
sudo apt-get update
sudo apt-get install -y python3-venv openssl
elif type pacman >/dev/null 2>&1 && [ -f "/etc/arch-release" ]; then
# Arch Linux
# Arch provides latest python version. User will need to manually install python 3.9 if it is not present
echo "Installing on Arch Linux."
case $(uname -m) in
x86_64|aarch64)
sudo pacman ${PACMAN_AUTOMATED} -S --needed git openssl
;;
*)
echo "Incompatible CPU architecture. Must be x86_64 or aarch64."
exit 1
;;
esac
elif type yum >/dev/null 2>&1 && [ ! -f "/etc/redhat-release" ] && [ ! -f "/etc/centos-release" ] && [ ! -f "/etc/fedora-release" ]; then
# AMZN 2
echo "Installing on Amazon Linux 2."
if ! command -v python3.9 >/dev/null 2>&1; then
install_python3_and_sqlite3_from_source_with_yum
fi
elif type yum >/dev/null 2>&1 && [ -f "/etc/centos-release" ]; then
# CentOS
echo "Install on CentOS."
if ! command -v python3.9 >/dev/null 2>&1; then
install_python3_and_sqlite3_from_source_with_yum
fi
elif type yum >/dev/null 2>&1 && [ -f "/etc/redhat-release" ] && grep Rocky /etc/redhat-release; then
echo "Installing on Rocky."
# TODO: make this smarter about getting the latest version
sudo yum install --assumeyes python39 openssl
elif type yum >/dev/null 2>&1 && [ -f "/etc/redhat-release" ] || [ -f "/etc/fedora-release" ]; then
# Redhat or Fedora
echo "Installing on Redhat/Fedora."
if ! command -v python3.9 >/dev/null 2>&1; then
sudo yum install -y python39 openssl
fi
fi
elif [ "$(uname)" = "Darwin" ]; then
echo "Installing on macOS."
if ! type brew >/dev/null 2>&1; then
echo "Installation currently requires brew on macOS - https://brew.sh/"
exit 1
fi
echo "Installing OpenSSL"
brew install openssl
elif [ "$(uname)" = "OpenBSD" ]; then
export MAKE=${MAKE:-gmake}
export BUILD_VDF_CLIENT=${BUILD_VDF_CLIENT:-N}
elif [ "$(uname)" = "FreeBSD" ]; then
export MAKE=${MAKE:-gmake}
export BUILD_VDF_CLIENT=${BUILD_VDF_CLIENT:-N}
fi
find_python() {
set +e
unset BEST_VERSION
for V in 310 3.10 39 3.9 38 3.8 37 3.7 3; do
if command -v python$V >/dev/null; then
if [ "$BEST_VERSION" = "" ]; then
BEST_VERSION=$V
if [ "$BEST_VERSION" = "3" ]; then
PY3_VERSION=$(python$BEST_VERSION --version | cut -d ' ' -f2)
if [[ "$PY3_VERSION" =~ 3.11.* ]]; then
echo "Flax requires Python version < 3.11.0" >&2
echo "Current Python version = $PY3_VERSION" >&2
# If Arch, direct to Arch Wiki
if type pacman >/dev/null 2>&1 && [ -f "/etc/arch-release" ]; then
echo "Please see https://wiki.archlinux.org/title/python#Old_versions for support." >&2
fi
exit 1
fi
fi
fi
fi
done
echo $BEST_VERSION
set -e
}
if [ "$INSTALL_PYTHON_VERSION" = "" ]; then
INSTALL_PYTHON_VERSION=$(find_python)
fi
# This fancy syntax sets INSTALL_PYTHON_PATH to "python3.7", unless
# INSTALL_PYTHON_VERSION is defined.
# If INSTALL_PYTHON_VERSION equals 3.8, then INSTALL_PYTHON_PATH becomes python3.8
INSTALL_PYTHON_PATH=python${INSTALL_PYTHON_VERSION:-3.7}
if ! command -v "$INSTALL_PYTHON_PATH" >/dev/null; then
echo "${INSTALL_PYTHON_PATH} was not found"
exit 1
fi
echo "Python version is $INSTALL_PYTHON_VERSION"
# Check sqlite3 version bound to python
SQLITE_VERSION=$($INSTALL_PYTHON_PATH -c 'import sqlite3; print(sqlite3.sqlite_version)')
SQLITE_MAJOR_VER=$(echo "$SQLITE_VERSION" | cut -d'.' -f1)
SQLITE_MINOR_VER=$(echo "$SQLITE_VERSION" | cut -d'.' -f2)
echo "SQLite version for Python is ${SQLITE_VERSION}"
if [ "$SQLITE_MAJOR_VER" -lt "3" ] || [ "$SQLITE_MAJOR_VER" = "3" ] && [ "$SQLITE_MINOR_VER" -lt "8" ]; then
echo "Only sqlite>=3.8 is supported"
exit 1
fi
# Check openssl version python will use
OPENSSL_VERSION_STRING=$($INSTALL_PYTHON_PATH -c 'import ssl; print(ssl.OPENSSL_VERSION)')
OPENSSL_VERSION_INT=$($INSTALL_PYTHON_PATH -c 'import ssl; print(ssl.OPENSSL_VERSION_NUMBER)')
# There is also ssl.OPENSSL_VERSION_INFO returning a tuple
# 1.1.1n corresponds to 269488367 as an integer
echo "OpenSSL version for Python is ${OPENSSL_VERSION_STRING}"
if [ "$OPENSSL_VERSION_INT" -lt "269488367" ]; then
echo "WARNING: OpenSSL versions before 3.0.2, 1.1.1n, or 1.0.2zd are vulnerable to CVE-2022-0778"
echo "Your OS may have patched OpenSSL and not updated the version to 1.1.1n"
fi
# If version of `python` and "$INSTALL_PYTHON_VERSION" does not match, clear old version
VENV_CLEAR=""
if [ -e venv/bin/python ]; then
VENV_PYTHON_VER=$(venv/bin/python -V)
TARGET_PYTHON_VER=$($INSTALL_PYTHON_PATH -V)
if [ "$VENV_PYTHON_VER" != "$TARGET_PYTHON_VER" ]; then
echo "existing python version in venv is $VENV_PYTHON_VER while target python version is $TARGET_PYTHON_VER"
echo "Refreshing venv modules..."
VENV_CLEAR="--clear"
fi
fi
$INSTALL_PYTHON_PATH -m venv venv $VENV_CLEAR
if [ ! -f "activate" ]; then
ln -s venv/bin/activate .
fi
EXTRAS=${EXTRAS%,}
if [ -n "${EXTRAS}" ]; then
EXTRAS=[${EXTRAS}]
fi
# shellcheck disable=SC1091
. ./activate
# pip 20.x+ supports Linux binary wheels
python -m pip install --upgrade pip
python -m pip install wheel
#if [ "$INSTALL_PYTHON_VERSION" = "3.8" ]; then
# This remains in case there is a diversion of binary wheels
python -m pip install --extra-index-url https://pypi.chia.net/simple/ miniupnpc==2.2.2
python -m pip install -e ."${EXTRAS}" --extra-index-url https://pypi.chia.net/simple/
echo ""
echo "Flax blockchain install.sh complete."
echo "For assistance join us on Discord in the #support chat channel:"
echo "https://discord.gg/yEWaF6CQcA"
echo ""
echo "Try the Quick Start Guide to running flax-blockchain:"
echo "https://github.com/Flax-Network/flax-blockchain/wiki/Quick-Start-Guide"
echo ""
echo "To install the GUI type 'sh install-gui.sh' after '. ./activate'."
echo ""
echo "Type '. ./activate' and then 'flax init' to begin."