diff --git a/installer/create_installers.sh b/installer/create_installers.sh new file mode 100644 index 0000000..70290ea --- /dev/null +++ b/installer/create_installers.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# For developers only! Not for users! +# This creates the installer zip files that will be distributed to users +# It packs install.{sh,bat} along with a readme, and ensures that the user +# has the install script inside a new empty folder (after unzipping), +# otherwise the git repo will extract into whatever folder the script is in. + +cd "$(dirname "${BASH_SOURCE[0]}")" + +# make the installer zip for linux and mac +rm -rf sygil +mkdir -p sygil +cp install.sh sygil +cp readme.txt sygil + +zip -r sygil-linux.zip sygil +zip -r sygil-mac.zip sygil + +# make the installer zip for windows +rm -rf sygil +mkdir -p sygil +cp install.bat sygil +cp readme.txt sygil + +zip -r sygil-windows.zip sygil + +echo "The installer zips are ready to be distributed.." diff --git a/installer/install.bat b/installer/install.bat new file mode 100644 index 0000000..973c6c8 --- /dev/null +++ b/installer/install.bat @@ -0,0 +1,96 @@ +@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 Then, it'll run the webui.cmd file to continue with the installation as usual. + +@rem This enables a user to install this project without manually installing conda and git. + +echo "Installing Sygil WebUI.." +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/Sygil-Dev/sygil-webui.git +@rem Change the download URL to Sygil repo's release URL +@rem We need to mirror micromamba.exe, because the official download URL uses tar.bz2 compression +@rem which Windows can't unzip natively. +@rem https://mamba.readthedocs.io/en/latest/installation.html#windows +set umamba_exists=F + +@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 master + call git init + call git remote add origin %REPO_URL% + call git fetch + call git checkout origin/master -ft +) + +@rem activate the base env +call conda activate + +@rem make the models dir +mkdir models\ldm\stable-diffusion-v1 + +@rem install the project +call webui.cmd + +@rem finally, tell the user that they need to download the ckpt +echo. +echo "Now you need to install the weights for the stable diffusion model." +echo "Please follow the steps related to models weights at https://sd-webui.github.io/stable-diffusion-webui/docs/1.windows-installation.html#cloning-the-repo to complete the installation" + +@rem it would be nice if the weights downloaded automatically, and didn't need the user to do this manually. + +pause diff --git a/installer/install.sh b/installer/install.sh new file mode 100755 index 0000000..432cd0c --- /dev/null +++ b/installer/install.sh @@ -0,0 +1,90 @@ +#!/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. + +# Then, it'll run the webui.cmd file to continue with the installation as usual. + +# This enables a user to install this project without manually installing conda and git. + +cd "$(dirname "${BASH_SOURCE[0]}")" + +echo "Installing Sygil WebUI.." +echo "" + +OS_ARCH=$(uname -m) +case "${OS_ARCH}" in + x86_64*) OS_ARCH="64";; + arm64*) OS_ARCH="aarch64";; + *) echo "Unknown system architecture: $OS_ARCH! This script runs only on x86_64 or arm64" && exit +esac + +# 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/linux-${OS_ARCH}/latest" +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 + +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 + +# run the installer script for linux +curl "https://raw.githubusercontent.com/JoshuaKimsey/Linux-StableDiffusion-Script/main/linux-sd.sh" > linux-sd.sh +chmod u+x linux-sd.sh + +./linux-sd.sh + +# tell the user that they need to download the ckpt +WEIGHTS_DOC_URL="https://sd-webui.github.io/stable-diffusion-webui/docs/2.linux-installation.html#initial-start-guide" + +echo "" +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. diff --git a/installer/readme.txt b/installer/readme.txt new file mode 100644 index 0000000..d73a027 --- /dev/null +++ b/installer/readme.txt @@ -0,0 +1,11 @@ +Sygil WebUI + +Project homepage: https://github.com/Sygil-Dev/sygil-webui + +Installation on Windows: + Please double-click the 'install.bat' file (while keeping it inside the sygil folder). + +Installation on Linux: + Please open the terminal, and run './install.sh' (while keeping it inside the sygil folder). + +After installation, please run the 'webui.cmd' file (on Windows) or 'webui.sh' file (on Linux/Mac) to start Sygil. \ No newline at end of file diff --git a/webui.cmd b/webui.cmd index 8765daa..3c31081 100644 --- a/webui.cmd +++ b/webui.cmd @@ -31,7 +31,11 @@ IF EXIST custom-conda-path.txt ( FOR /F %%i IN (custom-conda-path.txt) DO set v_custom_path=%%i ) -set v_paths=%ProgramData%\miniconda3 +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% + +set v_paths=%INSTALL_ENV_DIR% +set v_paths=%v_paths%;%ProgramData%\miniconda3 set v_paths=%v_paths%;%USERPROFILE%\miniconda3 set v_paths=%v_paths%;%ProgramData%\anaconda3 set v_paths=%v_paths%;%USERPROFILE%\anaconda3 diff --git a/webui.sh b/webui.sh index a6d4205..66c6fd5 100755 --- a/webui.sh +++ b/webui.sh @@ -24,6 +24,9 @@ ENV_MODIFIED=$(date -r $ENV_FILE "+%s") ENV_MODIFED_FILE=".env_updated" ENV_UPDATED=0 +INSTALL_ENV_DIR="$(pwd)/../installer_files/env" # since linux-sd.sh clones the repo into a subfolder +if [ -e "$INSTALL_ENV_DIR" ]; then export PATH="$INSTALL_ENV_DIR/bin:$PATH"; fi + # Models used for upscaling GFPGAN_MODEL="https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth" LATENT_DIFFUSION_REPO="https://github.com/devilismyfriend/latent-diffusion.git" @@ -50,6 +53,11 @@ conda_env_setup () { CUSTOM_CONDA_PATH=$(cat custom-conda-path.txt) fi + # If a custom conda isn't specified, and the installer downloaded conda for the user, then use that + if [ -f "$INSTALL_ENV_DIR/etc/profile.d/conda.sh" ] && [ "$CUSTOM_CONDA_PATH" == "" ]; then + . "$INSTALL_ENV_DIR/etc/profile.d/conda.sh" + fi + # If custom path is set above, try to setup conda environment if [ -f "${CUSTOM_CONDA_PATH}/etc/profile.d/conda.sh" ]; then . "${CUSTOM_CONDA_PATH}/etc/profile.d/conda.sh"