From cc356ce67d23e03a471547ef6f66776b477de4bd Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Sat, 22 Oct 2022 23:24:13 +0530 Subject: [PATCH 01/31] Initial commit of the new micromamba-based installer; This should work seamlessly for new and existing users; Also allows the installer to run on mac (but the installation will fail because the mac-specific environment.yaml hasn't been added yet) --- scripts/Developer Console.cmd | 21 +++++++-- scripts/Start Stable Diffusion UI.cmd | 28 +++++++---- scripts/bootstrap.bat | 53 +++++++++++++++++++++ scripts/bootstrap.sh | 67 +++++++++++++++++++++++++++ scripts/developer_console.sh | 20 ++++++-- scripts/on_env_start.bat | 3 +- scripts/on_env_start.sh | 1 + scripts/on_sd_start.bat | 3 +- scripts/on_sd_start.sh | 6 ++- scripts/start.sh | 19 ++++++-- 10 files changed, 194 insertions(+), 27 deletions(-) create mode 100644 scripts/bootstrap.bat create mode 100644 scripts/bootstrap.sh diff --git a/scripts/Developer Console.cmd b/scripts/Developer Console.cmd index e9bfb28b..e088a51f 100644 --- a/scripts/Developer Console.cmd +++ b/scripts/Developer Console.cmd @@ -2,13 +2,24 @@ echo "Opening Stable Diffusion UI - Developer Console.." & echo. -@call installer\Scripts\activate.bat +set PATH=C:\Windows\System32;%PATH% -@call conda-unpack +@rem set legacy and new installer's PATH, if they exist +if exist "installer" set PATH=%cd%\installer;%cd%\installer\Library\bin;%cd%\installer\Scripts;%PATH% +if exist "installer_files\env" set PATH=%cd%\installer_files\env;%cd%\installer_files\env\Library\bin;%cd%\installer_files\env\Scripts;%PATH% -@call conda --version -@call git --version +@rem Test the environment +echo "Environment Info:" +call where git +call git --version -@call conda activate .\stable-diffusion\env +call where python +call python --version + +call where conda +call conda --version + +@rem activate the environment +call conda activate .\stable-diffusion\env cmd /k \ No newline at end of file diff --git a/scripts/Start Stable Diffusion UI.cmd b/scripts/Start Stable Diffusion UI.cmd index 8563f6b3..3a8100da 100644 --- a/scripts/Start Stable Diffusion UI.cmd +++ b/scripts/Start Stable Diffusion UI.cmd @@ -1,19 +1,27 @@ @echo off -@REM Delete the post-activate hook from the old installer -if exist "installer\etc\conda\activate.d\post_activate.bat" ( - echo. > installer\etc\conda\activate.d\post_activate.bat -) +set PATH=C:\Windows\System32;%PATH% -@call installer\Scripts\activate.bat +@rem set legacy installer's PATH, if it exists +if exist "installer" set PATH=%cd%\installer;%cd%\installer\Library\bin;%cd%\installer\Scripts;%PATH% -@call conda-unpack +@rem Setup the packages required for the installer +call scripts\bootstrap.bat -@call conda --version -@call git --version +@rem set new installer's PATH, if it downloaded any packages +if exist "installer_files\env" set PATH=%cd%\installer_files\env;%cd%\installer_files\env\Library\bin;%cd%\installer_files\env\Scripts;%PATH% -@cd installer +@rem Test the bootstrap +call where git +call git --version -@call ..\scripts\on_env_start.bat +call where python +call python --version + +call where conda +call conda --version + +@rem Download the rest of the installer and UI +call scripts\on_env_start.bat @pause diff --git a/scripts/bootstrap.bat b/scripts/bootstrap.bat new file mode 100644 index 00000000..8a231deb --- /dev/null +++ b/scripts/bootstrap.bat @@ -0,0 +1,53 @@ +@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 This enables a user to install this project without manually installing conda and git. + +@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 + +@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;%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 + +@rem (if necessary) install git and conda into a contained environment +if "%PACKAGES_TO_INSTALL%" NEQ "" ( + @rem download micromamba + if not exist "%MAMBA_ROOT_PREFIX%\micromamba.exe" ( + 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 + ) +) diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh new file mode 100644 index 00000000..da39f4c5 --- /dev/null +++ b/scripts/bootstrap.sh @@ -0,0 +1,67 @@ +#!/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. + + +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 + +# 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" + +# 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 necessary) install git and conda into a contained environment +if [ "$PACKAGES_TO_INSTALL" != "" ]; then + # download micromamba + if [ ! -e "$MAMBA_ROOT_PREFIX/micromamba" ]; 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 "$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 installing$PACKAGES_TO_INSTALL using micromamba. Cannot continue." + exit + fi +fi diff --git a/scripts/developer_console.sh b/scripts/developer_console.sh index d242d1f6..1fe016a9 100755 --- a/scripts/developer_console.sh +++ b/scripts/developer_console.sh @@ -4,13 +4,25 @@ if [ "$0" == "bash" ]; then echo "Opening Stable Diffusion UI - Developer Console.." echo "" - source installer/bin/activate + # set legacy and new installer's PATH, if they exist + if [ -e "installer" ]; then export PATH="$(pwd)/installer/bin:$PATH"; fi + if [ -e "installer_files/env" ]; then export PATH="$(pwd)/installer_files/env/bin:$PATH"; fi - conda-unpack - - conda --version + # test the environment + echo "Environment Info:" + which git git --version + which python + python --version + + which conda + conda --version + + # activate 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 ./stable-diffusion/env else bash --init-file developer_console.sh diff --git a/scripts/on_env_start.bat b/scripts/on_env_start.bat index 0c8eb327..eb5aa06c 100644 --- a/scripts/on_env_start.bat +++ b/scripts/on_env_start.bat @@ -4,8 +4,6 @@ set PATH=C:\Windows\System32;%PATH% -@cd .. - if exist "scripts\config.bat" ( @call scripts\config.bat ) @@ -54,6 +52,7 @@ if "%update_branch%"=="" ( @xcopy sd-ui-files\ui ui /s /i /Y @copy sd-ui-files\scripts\on_sd_start.bat scripts\ /Y +@copy sd-ui-files\scripts\bootstrap.bat scripts\ /Y @copy "sd-ui-files\scripts\Start Stable Diffusion UI.cmd" . /Y @copy "sd-ui-files\scripts\Developer Console.cmd" . /Y diff --git a/scripts/on_env_start.sh b/scripts/on_env_start.sh index 5c574e4c..eff27e57 100755 --- a/scripts/on_env_start.sh +++ b/scripts/on_env_start.sh @@ -36,6 +36,7 @@ fi rm -rf ui cp -Rf sd-ui-files/ui . cp sd-ui-files/scripts/on_sd_start.sh scripts/ +cp sd-ui-files/scripts/bootstrap.sh scripts/ cp sd-ui-files/scripts/start.sh . cp sd-ui-files/scripts/developer_console.sh . diff --git a/scripts/on_sd_start.bat b/scripts/on_sd_start.bat index feb73468..94ba6a89 100644 --- a/scripts/on_sd_start.bat +++ b/scripts/on_sd_start.bat @@ -1,11 +1,12 @@ @echo off @copy sd-ui-files\scripts\on_env_start.bat scripts\ /Y +@copy sd-ui-files\scripts\bootstrap.bat scripts\ /Y @REM Caution, this file will make your eyes and brain bleed. It's such an unholy mess. @REM Note to self: Please rewrite this in Python. For the sake of your own sanity. -@copy "sd-ui-files\scripts\Developer Console.cmd" . /Y +@REM remove the old version of the dev console script, if it's still present if exist "Open Developer Console.cmd" del "Open Developer Console.cmd" @call python -c "import os; import shutil; frm = 'sd-ui-files\\ui\\hotfix\\9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142'; dst = os.path.join(os.path.expanduser('~'), '.cache', 'huggingface', 'transformers', '9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142'); shutil.copyfile(frm, dst) if os.path.exists(dst) else print(''); print('Hotfixed broken JSON file from OpenAI');" diff --git a/scripts/on_sd_start.sh b/scripts/on_sd_start.sh index e949dfcb..964ea051 100755 --- a/scripts/on_sd_start.sh +++ b/scripts/on_sd_start.sh @@ -1,10 +1,12 @@ #!/bin/bash cp sd-ui-files/scripts/on_env_start.sh scripts/ +cp sd-ui-files/scripts/bootstrap.sh scripts/ -source installer/etc/profile.d/conda.sh +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) -cp sd-ui-files/scripts/developer_console.sh . +# remove the old version of the dev console script, if it's still present if [ -e "open_dev_console.sh" ]; then rm "open_dev_console.sh" fi diff --git a/scripts/start.sh b/scripts/start.sh index e077593a..e5981434 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,10 +1,23 @@ #!/bin/bash -source installer/bin/activate +# set legacy installer's PATH, if it exists +if [ -e "installer" ]; then export PATH="$(pwd)/installer/bin:$PATH"; fi -conda-unpack +# Setup the packages required for the installer +scripts/bootstrap.sh -conda --version +# set new installer's PATH, if it downloaded any packages +if [ -e "installer_files/env" ]; then export PATH="$(pwd)/installer_files/env/bin:$PATH"; fi + +# Test the bootstrap +which git git --version +which python +python --version + +which conda +conda --version + +# Download the rest of the installer and UI scripts/on_env_start.sh From e8d61225f53a6e27ef64176851c485c0029a0d41 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Sat, 22 Oct 2022 23:26:59 +0530 Subject: [PATCH 02/31] Make the linux installer executable --- scripts/bootstrap.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/bootstrap.sh diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh old mode 100644 new mode 100755 From 338c2243e36bcf2e57a8300ce2b1406d7d4379bf Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Sat, 22 Oct 2022 23:28:43 +0530 Subject: [PATCH 03/31] Newline after printing env info in developer scripts --- scripts/Developer Console.cmd | 2 ++ scripts/developer_console.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/scripts/Developer Console.cmd b/scripts/Developer Console.cmd index e088a51f..288f2b8c 100644 --- a/scripts/Developer Console.cmd +++ b/scripts/Developer Console.cmd @@ -19,6 +19,8 @@ call python --version call where conda call conda --version +echo. + @rem activate the environment call conda activate .\stable-diffusion\env diff --git a/scripts/developer_console.sh b/scripts/developer_console.sh index 1fe016a9..53e4ed59 100755 --- a/scripts/developer_console.sh +++ b/scripts/developer_console.sh @@ -19,6 +19,8 @@ if [ "$0" == "bash" ]; then which conda conda --version + echo "" + # activate 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) From 3772137c8f1b783ef363ca6e4d783aa139e6e776 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Sun, 23 Oct 2022 10:23:43 +0530 Subject: [PATCH 04/31] Include usr/bin in the installer PATH; newlines at the end of all files --- scripts/Developer Console.cmd | 6 +++--- scripts/Start Stable Diffusion UI.cmd | 4 ++-- scripts/bootstrap.bat | 2 +- scripts/developer_console.sh | 2 +- scripts/on_env_start.bat | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/Developer Console.cmd b/scripts/Developer Console.cmd index 288f2b8c..81676136 100644 --- a/scripts/Developer Console.cmd +++ b/scripts/Developer Console.cmd @@ -5,8 +5,8 @@ echo "Opening Stable Diffusion UI - Developer Console.." & echo. set PATH=C:\Windows\System32;%PATH% @rem set legacy and new installer's PATH, if they exist -if exist "installer" set PATH=%cd%\installer;%cd%\installer\Library\bin;%cd%\installer\Scripts;%PATH% -if exist "installer_files\env" set PATH=%cd%\installer_files\env;%cd%\installer_files\env\Library\bin;%cd%\installer_files\env\Scripts;%PATH% +if exist "installer" set PATH=%cd%\installer;%cd%\installer\Library\bin;%cd%\installer\Scripts;%cd%\installer\Library\usr\bin;%PATH% +if exist "installer_files\env" set PATH=%cd%\installer_files\env;%cd%\installer_files\env\Library\bin;%cd%\installer_files\env\Scripts;%cd%\installer_files\Library\usr\bin;%PATH% @rem Test the environment echo "Environment Info:" @@ -24,4 +24,4 @@ echo. @rem activate the environment call conda activate .\stable-diffusion\env -cmd /k \ No newline at end of file +cmd /k diff --git a/scripts/Start Stable Diffusion UI.cmd b/scripts/Start Stable Diffusion UI.cmd index 3a8100da..428da218 100644 --- a/scripts/Start Stable Diffusion UI.cmd +++ b/scripts/Start Stable Diffusion UI.cmd @@ -3,13 +3,13 @@ set PATH=C:\Windows\System32;%PATH% @rem set legacy installer's PATH, if it exists -if exist "installer" set PATH=%cd%\installer;%cd%\installer\Library\bin;%cd%\installer\Scripts;%PATH% +if exist "installer" set PATH=%cd%\installer;%cd%\installer\Library\bin;%cd%\installer\Scripts;%cd%\installer\Library\usr\bin;%PATH% @rem Setup the packages required for the installer call scripts\bootstrap.bat @rem set new installer's PATH, if it downloaded any packages -if exist "installer_files\env" set PATH=%cd%\installer_files\env;%cd%\installer_files\env\Library\bin;%cd%\installer_files\env\Scripts;%PATH% +if exist "installer_files\env" set PATH=%cd%\installer_files\env;%cd%\installer_files\env\Library\bin;%cd%\installer_files\env\Scripts;%cd%\installer_files\Library\usr\bin;%PATH% @rem Test the bootstrap call where git diff --git a/scripts/bootstrap.bat b/scripts/bootstrap.bat index 8a231deb..26d74b52 100644 --- a/scripts/bootstrap.bat +++ b/scripts/bootstrap.bat @@ -12,7 +12,7 @@ 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 @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;%PATH% +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= diff --git a/scripts/developer_console.sh b/scripts/developer_console.sh index 53e4ed59..b9f1341e 100755 --- a/scripts/developer_console.sh +++ b/scripts/developer_console.sh @@ -28,4 +28,4 @@ if [ "$0" == "bash" ]; then conda activate ./stable-diffusion/env else bash --init-file developer_console.sh -fi \ No newline at end of file +fi diff --git a/scripts/on_env_start.bat b/scripts/on_env_start.bat index eb5aa06c..4d402fdc 100644 --- a/scripts/on_env_start.bat +++ b/scripts/on_env_start.bat @@ -58,4 +58,4 @@ if "%update_branch%"=="" ( @call scripts\on_sd_start.bat -@pause \ No newline at end of file +@pause From 6f3c66278380bcb3e13d4cab9526146922ad1258 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Sun, 23 Oct 2022 10:28:27 +0530 Subject: [PATCH 05/31] Bump version --- ui/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/index.html b/ui/index.html index fdaf42af..63646123 100644 --- a/ui/index.html +++ b/ui/index.html @@ -18,7 +18,7 @@