Update install plotters scripts (#15838)

* adding bladebit-cuda to install-plotter.sh

Signed-off-by: wallentx <william.allentx@gmail.com>

* cleanup install-plotter.sh

Signed-off-by: wallentx <william.allentx@gmail.com>

* optimize install-plotter.sh

Signed-off-by: wallentx <william.allentx@gmail.com>

* update install-plotter.ps1

Signed-off-by: wallentx <william.allentx@gmail.com>

* Update pyinstaller.spec

* Fix whitespace in pyinstaller.spec

* using an approved verb for ps1...

* Fixing Install-plotter.ps1, and expanding install-ploter.sh distro support

* Fixing linter

---------

Signed-off-by: wallentx <william.allentx@gmail.com>
This commit is contained in:
William Allen
2023-07-24 20:57:49 -05:00
committed by GitHub
parent 1fed854268
commit d7539b14c6
3 changed files with 247 additions and 139 deletions
+113 -63
View File
@@ -16,13 +16,44 @@ param(
$ErrorActionPreference = "Stop"
$DEFAULT_BLADEBIT_VERSION = "v2.0.1"
$DEFAULT_MADMAX_VERSION = "0.0.2"
$VERSION = $v
$OS = "windows"
$ARCH = "x86-64"
if (("$plotter" -ne "bladebit") -And ("$plotter" -ne "madmax"))
{
Write-Output "Plotter must be 'bladebit' or 'madmax'"
Exit 1
}
function get_bladebit_filename()
# Check for necessary tools
if (!(Get-Command Invoke-WebRequest -errorAction SilentlyContinue)) {
Write-Output "ERROR: Invoke-WebRequest could not be found. Please ensure PowerShell is updated and try again."
Exit 1
}
if (!(Get-Command Expand-Archive -errorAction SilentlyContinue)) {
Write-Output "ERROR: Expand-Archive could not be found. Please ensure PowerShell is updated and try again."
Exit 1
}
if ($null -eq (Get-ChildItem env:VIRTUAL_ENV -ErrorAction SilentlyContinue))
{
Write-Output "This script requires that the Chia Python virtual environment is activated."
Write-Output "Execute '.\venv\Scripts\Activate.ps1' before running."
Exit 1
}
$venv_bin = "${env:VIRTUAL_ENV}\Scripts"
if (-not (Test-Path -Path "$venv_bin" -PathType Container))
{
Write-Output "ERROR: venv folder does not exists: '${venv_bin}'"
Exit 1
}
function Get-BladebitFilename()
{
param(
[string]$ver,
@@ -33,7 +64,19 @@ function get_bladebit_filename()
"bladebit-${ver}-${os}-${arch}.zip"
}
function get_bladebit_url()
function Get-BladebitCudaFilename()
{
param(
[string]$ver,
[string]$os,
[string]$arch
)
"bladebit-cuda-${ver}-${os}-${arch}.zip"
}
function Get-BladebitUrl()
{
param(
[string]$ver,
@@ -42,12 +85,26 @@ function get_bladebit_url()
)
$GITHUB_BASE_URL = "https://github.com/Chia-Network/bladebit/releases/download"
$filename = get_bladebit_filename -ver $ver -os $os -arch $arch
$filename = Get-BladebitFilename -ver $ver -os $os -arch $arch
"${GITHUB_BASE_URL}/${ver}/${filename}"
}
function get_madmax_filename()
function Get-BladebitCudaUrl()
{
param(
[string]$ver,
[string]$os,
[string]$arch
)
$GITHUB_BASE_URL = "https://github.com/Chia-Network/bladebit/releases/download"
$filename = Get-BladebitCudaFilename -ver $ver -os $os -arch $arch
"${GITHUB_BASE_URL}/${ver}/${filename}"
}
function Get-MadmaxFilename()
{
param(
[string]$ksize,
@@ -78,7 +135,7 @@ function get_madmax_filename()
"${chia_plot}-${ver}${suffix}"
}
function get_madmax_url()
function Get-MadmaxUrl()
{
param(
[string]$ksize,
@@ -88,30 +145,51 @@ function get_madmax_url()
)
$GITHUB_BASE_URL = "https://github.com/Chia-Network/chia-plotter-madmax/releases/download"
$madmax_filename = get_madmax_filename -ksize $ksize -ver $ver -os $os -arch $arch
$madmax_filename = Get-MadmaxFilename -ksize $ksize -ver $ver -os $os -arch $arch
"${GITHUB_BASE_URL}/${ver}/${madmax_filename}"
}
$DEFAULT_BLADEBIT_VERSION = "v2.0.0"
$DEFAULT_MADMAX_VERSION = "0.0.2"
$VERSION = $v
$OS = "windows"
$ARCH = "x86-64"
if ($null -eq (Get-ChildItem env:VIRTUAL_ENV -ErrorAction SilentlyContinue))
# Function to download, extract, set permissions, and clean up
function Get-Binary()
{
Write-Output "This script requires that the Chia Python virtual environment is activated."
Write-Output "Execute '.\venv\Scripts\Activate.ps1' before running."
Exit 1
}
param(
[string]$url,
[string]$dest_dir,
[string]$new_filename
)
$venv_bin = "${env:VIRTUAL_ENV}\Scripts"
if (-not (Test-Path -Path "$venv_bin" -PathType Container))
{
Write-Output "ERROR: venv folder does not exists: '${venv_bin}'"
Exit 1
$filename = [System.IO.Path]::GetFileName($url)
$download_path = Join-Path -Path $PWD -ChildPath $filename
try {
Invoke-WebRequest -Uri $url -OutFile $download_path
} catch {
Write-Warning "Failed to download from ${url}. Maybe specified version of the binary does not exist."
return
}
$extension = [System.IO.Path]::GetExtension($download_path)
if ($extension -eq '.zip') {
Expand-Archive -Path $download_path -DestinationPath $dest_dir -Force
Remove-Item -Path $download_path
} else {
Move-Item -Path $download_path -Destination (Join-Path -Path $dest_dir -ChildPath $filename) -Force
}
# Check if new_filename parameter is provided
if ($new_filename) {
# Construct the full paths to the old and new files
$old_file_path = Join-Path -Path $dest_dir -ChildPath $filename
$new_file_path = Join-Path -Path $dest_dir -ChildPath $new_filename
# If the new file already exists, delete it
if (Test-Path $new_file_path) {
Remove-Item -Path $new_file_path
}
# Rename the old file to the new filename
Rename-Item -Path $old_file_path -NewName $new_file_path
}
Write-Output "Successfully installed $filename to $dest_dir"
}
Push-Location
@@ -128,23 +206,13 @@ try {
Write-Output "Installing bladebit ${VERSION}"
$URL = get_bladebit_url -ver "${VERSION}" -os "${OS}" -arch "${ARCH}"
Write-Output "Fetching binary from: ${URL}"
try {
Invoke-WebRequest -Uri "$URL" -OutFile ".\bladebit.zip"
Write-Output "Successfully downloaded: $URL"
}
catch {
Write-Output "ERROR: Download failed. Maybe specified version of the binary does not exist."
Pop-Location
Exit 1
}
$url = Get-BladebitUrl -ver $version -os $os -arch $arch
$dest_dir = $PWD
Get-Binary -url $url -dest_dir $dest_dir
Expand-Archive -Path ".\bladebit.zip" -DestinationPath ".\bladebit"
Move-Item .\bladebit\bladebit.exe .\ -Force
Remove-Item bladebit -Force
Remove-Item bladebit.zip -Force
Write-Output "Successfully installed bladebit to $(Get-Location)\bladebit.exe"
$url = Get-BladebitCudaUrl -ver $version -os $os -arch $arch
$dest_dir = $PWD
Get-Binary -url $url -dest_dir $dest_dir
}
elseif("${plotter}" -eq "madmax")
{
@@ -155,31 +223,13 @@ try {
Write-Output "Installing madmax ${VERSION}"
$madmax_filename = get_madmax_filename -ksize k32 -ver "${VERSION}" -os "${OS}" -arch "${ARCH}"
$URL = get_madmax_url -ksize k32 -ver "${VERSION}" -os "${OS}" -arch "${ARCH}"
Write-Output "Fetching binary from: ${URL}"
try {
Invoke-WebRequest -Uri "$URL" -Outfile "chia_plot.exe"
Write-Output "Successfully downloaded: $URL"
Write-Output "Successfully installed madmax to $(Get-Location)\chia_plot.exe"
}
catch {
Write-Output "ERROR: Download failed. Maybe specified version of the binary does not exist."
Pop-Location
Exit 1
}
$url = Get-MadmaxUrl -ksize "k32" -ver $version -os $os -arch $arch
$dest_dir = $PWD
Get-Binary -url $url -dest_dir $dest_dir -new_filename "chia_plot_k32.exe"
$madmax_filename = get_madmax_filename -ksize k34 -ver "${VERSION}" -os "${OS}" -arch "${ARCH}"
$URL = get_madmax_url -ksize k34 -ver "${VERSION}" -os "${OS}" -arch "${ARCH}"
Write-Output "Fetching binary from: ${URL}"
try {
Invoke-WebRequest -Uri "$URL" -Outfile "chia_plot_k34.exe"
Write-Output "Successfully downloaded: $URL"
Write-Output "Successfully installed madmax for k34 to $(Get-Location)\chia_plot_k34.exe"
}
catch {
Write-Output "madmax for k34 is not found"
}
$url = Get-MadmaxUrl -ksize "k34" -ver $version -os $os -arch $arch
$dest_dir = $PWD
Get-Binary -url $url -dest_dir $dest_dir -new_filename "chia_plot_k34.exe"
}
else
{
+12
View File
@@ -102,6 +102,14 @@ if os.path.exists(f"{ROOT}/bladebit/bladebit"):
)
])
if os.path.exists(f"{ROOT}/bladebit/bladebit_cuda"):
binaries.extend([
(
f"{ROOT}/bladebit/bladebit_cuda",
"bladebit"
)
])
if THIS_IS_WINDOWS:
chia_mod = importlib.import_module("chia")
dll_paths = pathlib.Path(sysconfig.get_path("platlib")) / "*.dll"
@@ -131,6 +139,10 @@ if THIS_IS_WINDOWS:
f"{ROOT}\\bladebit\\bladebit.exe",
"bladebit"
),
(
f"{ROOT}\\bladebit\\bladebit_cuda.exe",
"bladebit"
),
]
+122 -76
View File
@@ -1,8 +1,8 @@
#!/bin/bash
#!/usr/bin/env bash
set -o errexit
USAGE_TEXT="\
USAGE_TEXT="\\
Usage: $0 <bladebit|madmax> [-v VERSION | -h]
-v VERSION Specify the version of plotter to install
@@ -10,37 +10,90 @@ Usage: $0 <bladebit|madmax> [-v VERSION | -h]
"
usage() {
echo "${USAGE_TEXT}"
echo "$USAGE_TEXT"
}
# Check for necessary tools
if ! command -v wget &>/dev/null; then
echo "ERROR: wget could not be found. Please install wget and try again."
exit 1
fi
if ! command -v tar &>/dev/null; then
echo "ERROR: tar could not be found. Please install tar and try again."
exit 1
fi
# Function to download, extract, set permissions, and clean up
handle_binary() {
URL="$1"
ARTIFACT=$(basename "$URL")
FILENAME="$2"
BINARY_NAME="$3"
echo "Fetching binary from: ${URL}"
if wget -q "$URL"; then
echo "Successfully downloaded: ${ARTIFACT}"
if [[ "$FILENAME" == *.tar.gz ]]; then
tar zxf "$FILENAME"
rm -f "$FILENAME"
else
mv "$ARTIFACT" "$BINARY_NAME"
fi
chmod 755 ./"$BINARY_NAME"
echo -e "\nSuccessfully installed '${BINARY_NAME}' to:\n$PWD/${BINARY_NAME}\n"
else
echo -e "\nWARNING: Failed to download from ${URL}. Maybe specified version of the binary does not exist.\n"
fi
}
get_bladebit_filename() {
BLADEBIT_VER="$1" # e.g. v2.0.0-beta1
OS="$2" # "ubuntu", "centos", "macos"
ARCH="$3" # "x86-64", "arm64"
OS="$2" # "ubuntu", "centos", "macos"
ARCH="$3" # "x86-64", "arm64"
echo "bladebit-${BLADEBIT_VER}-${OS}-${ARCH}.tar.gz"
}
get_bladebit_cuda_filename() {
BLADEBIT_VER="$1" # e.g. v2.0.0-beta1
OS="$2" # "ubuntu", "centos", "macos"
ARCH="$3" # "x86-64", "arm64"
echo "bladebit-cuda-${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"
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}")"
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"
get_bladebit_cuda_url() {
BLADEBIT_VER="$1" # e.g. v2.0.0-beta1
OS="$2" # "ubuntu", "centos", "macos"
ARCH="$3" # "x86-64", "arm64"
CHIA_PLOT="chia_plot"
GITHUB_BASE_URL="https://github.com/Chia-Network/bladebit/releases/download"
BLADEBIT_CUDA_FILENAME="$(get_bladebit_cuda_filename "$BLADEBIT_VER" "$OS" "$ARCH")"
echo "${GITHUB_BASE_URL}/${BLADEBIT_VER}/${BLADEBIT_CUDA_FILENAME}"
}
get_madmax_filename() {
KSIZE="$1"
MADMAX_VER="$2"
OS="$3"
ARCH="$4"
export CHIA_PLOT="chia_plot"
if [ "$KSIZE" = "k34" ]; then
CHIA_PLOT="chia_plot_k34"
export CHIA_PLOT="chia_plot_k34"
fi
SUFFIX=""
if [ "$OS" = "macos" ]; then
@@ -51,26 +104,25 @@ get_madmax_filename() {
fi
SUFFIX="${OS}-${ARCH}"
else
SUFFIX="${ARCH}"
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"
KSIZE="$1"
MADMAX_VER="$2"
OS="$3"
ARCH="$4"
GITHUB_BASE_URL="https://github.com/Chia-Network/chia-plotter-madmax/releases/download"
MADMAX_FILENAME="$(get_madmax_filename "${KSIZE}" "${MADMAX_VER}" "${OS}" "${ARCH}")"
MADMAX_FILENAME="$(get_madmax_filename "$KSIZE" "$MADMAX_VER" "$OS" "$ARCH")"
echo "${GITHUB_BASE_URL}/${MADMAX_VER}/${MADMAX_FILENAME}"
}
if [ "$1" = "-h" ] || [ -z "$1" ]; then
if [ "$1" = "-h" ] || [ "$1" = "" ]; then
usage
exit 0
fi
@@ -81,25 +133,33 @@ 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;;
while getopts v:h flag; do
case "$flag" in
v) VERSION="$OPTARG" ;;
h)
usage
exit 0
;;
*)
echo
usage
exit 1
;;
esac
done
SCRIPT_DIR=$(cd -- "$(dirname -- "$0")"; pwd)
SCRIPT_DIR=$(
cd -- "$(dirname -- "$0")"
pwd
)
if [ "${SCRIPT_DIR}" != "$(pwd)" ]; then
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
if [ "$VIRTUAL_ENV" = "" ]; then
echo "This requires the chia python virtual environment."
echo "Execute '. ./activate' before running."
exit 1
@@ -113,24 +173,26 @@ 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"
elif [ -f /etc/os-release ]; then
OS=$(grep -oP '(?<=^ID=).+' /etc/os-release | tr -d '"')
if [ "$OS" == "arch" ]; then
OS="ubuntu"
fi
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"
echo "ERROR: $(uname) is not supported"
exit 1
fi
@@ -144,55 +206,39 @@ if [ ! -d "${VIRTUAL_ENV}/bin" ]; then
fi
cd "${VIRTUAL_ENV}/bin"
# Handle BladeBit and BladeBit CUDA binaries
if [ "$PLOTTER" = "bladebit" ]; then
if [ -z "$VERSION" ]; then
if [ "$VERSION" = "" ]; then
VERSION="$DEFAULT_BLADEBIT_VERSION"
fi
echo "Installing bladebit $VERSION"
echo -e "Installing bladebit $VERSION\n"
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"
# Regular bladebit binary
url="$(get_bladebit_url "$VERSION" "$OS" "$ARCH")"
bladebit_filename="$(get_bladebit_filename "$VERSION" "$OS" "$ARCH")"
handle_binary "$url" "$bladebit_filename" "bladebit"
# CUDA bladebit binary
url="$(get_bladebit_cuda_url "$VERSION" "$OS" "$ARCH")"
bladebit_cuda_filename="$(get_bladebit_cuda_filename "$VERSION" "$OS" "$ARCH")"
handle_binary "$url" "$bladebit_cuda_filename" "bladebit_cuda"
# Handle MadMax binaries
elif [ "$PLOTTER" = "madmax" ]; then
if [ -z "$VERSION" ]; then
if [ "$VERSION" = "" ]; then
VERSION="$DEFAULT_MADMAX_VERSION"
fi
echo "Installing madmax $VERSION"
echo -e "Installing madmax $VERSION\n"
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"
# k32 MadMax binary
url="$(get_madmax_url "k32" "$VERSION" "$OS" "$ARCH")"
madmax_filename="$(get_madmax_filename "k32" "$VERSION" "$OS" "$ARCH")"
handle_binary "$url" "$madmax_filename" "chia_plot"
# k34 MadMax binary
url="$(get_madmax_url "k34" "$VERSION" "$OS" "$ARCH")"
madmax_filename="$(get_madmax_filename "k34" "$VERSION" "$OS" "$ARCH")"
handle_binary "$url" "$madmax_filename" "chia_plot_k34"
else
usage
fi