2022-10-22 19:54:13 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# This script will install git and conda (if not found on the PATH variable)
|
|
|
|
# using micromamba (an 8mb static-linked single-file binary, conda replacement).
|
|
|
|
# For users who already have git and conda, this step will be skipped.
|
|
|
|
|
|
|
|
# This enables a user to install this project without manually installing conda and git.
|
|
|
|
|
2022-11-05 18:59:59 +01:00
|
|
|
source ./scripts/functions.sh
|
|
|
|
|
|
|
|
set -o pipefail
|
2022-10-22 19:54:13 +02:00
|
|
|
|
|
|
|
OS_NAME=$(uname -s)
|
|
|
|
case "${OS_NAME}" in
|
|
|
|
Linux*) OS_NAME="linux";;
|
|
|
|
Darwin*) OS_NAME="osx";;
|
|
|
|
*) echo "Unknown OS: $OS_NAME! This script runs only on Linux or Mac" && exit
|
|
|
|
esac
|
|
|
|
|
|
|
|
OS_ARCH=$(uname -m)
|
|
|
|
case "${OS_ARCH}" in
|
|
|
|
x86_64*) OS_ARCH="64";;
|
|
|
|
arm64*) OS_ARCH="arm64";;
|
|
|
|
*) echo "Unknown system architecture: $OS_ARCH! This script runs only on x86_64 or arm64" && exit
|
|
|
|
esac
|
|
|
|
|
2023-01-19 00:40:20 +01:00
|
|
|
if ! which curl; then fail "'curl' not found. Please install curl."; fi
|
|
|
|
if ! which tar; then fail "'tar' not found. Please install tar."; fi
|
|
|
|
if ! which bzip2; then fail "'bzip2' not found. Please install bzip2."; fi
|
|
|
|
|
|
|
|
if pwd | grep ' '; then fail "The installation directory's path contains a space character. Conda will fail to install. Please change the directory."; fi
|
|
|
|
if ! cat /proc/cpuinfo | grep avx | uniq; then fail "Your CPU doesn't support AVX."; fi
|
|
|
|
|
2022-10-22 19:54:13 +02:00
|
|
|
# https://mamba.readthedocs.io/en/latest/installation.html
|
|
|
|
if [ "$OS_NAME" == "linux" ] && [ "$OS_ARCH" == "arm64" ]; then OS_ARCH="aarch64"; fi
|
|
|
|
|
|
|
|
# config
|
|
|
|
export MAMBA_ROOT_PREFIX="$(pwd)/installer_files/mamba"
|
|
|
|
INSTALL_ENV_DIR="$(pwd)/installer_files/env"
|
2022-10-23 11:32:03 +02:00
|
|
|
LEGACY_INSTALL_ENV_DIR="$(pwd)/installer"
|
2022-10-22 19:54:13 +02:00
|
|
|
MICROMAMBA_DOWNLOAD_URL="https://micro.mamba.pm/api/micromamba/${OS_NAME}-${OS_ARCH}/latest"
|
2022-10-29 16:11:52 +02:00
|
|
|
umamba_exists="F"
|
2022-10-22 19:54:13 +02:00
|
|
|
|
|
|
|
# figure out whether git and conda needs to be installed
|
|
|
|
if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$INSTALL_ENV_DIR/bin:$PATH"; fi
|
|
|
|
|
2022-10-23 08:06:31 +02:00
|
|
|
PACKAGES_TO_INSTALL=""
|
2022-10-22 19:54:13 +02:00
|
|
|
|
2022-12-24 10:27:57 +01:00
|
|
|
if [ ! -e "$LEGACY_INSTALL_ENV_DIR/etc/profile.d/conda.sh" ] && [ ! -e "$INSTALL_ENV_DIR/etc/profile.d/conda.sh" ]; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL conda python=3.8.5"; fi
|
2022-10-22 19:54:13 +02:00
|
|
|
if ! hash "git" &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL git"; fi
|
|
|
|
|
2022-10-29 16:11:52 +02:00
|
|
|
if "$MAMBA_ROOT_PREFIX/micromamba" --version &>/dev/null; then umamba_exists="T"; fi
|
|
|
|
|
2022-10-22 19:54:13 +02:00
|
|
|
# (if necessary) install git and conda into a contained environment
|
|
|
|
if [ "$PACKAGES_TO_INSTALL" != "" ]; then
|
|
|
|
# download micromamba
|
2022-10-29 16:11:52 +02:00
|
|
|
if [ "$umamba_exists" == "F" ]; then
|
2022-10-22 19:54:13 +02:00
|
|
|
echo "Downloading micromamba from $MICROMAMBA_DOWNLOAD_URL to $MAMBA_ROOT_PREFIX/micromamba"
|
|
|
|
|
|
|
|
mkdir -p "$MAMBA_ROOT_PREFIX"
|
2023-02-10 22:34:52 +01:00
|
|
|
curl -L "$MICROMAMBA_DOWNLOAD_URL" | tar -xvj -O bin/micromamba > "$MAMBA_ROOT_PREFIX/micromamba"
|
2022-11-12 08:17:39 +01:00
|
|
|
|
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
echo
|
|
|
|
echo "EE micromamba download failed"
|
|
|
|
echo "EE If the lines above contain 'bzip2: Cannot exec', your system doesn't have bzip2 installed"
|
|
|
|
echo "EE If there are network errors, please check your internet setup"
|
|
|
|
fail "micromamba download failed"
|
|
|
|
fi
|
2022-10-22 19:54:13 +02:00
|
|
|
|
2022-10-23 07:08:01 +02:00
|
|
|
chmod u+x "$MAMBA_ROOT_PREFIX/micromamba"
|
|
|
|
|
2022-10-22 19:54:13 +02:00
|
|
|
# test the mamba binary
|
|
|
|
echo "Micromamba version:"
|
|
|
|
"$MAMBA_ROOT_PREFIX/micromamba" --version
|
|
|
|
fi
|
|
|
|
|
|
|
|
# create the installer env
|
|
|
|
if [ ! -e "$INSTALL_ENV_DIR" ]; then
|
2022-11-05 18:59:59 +01:00
|
|
|
"$MAMBA_ROOT_PREFIX/micromamba" create -y --prefix "$INSTALL_ENV_DIR" || fail "unable to create the install environment"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -e "$INSTALL_ENV_DIR" ]; then
|
|
|
|
fail "There was a problem while installing$PACKAGES_TO_INSTALL using micromamba. Cannot continue."
|
2022-10-22 19:54:13 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Packages to install:$PACKAGES_TO_INSTALL"
|
|
|
|
|
|
|
|
"$MAMBA_ROOT_PREFIX/micromamba" install -y --prefix "$INSTALL_ENV_DIR" -c conda-forge $PACKAGES_TO_INSTALL
|
2022-11-05 18:59:59 +01:00
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
fail "Installation of the packages '$PACKAGES_TO_INSTALL' failed."
|
2022-10-22 19:54:13 +02:00
|
|
|
fi
|
|
|
|
fi
|