diff --git a/installer/create_installers.sh b/installer/create_installers.sh new file mode 100755 index 0000000000..1b1d634ca6 --- /dev/null +++ b/installer/create_installers.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +cd "$(dirname "${BASH_SOURCE[0]}")" + +# make the installer zip for linux and mac +rm -rf invokeAI +mkdir -p invokeAI +cp install.sh invokeAI +cp readme.txt invokeAI + +zip -r invokeAI-linux.zip invokeAI +zip -r invokeAI-mac.zip invokeAI + +# make the installer zip for windows +rm -rf invokeAI +mkdir -p invokeAI +cp install.bat invokeAI +cp readme.txt invokeAI + +zip -r invokeAI-windows.zip invokeAI + +echo "The installer zips are ready to be distributed.." diff --git a/installer/install.bat b/installer/install.bat new file mode 100644 index 0000000000..508c9ced4f --- /dev/null +++ b/installer/install.bat @@ -0,0 +1,92 @@ +@echo off + +@rem This script will install git and conda (if not found on the PATH variable) +@rem using micromamba (an 8mb static-linked single-file binary, conda replacement). +@rem For users who already have git and conda, this step will be skipped. + +@rem Next, it'll checkout the project's git repo, if necessary. +@rem Finally, it'll create the conda environment and preload the models. + +@rem This enables a user to install this project without manually installing conda and git. + +echo "Installing InvokeAI.." +echo. + +@rem config +set MAMBA_ROOT_PREFIX=%cd%\installer_files\mamba +set INSTALL_ENV_DIR=%cd%\installer_files\env +set MICROMAMBA_DOWNLOAD_URL=https://github.com/cmdr2/stable-diffusion-ui/releases/download/v1.1/micromamba.exe +set REPO_URL=https://github.com/cmdr2/InvokeAI.git +set umamba_exists=F +@rem Change the download URL to an InvokeAI repo's release URL + +@rem figure out whether git and conda needs to be installed +if exist "%INSTALL_ENV_DIR%" set PATH=%INSTALL_ENV_DIR%;%INSTALL_ENV_DIR%\Library\bin;%INSTALL_ENV_DIR%\Scripts;%INSTALL_ENV_DIR%\Library\usr\bin;%PATH% + +set PACKAGES_TO_INSTALL= + +call conda --version >.tmp1 2>.tmp2 +if "%ERRORLEVEL%" NEQ "0" set PACKAGES_TO_INSTALL=%PACKAGES_TO_INSTALL% conda + +call git --version >.tmp1 2>.tmp2 +if "%ERRORLEVEL%" NEQ "0" set PACKAGES_TO_INSTALL=%PACKAGES_TO_INSTALL% git + +call "%MAMBA_ROOT_PREFIX%\micromamba.exe" --version >.tmp1 2>.tmp2 +if "%ERRORLEVEL%" EQU "0" set umamba_exists=T + +@rem (if necessary) install git and conda into a contained environment +if "%PACKAGES_TO_INSTALL%" NEQ "" ( + @rem download micromamba + if "%umamba_exists%" == "F" ( + echo "Downloading micromamba from %MICROMAMBA_DOWNLOAD_URL% to %MAMBA_ROOT_PREFIX%\micromamba.exe" + + mkdir "%MAMBA_ROOT_PREFIX%" + call curl -L "%MICROMAMBA_DOWNLOAD_URL%" > "%MAMBA_ROOT_PREFIX%\micromamba.exe" + + @rem test the mamba binary + echo Micromamba version: + call "%MAMBA_ROOT_PREFIX%\micromamba.exe" --version + ) + + @rem create the installer env + if not exist "%INSTALL_ENV_DIR%" ( + call "%MAMBA_ROOT_PREFIX%\micromamba.exe" create -y --prefix "%INSTALL_ENV_DIR%" + ) + + echo "Packages to install:%PACKAGES_TO_INSTALL%" + + call "%MAMBA_ROOT_PREFIX%\micromamba.exe" install -y --prefix "%INSTALL_ENV_DIR%" -c conda-forge %PACKAGES_TO_INSTALL% + + if not exist "%INSTALL_ENV_DIR%" ( + echo "There was a problem while installing%PACKAGES_TO_INSTALL% using micromamba. Cannot continue." + pause + exit /b + ) +) + +set PATH=%INSTALL_ENV_DIR%;%INSTALL_ENV_DIR%\Library\bin;%INSTALL_ENV_DIR%\Scripts;%INSTALL_ENV_DIR%\Library\usr\bin;%PATH% + +@rem get the repo (and load into the current directory) +if not exist ".git" ( + call git config --global init.defaultBranch main + call git init + call git remote add origin %REPO_URL% + call git fetch + call git checkout origin/main -ft +) + +@rem activate the base env +call conda activate + +@rem create the environment +call conda env create +call conda activate invokeai + +@rem preload the models +call python scripts\preload_models.py + +@rem tell the user their next steps +echo. +echo "You can now start generating images by double-clicking the 'invoke.bat' file (inside this folder) + +pause diff --git a/installer/install.sh b/installer/install.sh new file mode 100755 index 0000000000..ea576ddda9 --- /dev/null +++ b/installer/install.sh @@ -0,0 +1,111 @@ +#!/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. + +# Next, it'll checkout the project's git repo, if necessary. +# Finally, it'll create the conda environment and preload the models. + +# This enables a user to install this project without manually installing conda and git. + +cd "$(dirname "${BASH_SOURCE[0]}")" + +echo "Installing InvokeAI.." +echo "" + +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 + 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 + +# 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" +MICROMAMBA_DOWNLOAD_URL="https://micro.mamba.pm/api/micromamba/${OS_NAME}-${OS_ARCH}/latest" +REPO_URL="https://github.com/cmdr2/InvokeAI.git" +umamba_exists="F" + +# figure out whether git and conda needs to be installed +if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$INSTALL_ENV_DIR/bin:$PATH"; fi + +PACKAGES_TO_INSTALL="" + +if ! hash "conda" &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL conda"; fi +if ! hash "git" &>/dev/null; then PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL git"; fi + +if "$MAMBA_ROOT_PREFIX/micromamba" --version &>/dev/null; then umamba_exists="T"; fi + +# (if necessary) install git and conda into a contained environment +if [ "$PACKAGES_TO_INSTALL" != "" ]; then + # download micromamba + if [ "$umamba_exists" == "F" ]; then + echo "Downloading micromamba from $MICROMAMBA_DOWNLOAD_URL to $MAMBA_ROOT_PREFIX/micromamba" + + mkdir -p "$MAMBA_ROOT_PREFIX" + curl -L "$MICROMAMBA_DOWNLOAD_URL" | tar -xvj bin/micromamba -O > "$MAMBA_ROOT_PREFIX/micromamba" + + chmod u+x "$MAMBA_ROOT_PREFIX/micromamba" + + # test the mamba binary + echo "Micromamba version:" + "$MAMBA_ROOT_PREFIX/micromamba" --version + fi + + # create the installer env + if [ ! -e "$INSTALL_ENV_DIR" ]; then + "$MAMBA_ROOT_PREFIX/micromamba" create -y --prefix "$INSTALL_ENV_DIR" + fi + + echo "Packages to install:$PACKAGES_TO_INSTALL" + + "$MAMBA_ROOT_PREFIX/micromamba" install -y --prefix "$INSTALL_ENV_DIR" -c conda-forge $PACKAGES_TO_INSTALL + + if [ ! -e "$INSTALL_ENV_DIR" ]; then + echo "There was a problem while initializing micromamba. Cannot continue." + exit + fi +fi + +if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$INSTALL_ENV_DIR/bin:$PATH"; fi + +# get the repo (and load into the current directory) +if [ ! -e ".git" ]; then + git config --global init.defaultBranch main + git init + git remote add origin "$REPO_URL" + git fetch + git checkout origin/main -ft +fi + +# create the environment +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) + +conda activate + +if [ "$OS_NAME" == "mac" ]; then + PIP_EXISTS_ACTION=w CONDA_SUBDIR=osx-${OS_ARCH} conda env create -f environment-mac.yml +else + conda env create -f environment.yml +fi + +conda activate invokeai + +# preload the models +python scripts/preload_models.py + +# tell the user their next steps +echo "You can now start generating images by running invoke.sh (inside this folder), using ./invoke.sh" diff --git a/installer/readme.txt b/installer/readme.txt new file mode 100644 index 0000000000..a5b8537a39 --- /dev/null +++ b/installer/readme.txt @@ -0,0 +1,11 @@ +InvokeAI + +Project homepage: https://github.com/invoke-ai/InvokeAI + +Installation on Windows: + Please double-click the 'install.bat' file (while keeping it inside the invokeAI folder). + +Installation on Linux and Mac: + Please open the terminal, and run './install.sh' (while keeping it inside the invokeAI folder). + +After installation, please run the 'invoke.bat' file (on Windows) or 'invoke.sh' file (on Linux/Mac) to start InvokeAI. \ No newline at end of file diff --git a/invoke.bat b/invoke.bat new file mode 100644 index 0000000000..62a1adb7c6 --- /dev/null +++ b/invoke.bat @@ -0,0 +1,29 @@ +@echo off + +set INSTALL_ENV_DIR=%cd%\installer_files\env +set PATH=%INSTALL_ENV_DIR%;%INSTALL_ENV_DIR%\Library\bin;%INSTALL_ENV_DIR%\Scripts;%INSTALL_ENV_DIR%\Library\usr\bin;%PATH% + +call conda activate invokeai + +echo Do you want to generate images using the +echo 1. command-line +echo 2. browser-based UI +echo 3. open the developer console +set /P restore="Please enter 1, 2 or 3: " +IF /I "%restore%" == "1" ( + echo Starting the InvokeAI command-line.. + python scripts\invoke.py +) ELSE IF /I "%restore%" == "2" ( + echo Starting the InvokeAI browser-based UI.. + python scripts\invoke.py --web +) ELSE IF /I "%restore%" == "3" ( + echo Developer Console + call where python + call python --version + + cmd /k +) ELSE ( + echo Invalid selection + pause + exit /b +) diff --git a/invoke.sh b/invoke.sh new file mode 100755 index 0000000000..55a0292e6e --- /dev/null +++ b/invoke.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +cd "$(dirname "${BASH_SOURCE[0]}")" + +INSTALL_ENV_DIR="$(pwd)/installer_files/env" +if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$INSTALL_ENV_DIR/bin:$PATH"; fi + +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) + +conda activate invokeai + +if [ "$0" != "bash" ]; then + echo "Do you want to generate images using the" + echo "1. command-line" + echo "2. browser-based UI" + echo "3. open the developer console" + read -p "Please enter 1, 2, or 3: " yn + case $yn in + 1 ) printf "\nStarting the InvokeAI command-line..\n"; python scripts/invoke.py;; + 2 ) printf "\nStarting the InvokeAI browser-based UI..\n"; python scripts/invoke.py --web;; + 3 ) printf "\nDeveloper Console:\n"; file_name=$(basename "${BASH_SOURCE[0]}"); bash --init-file "$file_name";; + * ) echo "Invalid selection"; exit;; + esac +else # in developer console + which python + python --version +fi diff --git a/update.bat b/update.bat new file mode 100644 index 0000000000..9beda82d0f --- /dev/null +++ b/update.bat @@ -0,0 +1,13 @@ +@echo off + +set INSTALL_ENV_DIR=%cd%\installer_files\env +set PATH=%INSTALL_ENV_DIR%;%INSTALL_ENV_DIR%\Library\bin;%INSTALL_ENV_DIR%\Scripts;%INSTALL_ENV_DIR%\Library\usr\bin;%PATH% + +@rem update the repo +if exist ".git" ( + call git pull +) + +conda env update + +pause diff --git a/update.sh b/update.sh new file mode 100755 index 0000000000..edf7756015 --- /dev/null +++ b/update.sh @@ -0,0 +1,22 @@ +#!/bin/bash + + +INSTALL_ENV_DIR="$(pwd)/installer_files/env" +if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$INSTALL_ENV_DIR/bin:$PATH"; fi + +# update the repo +if [ -e ".git" ]; then + git pull +fi + +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) + +conda activate invokeai + +OS_NAME=$(uname -s) +case "${OS_NAME}" in + Linux*) conda env update;; + Darwin*) conda env update -f environment-mac.yml;; + *) echo "Unknown OS: $OS_NAME! This script runs only on Linux or Mac" && exit +esac