forked from Chia-Network/chia-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-plotter.sh
executable file
·198 lines (166 loc) · 4.79 KB
/
install-plotter.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
#!/bin/bash
set -o errexit
USAGE_TEXT="\
Usage: $0 <bladebit|madmax> [-v VERSION | -h]
-v VERSION Specify the version of plotter to install
-h Show usage
"
usage() {
echo "${USAGE_TEXT}"
}
get_bladebit_filename() {
BLADEBIT_VER="$1" # e.g. v2.0.0-beta1
OS="$2" # "ubuntu", "centos", "macos"
ARCH="$3" # "x86-64", "arm64"
echo "bladebit-${BLADEBIT_VER}-${OS}-${ARCH}.tar.gz"
}
get_bladebit_url() {
BLADEBIT_VER="$1" # e.g. v2.0.0-beta1
OS="$2" # "ubuntu", "centos", "macos"
ARCH="$3" # "x86-64", "arm64"
GITHUB_BASE_URL="https://github.com/Chia-Network/bladebit/releases/download"
BLADEBIT_FILENAME="$(get_bladebit_filename "${BLADEBIT_VER}" "${OS}" "${ARCH}")"
echo "${GITHUB_BASE_URL}/${BLADEBIT_VER}/${BLADEBIT_FILENAME}"
}
get_madmax_filename() {
KSIZE="$1" # "k34" or other
MADMAX_VER="$2" # e.g. 0.0.2
OS="$3" # "macos", others
ARCH="$4" # "arm64", "x86-64"
CHIA_PLOT="chia_plot"
if [ "$KSIZE" = "k34" ]; then
CHIA_PLOT="chia_plot_k34"
fi
SUFFIX=""
if [ "$OS" = "macos" ]; then
if [ "$ARCH" = "arm64" ]; then
ARCH="m1"
else
ARCH="intel"
fi
SUFFIX="${OS}-${ARCH}"
else
SUFFIX="${ARCH}"
fi
echo "${CHIA_PLOT}-${MADMAX_VER}-${SUFFIX}"
}
get_madmax_url() {
KSIZE="$1" # "k34" or other
MADMAX_VER="$2" # e.g. 0.0.2
OS="$3" # "macos", others
ARCH="$4" # "intel", "m1", "arm64", "x86-64"
GITHUB_BASE_URL="https://github.com/Chia-Network/chia-plotter-madmax/releases/download"
MADMAX_FILENAME="$(get_madmax_filename "${KSIZE}" "${MADMAX_VER}" "${OS}" "${ARCH}")"
echo "${GITHUB_BASE_URL}/${MADMAX_VER}/${MADMAX_FILENAME}"
}
if [ "$1" = "-h" ] || [ -z "$1" ]; then
usage
exit 0
fi
DEFAULT_BLADEBIT_VERSION="v2.0.1"
DEFAULT_MADMAX_VERSION="0.0.2"
VERSION=
PLOTTER=$1
shift 1
while getopts v:h flag
do
case "${flag}" in
# version
v) VERSION="$OPTARG";;
h) usage; exit 0;;
*) echo; usage; exit 1;;
esac
done
SCRIPT_DIR=$(cd -- "$(dirname -- "$0")"; pwd)
if [ "${SCRIPT_DIR}" != "$(pwd)" ]; then
echo "ERROR: Please change working directory by the command below"
echo " cd ${SCRIPT_DIR}"
exit 1
fi
if [ -z "$VIRTUAL_ENV" ]; then
echo "This requires the chia python virtual environment."
echo "Execute '. ./activate' before running."
exit 1
fi
if [ "$(id -u)" = 0 ]; then
echo "ERROR: Plotter can not be installed or run by the root user."
exit 1
fi
OS=""
ARCH="x86-64"
if [ "$(uname)" = "Linux" ]; then
# Debian / Ubuntu
if command -v apt-get >/dev/null; then
echo "Detected Debian/Ubuntu like OS"
OS="ubuntu"
# RedHut / CentOS / Rocky / AMLinux
elif type yum >/dev/null 2>&1; then
echo "Detected RedHut like OS"
OS="centos"
else
echo "ERROR: Unknown Linux distro"
exit 1
fi
# MacOS
elif [ "$(uname)" = "Darwin" ]; then
echo "Detected MacOS"
OS="macos"
else
echo "ERROR: $(uname) is not supported"
exit 1
fi
if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then
ARCH="arm64"
fi
if [ ! -d "${VIRTUAL_ENV}/bin" ]; then
echo "ERROR: venv directory does not exists: '${VIRTUAL_ENV}/bin'"
exit 1
fi
cd "${VIRTUAL_ENV}/bin"
if [ "$PLOTTER" = "bladebit" ]; then
if [ -z "$VERSION" ]; then
VERSION="$DEFAULT_BLADEBIT_VERSION"
fi
echo "Installing bladebit $VERSION"
URL="$(get_bladebit_url "${VERSION}" "${OS}" "${ARCH}")"
echo "Fetching binary from: ${URL}"
if ! wget -q "${URL}"; then
echo "ERROR: Download failed. Maybe specified version of the binary does not exist."
exit 1
fi
echo "Successfully downloaded: ${URL}"
bladebit_filename="$(get_bladebit_filename "${VERSION}" "${OS}" "${ARCH}")"
tar zxf "${bladebit_filename}"
chmod 755 ./bladebit
rm -f "${bladebit_filename}"
echo "Successfully installed bladebit to $(pwd)/bladebit"
elif [ "$PLOTTER" = "madmax" ]; then
if [ -z "$VERSION" ]; then
VERSION="$DEFAULT_MADMAX_VERSION"
fi
echo "Installing madmax $VERSION"
URL="$(get_madmax_url k32 "${VERSION}" "${OS}" "${ARCH}")"
echo "Fetching binary from: ${URL}"
if ! wget -q "${URL}"; then
echo "ERROR: Download failed. Maybe specified version of the binary does not exist."
exit 1
fi
echo "Successfully downloaded: ${URL}"
madmax_filename="$(get_madmax_filename "k32" "${VERSION}" "${OS}" "${ARCH}")"
mv -f "${madmax_filename}" chia_plot
chmod 755 chia_plot
echo "Successfully installed madmax to $(pwd)/chia_plot"
URL="$(get_madmax_url k34 "${VERSION}" "${OS}" "${ARCH}")"
echo "Fetching binary from: ${URL}"
if ! wget -q "${URL}"; then
echo "madmax for k34 for this version is not found"
exit 1
fi
echo "Successfully downloaded: ${URL}"
madmax_filename="$(get_madmax_filename "k34" "${VERSION}" "${OS}" "${ARCH}")"
mv -f "${madmax_filename}" chia_plot_k34
chmod 755 chia_plot_k34
echo "Successfully installed madmax for k34 to $(pwd)/chia_plot_k34"
else
usage
fi