2022-10-12 11:08:06 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-10-12 16:45:38 +00:00
|
|
|
# This script will install git and conda (if not found on the PATH variable)
|
2022-10-12 11:08:06 +00:00
|
|
|
# using micromamba (an 8mb static-linked single-file binary, conda replacement).
|
2022-10-12 16:45:38 +00:00
|
|
|
# For users who already have git and conda, this step will be skipped.
|
2022-10-12 11:08:06 +00:00
|
|
|
|
|
|
|
# Next, it'll checkout the project's git repo, if necessary.
|
|
|
|
# Finally, it'll create the conda environment and preload the models.
|
|
|
|
|
2022-10-12 16:45:38 +00:00
|
|
|
# This enables a user to install this project without manually installing conda and git.
|
2022-10-12 11:08:06 +00:00
|
|
|
|
2022-10-29 14:17:55 +00:00
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
|
|
|
|
2022-10-26 10:05:42 +00:00
|
|
|
echo "Installing InvokeAI.."
|
|
|
|
echo ""
|
2022-10-14 03:26:27 +00:00
|
|
|
|
2022-10-12 11:08:06 +00:00
|
|
|
OS_NAME=$(uname -s)
|
|
|
|
case "${OS_NAME}" in
|
|
|
|
Linux*) OS_NAME="linux";;
|
|
|
|
Darwin*) OS_NAME="mac";;
|
|
|
|
*) echo "Unknown OS: $OS_NAME! This script runs only on Linux or Mac" && exit
|
|
|
|
esac
|
|
|
|
|
|
|
|
OS_ARCH=$(uname -m)
|
|
|
|
case "${OS_ARCH}" in
|
2022-10-26 10:00:48 +00:00
|
|
|
x86_64*) OS_ARCH="64";;
|
2022-10-12 11:08:06 +00:00
|
|
|
arm64*) OS_ARCH="arm64";;
|
|
|
|
*) echo "Unknown system architecture: $OS_ARCH! This script runs only on x86_64 or arm64" && exit
|
|
|
|
esac
|
|
|
|
|
2022-10-26 10:00:48 +00:00
|
|
|
# https://mamba.readthedocs.io/en/latest/installation.html
|
|
|
|
if [ "$OS_NAME" == "linux" ] && [ "$OS_ARCH" == "arm64" ]; then OS_ARCH="aarch64"; fi
|
|
|
|
|
2022-10-12 11:08:06 +00:00
|
|
|
# config
|
|
|
|
export MAMBA_ROOT_PREFIX="$(pwd)/installer_files/mamba"
|
|
|
|
INSTALL_ENV_DIR="$(pwd)/installer_files/env"
|
2022-10-26 10:00:48 +00:00
|
|
|
MICROMAMBA_DOWNLOAD_URL="https://micro.mamba.pm/api/micromamba/${OS_NAME}-${OS_ARCH}/latest"
|
2022-10-30 16:13:11 +00:00
|
|
|
REPO_URL="https://github.com/invoke-ai/InvokeAI.git"
|
2022-10-29 14:17:55 +00:00
|
|
|
umamba_exists="F"
|
2022-10-12 11:08:06 +00:00
|
|
|
|
2022-10-12 16:45:38 +00:00
|
|
|
# figure out whether git and conda needs to be installed
|
2022-10-26 10:00:48 +00:00
|
|
|
if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$INSTALL_ENV_DIR/bin:$PATH"; fi
|
|
|
|
|
2022-10-12 11:23:07 +00:00
|
|
|
PACKAGES_TO_INSTALL=""
|
|
|
|
|
2022-11-08 21:20:44 +00:00
|
|
|
if ! command conda &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL conda"; fi
|
|
|
|
if ! command git &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL git"; fi
|
2022-10-12 11:23:07 +00:00
|
|
|
|
2022-10-29 14:17:55 +00:00
|
|
|
if "$MAMBA_ROOT_PREFIX/micromamba" --version &>/dev/null; then umamba_exists="T"; fi
|
|
|
|
|
2022-10-12 16:45:38 +00:00
|
|
|
# (if necessary) install git and conda into a contained environment
|
2022-10-12 11:08:06 +00:00
|
|
|
if [ "$PACKAGES_TO_INSTALL" != "" ]; then
|
2022-10-26 10:00:48 +00:00
|
|
|
# download micromamba
|
2022-10-29 14:17:55 +00:00
|
|
|
if [ "$umamba_exists" == "F" ]; then
|
2022-10-26 10:00:48 +00:00
|
|
|
echo "Downloading micromamba from $MICROMAMBA_DOWNLOAD_URL to $MAMBA_ROOT_PREFIX/micromamba"
|
|
|
|
|
2022-10-12 16:45:38 +00:00
|
|
|
mkdir -p "$MAMBA_ROOT_PREFIX"
|
2022-10-26 10:00:48 +00:00
|
|
|
curl -L "$MICROMAMBA_DOWNLOAD_URL" | tar -xvj bin/micromamba -O > "$MAMBA_ROOT_PREFIX/micromamba"
|
|
|
|
|
|
|
|
chmod u+x "$MAMBA_ROOT_PREFIX/micromamba"
|
2022-10-12 16:45:38 +00:00
|
|
|
|
|
|
|
# test the mamba binary
|
|
|
|
echo "Micromamba version:"
|
|
|
|
"$MAMBA_ROOT_PREFIX/micromamba" --version
|
|
|
|
fi
|
2022-10-12 11:08:06 +00:00
|
|
|
|
2022-10-12 16:45:38 +00:00
|
|
|
# create the installer env
|
2022-10-12 11:08:06 +00:00
|
|
|
if [ ! -e "$INSTALL_ENV_DIR" ]; then
|
2022-10-12 16:45:38 +00:00
|
|
|
"$MAMBA_ROOT_PREFIX/micromamba" create -y --prefix "$INSTALL_ENV_DIR"
|
2022-10-12 11:08:06 +00:00
|
|
|
fi
|
|
|
|
|
2022-10-12 16:45:38 +00:00
|
|
|
echo "Packages to install:$PACKAGES_TO_INSTALL"
|
2022-10-12 11:08:06 +00:00
|
|
|
|
2022-10-12 16:45:38 +00:00
|
|
|
"$MAMBA_ROOT_PREFIX/micromamba" install -y --prefix "$INSTALL_ENV_DIR" -c conda-forge $PACKAGES_TO_INSTALL
|
2022-10-14 04:43:41 +00:00
|
|
|
|
|
|
|
if [ ! -e "$INSTALL_ENV_DIR" ]; then
|
|
|
|
echo "There was a problem while initializing micromamba. Cannot continue."
|
|
|
|
exit
|
|
|
|
fi
|
2022-10-12 11:08:06 +00:00
|
|
|
fi
|
|
|
|
|
2022-10-13 05:26:04 +00:00
|
|
|
if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$INSTALL_ENV_DIR/bin:$PATH"; fi
|
2022-10-12 16:45:38 +00:00
|
|
|
|
2022-10-12 11:08:06 +00:00
|
|
|
# get the repo (and load into the current directory)
|
2022-10-12 17:26:28 +00:00
|
|
|
if [ ! -e ".git" ]; then
|
2022-10-12 11:08:06 +00:00
|
|
|
git init
|
2022-11-08 19:44:44 +00:00
|
|
|
git config --local init.defaultBranch main
|
2022-10-26 10:08:49 +00:00
|
|
|
git remote add origin "$REPO_URL"
|
2022-10-12 11:08:06 +00:00
|
|
|
git fetch
|
2022-11-08 12:56:36 +00:00
|
|
|
git checkout origin/release-candidate-2-1-3 -ft
|
2022-10-12 11:08:06 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# create the environment
|
2022-10-13 04:27:14 +00:00
|
|
|
CONDA_BASEPATH=$(conda info --base)
|
|
|
|
source "$CONDA_BASEPATH/etc/profile.d/conda.sh" # otherwise conda complains about 'shell not initialized' (needed when running in a script)
|
|
|
|
|
2022-10-26 10:00:48 +00:00
|
|
|
conda activate
|
|
|
|
|
2022-10-12 11:08:06 +00:00
|
|
|
if [ "$OS_NAME" == "mac" ]; then
|
2022-11-08 21:21:25 +00:00
|
|
|
PIP_EXISTS_ACTION=w CONDA_SUBDIR=osx-${OS_ARCH} conda env update -f environment-mac.yml
|
2022-10-12 11:08:06 +00:00
|
|
|
else
|
2022-11-08 21:21:25 +00:00
|
|
|
conda env update -f environment.yml
|
2022-10-12 11:08:06 +00:00
|
|
|
fi
|
|
|
|
|
2022-11-01 17:54:42 +00:00
|
|
|
status=$?
|
2022-10-12 11:08:06 +00:00
|
|
|
|
2022-11-01 16:02:22 +00:00
|
|
|
if test $status -ne 0
|
|
|
|
then
|
2022-11-01 17:54:42 +00:00
|
|
|
echo "Something went wrong while installing Python libraries and cannot continue."
|
2022-11-01 16:02:22 +00:00
|
|
|
echo "Please visit https://invoke-ai.github.io/InvokeAI/#installation for alternative"
|
|
|
|
echo "installation methods"
|
|
|
|
else
|
|
|
|
conda activate invokeai
|
|
|
|
# preload the models
|
|
|
|
echo "Calling the preload_models.py script"
|
|
|
|
python scripts/preload_models.py
|
2022-11-01 17:54:42 +00:00
|
|
|
status=$?
|
|
|
|
if test $status -ne 0
|
2022-11-01 16:02:22 +00:00
|
|
|
then
|
|
|
|
echo "The preload_models.py script crashed or was cancelled."
|
2022-11-02 19:26:02 +00:00
|
|
|
echo "InvokeAI is not ready to run. Try again by running"
|
|
|
|
echo "update.sh in this directory."
|
2022-11-01 16:02:22 +00:00
|
|
|
else
|
|
|
|
# tell the user their next steps
|
|
|
|
echo "You can now start generating images by running invoke.sh (inside this folder), using ./invoke.sh"
|
2022-11-01 17:54:42 +00:00
|
|
|
fi
|
2022-11-08 21:20:44 +00:00
|
|
|
fi
|
2022-11-01 17:54:42 +00:00
|
|
|
|
|
|
|
conda activate invokeai
|