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-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-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-10-12 16:45:38 +00:00
|
|
|
if ! hash "conda" &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL conda"; fi
|
2022-10-12 11:23:07 +00:00
|
|
|
if ! hash "git" &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL git"; 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
|
|
|
|
if [ ! -e "$MAMBA_ROOT_PREFIX/micromamba" ]; then
|
|
|
|
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 16:45:38 +00:00
|
|
|
git config --global init.defaultBranch main
|
2022-10-12 11:08:06 +00:00
|
|
|
git init
|
|
|
|
git remote add origin https://github.com/cmdr2/InvokeAI.git
|
|
|
|
git fetch
|
|
|
|
git checkout origin/main -ft
|
|
|
|
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-10-13 04:27:14 +00:00
|
|
|
PIP_EXISTS_ACTION=w CONDA_SUBDIR=osx-${OS_ARCH} conda env create -f environment-mac.yml
|
2022-10-12 11:08:06 +00:00
|
|
|
else
|
2022-10-12 17:31:08 +00:00
|
|
|
conda env create -f environment.yml
|
2022-10-12 11:08:06 +00:00
|
|
|
fi
|
|
|
|
|
2022-10-12 16:45:38 +00:00
|
|
|
conda activate invokeai
|
2022-10-12 11:08:06 +00:00
|
|
|
|
|
|
|
# preload the models
|
|
|
|
python scripts/preload_models.py
|
|
|
|
|
|
|
|
# make the models dir
|
2022-10-12 16:45:38 +00:00
|
|
|
mkdir models/ldm/stable-diffusion-v1
|
|
|
|
|
|
|
|
# tell the user that they need to download the ckpt
|
|
|
|
WEIGHTS_DOC_URL="https://invoke-ai.github.io/InvokeAI/installation/INSTALL_LINUX/"
|
|
|
|
if [ "$OS_NAME" == "mac" ]; then
|
|
|
|
WEIGHTS_DOC_URL="https://invoke-ai.github.io/InvokeAI/installation/INSTALL_MAC/"
|
|
|
|
fi
|
|
|
|
|
2022-10-13 04:30:53 +00:00
|
|
|
echo ""
|
2022-10-12 16:45:38 +00:00
|
|
|
echo "Now you need to install the weights for the stable diffusion model."
|
|
|
|
echo "Please follow the steps at $WEIGHTS_DOC_URL to complete the installation"
|
|
|
|
|
|
|
|
# it would be nice if the weights downloaded automatically, and didn't need the user to do this manually.
|