2022-09-13 07:28:04 -06:00
|
|
|
#!/bin/bash
|
|
|
|
#################################################
|
|
|
|
# Please do not make any changes to this file, #
|
|
|
|
# change the variables in webui-user.sh instead #
|
|
|
|
#################################################
|
|
|
|
# Read variables from webui-user.sh
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
if [[ -f webui-user.sh ]]
|
|
|
|
then
|
|
|
|
source ./webui-user.sh
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set defaults
|
|
|
|
# Install directory without trailing slash
|
|
|
|
if [[ -z "${install_dir}" ]]
|
|
|
|
then
|
|
|
|
install_dir="/home/$(whoami)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Name of the subdirectory (defaults to stable-diffusion-webui)
|
|
|
|
if [[ -z "${clone_dir}" ]]
|
|
|
|
then
|
|
|
|
clone_dir="stable-diffusion-webui"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# python3 executable
|
|
|
|
if [[ -z "${python_cmd}" ]]
|
|
|
|
then
|
|
|
|
python_cmd="python3"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# git executable
|
2022-09-13 09:28:54 -06:00
|
|
|
if [[ -z "${GIT}" ]]
|
2022-09-13 07:28:04 -06:00
|
|
|
then
|
2022-09-13 09:28:54 -06:00
|
|
|
export GIT="git"
|
2022-09-13 07:28:04 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
# python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv)
|
|
|
|
if [[ -z "${venv_dir}" ]]
|
|
|
|
then
|
|
|
|
venv_dir="venv"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Do not reinstall existing pip packages on Debian/Ubuntu
|
|
|
|
export PIP_IGNORE_INSTALLED=0
|
|
|
|
|
|
|
|
# Pretty print
|
|
|
|
delimiter="################################################################"
|
|
|
|
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
printf "\e[1m\e[32mInstall script for stable-diffusion + Web UI\n"
|
|
|
|
printf "\e[1m\e[34mTested on Debian 11 (Bullseye)\e[0m"
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
|
|
|
|
# Do not run as root
|
|
|
|
if [[ $(id -u) -eq 0 ]]
|
|
|
|
then
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
printf "\e[1m\e[31mERROR: This script must not be launched as root, aborting...\e[0m"
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
printf "Running on \e[1m\e[32m%s\e[0m user" "$(whoami)"
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -d .git ]]
|
|
|
|
then
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
printf "Repo already cloned, using it as install directory"
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
install_dir="${PWD}/../"
|
|
|
|
clone_dir="${PWD##*/}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check prequisites
|
|
|
|
for preq in git python3
|
|
|
|
do
|
|
|
|
if ! hash "${preq}" &>/dev/null
|
|
|
|
then
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
printf "\e[1m\e[31mERROR: %s is not installed, aborting...\e[0m" "${preq}"
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if ! "${python_cmd}" -c "import venv" &>/dev/null
|
|
|
|
then
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
printf "\e[1m\e[31mERROR: python3-venv is not installed, aborting...\e[0m"
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
printf "Clone or update stable-diffusion-webui"
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
cd "${install_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/, aborting...\e[0m" "${install_dir}"; exit 1; }
|
|
|
|
if [[ -d "${clone_dir}" ]]
|
|
|
|
then
|
|
|
|
cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
|
2022-09-13 09:28:54 -06:00
|
|
|
"${GIT}" pull
|
2022-09-13 07:28:04 -06:00
|
|
|
else
|
2022-09-13 09:28:54 -06:00
|
|
|
"${GIT}" clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git "${clone_dir}"
|
2022-09-13 07:28:04 -06:00
|
|
|
cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
printf "Create and activate python venv"
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
cd "${install_dir}"/"${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; }
|
|
|
|
if [[ ! -d "${venv_dir}" ]]
|
|
|
|
then
|
|
|
|
"${python_cmd}" -m venv "${venv_dir}"
|
|
|
|
first_launch=1
|
|
|
|
fi
|
|
|
|
# shellcheck source=/dev/null
|
2022-09-13 09:28:54 -06:00
|
|
|
if [[ -f "${venv_dir}"/bin/activate ]]
|
2022-09-13 07:28:04 -06:00
|
|
|
then
|
2022-09-13 09:28:54 -06:00
|
|
|
source "${venv_dir}"/bin/activate
|
2022-09-13 07:28:04 -06:00
|
|
|
else
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
printf "\e[1m\e[31mERROR: Cannot activate python venv, aborting...\e[0m"
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "\n%s\n" "${delimiter}"
|
2022-09-13 09:28:54 -06:00
|
|
|
printf "Launching launch.py..."
|
2022-09-13 07:28:04 -06:00
|
|
|
printf "\n%s\n" "${delimiter}"
|
2022-09-13 09:28:54 -06:00
|
|
|
"${python_cmd}" launch.py
|