2024-07-24 21:23:29 -04:00
|
|
|
#!/usr/bin/env bash
|
2023-09-21 18:35:53 -04:00
|
|
|
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
|
|
|
|
|
|
|
if [[ "$(pwd)" =~ " " ]]; then echo This script relies on Miniconda which can not be silently installed under a path with spaces. && exit; fi
|
|
|
|
|
2023-09-21 22:52:29 -04:00
|
|
|
# deactivate existing conda envs as needed to avoid conflicts
|
|
|
|
{ conda deactivate && conda deactivate && conda deactivate; } 2> /dev/null
|
|
|
|
|
2023-09-21 18:35:53 -04:00
|
|
|
OS_ARCH=$(uname -m)
|
|
|
|
case "${OS_ARCH}" in
|
|
|
|
x86_64*) OS_ARCH="x86_64";;
|
|
|
|
arm64*) OS_ARCH="aarch64";;
|
|
|
|
aarch64*) OS_ARCH="aarch64";;
|
|
|
|
*) echo "Unknown system architecture: $OS_ARCH! This script runs only on x86_64 or arm64" && exit
|
|
|
|
esac
|
|
|
|
|
|
|
|
# config
|
|
|
|
INSTALL_DIR="$(pwd)/installer_files"
|
|
|
|
CONDA_ROOT_PREFIX="$(pwd)/installer_files/conda"
|
|
|
|
INSTALL_ENV_DIR="$(pwd)/installer_files/env"
|
|
|
|
MINICONDA_DOWNLOAD_URL="https://repo.anaconda.com/miniconda/Miniconda3-py310_23.3.1-0-Linux-${OS_ARCH}.sh"
|
|
|
|
conda_exists="F"
|
|
|
|
|
|
|
|
# figure out whether git and conda needs to be installed
|
|
|
|
if "$CONDA_ROOT_PREFIX/bin/conda" --version &>/dev/null; then conda_exists="T"; fi
|
|
|
|
|
|
|
|
# (if necessary) install git and conda into a contained environment
|
|
|
|
# download miniconda
|
|
|
|
if [ "$conda_exists" == "F" ]; then
|
|
|
|
echo "Downloading Miniconda from $MINICONDA_DOWNLOAD_URL to $INSTALL_DIR/miniconda_installer.sh"
|
|
|
|
|
|
|
|
mkdir -p "$INSTALL_DIR"
|
2024-02-25 00:35:23 -05:00
|
|
|
curl -L "$MINICONDA_DOWNLOAD_URL" > "$INSTALL_DIR/miniconda_installer.sh"
|
2023-09-21 18:35:53 -04:00
|
|
|
|
|
|
|
chmod u+x "$INSTALL_DIR/miniconda_installer.sh"
|
|
|
|
bash "$INSTALL_DIR/miniconda_installer.sh" -b -p $CONDA_ROOT_PREFIX
|
|
|
|
|
|
|
|
# test the conda binary
|
|
|
|
echo "Miniconda version:"
|
|
|
|
"$CONDA_ROOT_PREFIX/bin/conda" --version
|
2024-03-04 11:11:03 -05:00
|
|
|
|
|
|
|
# delete the Miniconda installer
|
|
|
|
rm "$INSTALL_DIR/miniconda_installer.sh"
|
2023-09-21 18:35:53 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# create the installer env
|
|
|
|
if [ ! -e "$INSTALL_ENV_DIR" ]; then
|
2023-10-21 02:46:23 -04:00
|
|
|
"$CONDA_ROOT_PREFIX/bin/conda" create -y -k --prefix "$INSTALL_ENV_DIR" python=3.11
|
2023-09-21 18:35:53 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# check if conda environment was actually created
|
|
|
|
if [ ! -e "$INSTALL_ENV_DIR/bin/python" ]; then
|
|
|
|
echo "Conda environment is empty."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# environment isolation
|
|
|
|
export PYTHONNOUSERSITE=1
|
|
|
|
unset PYTHONPATH
|
|
|
|
unset PYTHONHOME
|
|
|
|
export CUDA_PATH="$INSTALL_ENV_DIR"
|
|
|
|
export CUDA_HOME="$CUDA_PATH"
|
|
|
|
|
|
|
|
# activate installer env
|
|
|
|
source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains about 'shell not initialized' (needed when running in a script)
|
|
|
|
conda activate "$INSTALL_ENV_DIR"
|
|
|
|
|
|
|
|
# setup installer env
|
2023-09-22 15:00:06 -04:00
|
|
|
python one_click.py $@
|