2020-05-22 06:00:08 +03:00
#!/bin/bash
2021-02-21 23:01:52 +03:00
2022-03-17 19:13:27 +03:00
set -o errexit
2022-04-08 19:58:46 +03:00
USAGE_TEXT = " \
Usage: $0 [ -d]
-n do not install Python development package, Python.h etc
-h display this help and exit
"
usage( ) {
echo " ${ USAGE_TEXT } "
}
INSTALL_PYTHON_DEV = 1
while getopts nh flag
do
case " ${ flag } " in
# development
n) INSTALL_PYTHON_DEV = ; ;
h) usage; exit 0; ;
*) echo; usage; exit 1; ;
esac
done
2021-02-21 23:01:52 +03:00
if [ -z " $VIRTUAL_ENV " ] ; then
echo "This requires the chia python virtual environment."
echo "Execute '. ./activate' before running."
exit 1
fi
2021-05-12 23:12:30 +03:00
echo "Timelord requires CMake 3.14+ to compile vdf_client."
2020-05-21 01:59:57 +03:00
2020-05-22 06:00:08 +03:00
PYTHON_VERSION = $( python -c 'import sys; print(f"python{sys.version_info.major}.{sys.version_info.minor}")' )
echo " Python version: $PYTHON_VERSION "
2020-05-21 01:59:57 +03:00
2022-04-08 19:58:46 +03:00
if [ " $INSTALL_PYTHON_DEV " ] ; then
PYTHON_DEV_DEPENDENCY = lib" $PYTHON_VERSION " -dev
else
PYTHON_DEV_DEPENDENCY =
fi
2020-04-18 02:17:36 +03:00
export BUILD_VDF_BENCH = Y # Installs the useful vdf_bench test of CPU squaring speed
2020-11-01 05:35:04 +03:00
THE_PATH = $( python -c 'import pkg_resources; print( pkg_resources.get_distribution("chiavdf").location)' 2>/dev/null) /vdf_client
2022-09-16 23:58:11 +03:00
CHIAVDF_VERSION = $( python -c 'import os; os.environ["CHIA_SKIP_SETUP"] = "1"; from setup import dependencies; t = [_ for _ in dependencies if _.startswith("chiavdf")][0]; print(t)' )
2020-04-06 03:52:34 +03:00
2020-05-22 06:00:08 +03:00
ubuntu_cmake_install( ) {
2023-07-22 01:29:34 +03:00
UBUNTU_PRE_2004 = $( python -c 'import subprocess; id = subprocess.run(["lsb_release", "-is"], stdout=subprocess.PIPE); version = subprocess.run(["lsb_release", "-rs"], stdout=subprocess.PIPE); print(id.stdout.decode("ascii") == "Ubuntu\n" and float(version.stdout) < float(20.04))' )
2020-11-01 05:35:04 +03:00
if [ " $UBUNTU_PRE_2004 " = "True" ] ; then
2022-03-23 02:19:32 +03:00
echo "Installing CMake with snap."
sudo apt-get install snapd -y
2020-11-01 05:35:04 +03:00
sudo apt-get remove --purge cmake -y
hash -r
sudo snap install cmake --classic
2023-01-20 02:00:41 +03:00
# shellcheck disable=SC1091
2022-03-23 02:19:32 +03:00
. /etc/profile
2020-11-01 05:35:04 +03:00
else
echo "Ubuntu 20.04LTS and newer support CMake 3.16+"
sudo apt-get install cmake -y
fi
2020-05-22 06:00:08 +03:00
}
symlink_vdf_bench( ) {
2020-11-01 05:35:04 +03:00
if [ ! -e vdf_bench ] && [ -e venv/lib/" $1 " /site-packages/vdf_bench ] ; then
echo ln -s venv/lib/" $1 " /site-packages/vdf_bench
ln -s venv/lib/" $1 " /site-packages/vdf_bench .
elif [ ! -e venv/lib/" $1 " /site-packages/vdf_bench ] ; then
echo " ERROR: Could not find venv/lib/ $1 /site-packages/vdf_bench "
else
2021-05-12 23:12:30 +03:00
echo "./vdf_bench link exists."
2020-11-01 05:35:04 +03:00
fi
2020-05-22 06:00:08 +03:00
}
if [ " $( uname) " = "Linux" ] && type apt-get; then
2020-11-01 05:35:04 +03:00
UBUNTU_DEBIAN = true
2021-05-12 23:12:30 +03:00
echo "Found Ubuntu/Debian."
2023-08-15 20:53:39 +03:00
2021-03-30 03:59:01 +03:00
elif [ " $( uname) " = "Linux" ] && type dnf || yum; then
RHEL_BASED = true
2021-05-12 23:12:30 +03:00
echo "Found RedHat."
2023-08-15 20:53:39 +03:00
if [ " $INSTALL_PYTHON_DEV " ] ; then
yumcmd = " sudo yum install $PYTHON_VERSION -devel gcc gcc-c++ gmp-devel libtool make autoconf automake openssl-devel libevent-devel boost-devel python3 cmake -y "
else
yumcmd = "sudo yum install gcc gcc-c++ gmp-devel libtool make autoconf automake openssl-devel libevent-devel boost-devel python3 cmake -y"
fi
2020-05-22 06:00:08 +03:00
elif [ " $( uname) " = "Darwin" ] ; then
2020-11-01 05:35:04 +03:00
MACOS = true
2021-05-12 23:12:30 +03:00
echo "Found MacOS."
2020-04-06 03:43:03 +03:00
fi
2023-08-15 20:53:39 +03:00
2020-05-22 06:00:08 +03:00
if [ -e " $THE_PATH " ] ; then
2020-11-01 05:35:04 +03:00
echo " $THE_PATH "
echo "vdf_client already exists, no action taken"
2020-03-28 01:59:25 +03:00
else
2023-01-20 02:00:41 +03:00
if [ -e venv/bin/python ] && test " $UBUNTU_DEBIAN " ; then
2022-04-12 20:51:29 +03:00
echo "Installing chiavdf dependencies on Ubuntu/Debian"
2020-11-01 05:35:04 +03:00
# If Ubuntu version is older than 20.04LTS then upgrade CMake
ubuntu_cmake_install
# Install remaining needed development tools - assumes venv and prior run of install.sh
2022-04-12 20:51:29 +03:00
echo " apt-get install libgmp-dev libboost-python-dev $PYTHON_DEV_DEPENDENCY libboost-system-dev build-essential -y "
2022-04-08 19:58:46 +03:00
sudo apt-get install libgmp-dev libboost-python-dev " $PYTHON_DEV_DEPENDENCY " libboost-system-dev build-essential -y
2022-04-12 20:51:29 +03:00
echo "Installing chiavdf from source on Ubuntu/Debian"
2020-11-01 05:35:04 +03:00
echo venv/bin/python -m pip install --force --no-binary chiavdf " $CHIAVDF_VERSION "
venv/bin/python -m pip install --force --no-binary chiavdf " $CHIAVDF_VERSION "
2021-03-30 03:59:01 +03:00
symlink_vdf_bench " $PYTHON_VERSION "
2023-01-20 02:00:41 +03:00
elif [ -e venv/bin/python ] && test " $RHEL_BASED " ; then
2022-04-12 20:51:29 +03:00
echo "Installing chiavdf dependencies on RedHat/CentOS/Fedora"
2021-03-30 03:59:01 +03:00
# Install remaining needed development tools - assumes venv and prior run of install.sh
2023-08-15 20:53:39 +03:00
echo " $yumcmd "
${ yumcmd }
2022-04-12 20:51:29 +03:00
echo "Installing chiavdf from source on RedHat/CentOS/Fedora"
2021-03-30 03:59:01 +03:00
echo venv/bin/python -m pip install --force --no-binary chiavdf " $CHIAVDF_VERSION "
venv/bin/python -m pip install --force --no-binary chiavdf " $CHIAVDF_VERSION "
2020-11-01 05:35:04 +03:00
symlink_vdf_bench " $PYTHON_VERSION "
2023-01-20 02:00:41 +03:00
elif [ -e venv/bin/python ] && test " $MACOS " ; then
2022-04-12 20:51:29 +03:00
echo "Installing chiavdf dependencies for MacOS."
brew install boost cmake gmp
2021-05-12 23:12:30 +03:00
echo "Installing chiavdf from source."
2020-11-01 05:35:04 +03:00
# User needs to provide required packages
echo venv/bin/python -m pip install --force --no-binary chiavdf " $CHIAVDF_VERSION "
venv/bin/python -m pip install --force --no-binary chiavdf " $CHIAVDF_VERSION "
symlink_vdf_bench " $PYTHON_VERSION "
elif [ -e venv/bin/python ] ; then
2021-05-12 23:12:30 +03:00
echo "Installing chiavdf from source."
2020-11-01 05:35:04 +03:00
# User needs to provide required packages
echo venv/bin/python -m pip install --force --no-binary chiavdf " $CHIAVDF_VERSION "
venv/bin/python -m pip install --force --no-binary chiavdf " $CHIAVDF_VERSION "
symlink_vdf_bench " $PYTHON_VERSION "
else
2021-05-12 23:12:30 +03:00
echo "No venv created yet, please run install.sh."
2020-11-01 05:35:04 +03:00
fi
2020-03-28 01:59:25 +03:00
fi
2021-05-12 23:12:30 +03:00
echo "To estimate a timelord on this CPU try './vdf_bench square_asm 400000' for an ips estimate."