From 3524ea2bd382b93792b0fe0938b20f90091a65cb Mon Sep 17 00:00:00 2001 From: RomanNum3ral Date: Sun, 28 Sep 2025 23:20:10 +0000 Subject: [PATCH] Add 03-stable_diffusion_install_v3.sh --- 03-stable_diffusion_install_v3.sh | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 03-stable_diffusion_install_v3.sh diff --git a/03-stable_diffusion_install_v3.sh b/03-stable_diffusion_install_v3.sh new file mode 100644 index 0000000..c24e350 --- /dev/null +++ b/03-stable_diffusion_install_v3.sh @@ -0,0 +1,58 @@ + #!/usr/bin/env bash + + set -euo pipefail + IFS=$'\n\t' + trap 'echo "[ERROR] Line ${LINENO}: command failed"; exit 1' ERR + + # Settings + TARGET_DIR="${1:-$HOME/sd-webui}" + PYTHON_BIN="${PYTHON_BIN:-python3}" + REPO_URL="https://github.com/AUTOMATIC1111/stable-diffusion-webui.git" + ENABLE_XFORMERS="${ENABLE_XFORMERS:-auto}" # auto|yes|no + + echo "[STEP] Creating target dir: $TARGET_DIR" + mkdir -p "$TARGET_DIR" + cd "$TARGET_DIR" + + if command -v apt >/dev/null 2>&1; then + echo "[STEP] Installing dependencies (APT)" + sudo apt-get update -y + sudo apt-get install -y git ${PYTHON_BIN} ${PYTHON_BIN}-venv build-essential ffmpeg + fi + + # GPU detection + GPU_VENDOR="cpu" + if command -v nvidia-smi >/dev/null 2>&1; then + GPU_VENDOR="nvidia" + echo "[INFO] Detected NVIDIA GPU" + nvidia-smi || true + else + if lspci | grep -qi 'amd/ati'; then GPU_VENDOR="amd"; fi + if lspci | grep -qi 'intel'; then GPU_VENDOR="intel"; fi + echo "[INFO] Detected GPU vendor: $GPU_VENDOR" + fi + + if [[ ! -d stable-diffusion-webui ]]; then + echo "[STEP] Cloning AUTOMATIC1111 webui" + git clone --depth=1 "$REPO_URL" + fi + cd stable-diffusion-webui + + echo "[STEP] Creating Python venv" + ${PYTHON_BIN} -m venv .venv + source .venv/bin/activate + + echo "[STEP] Upgrading pip" + pip install --upgrade pip wheel setuptools + + # Optional performance packages + if [[ "$GPU_VENDOR" == "nvidia" ]]; then + if [[ "$ENABLE_XFORMERS" == "yes" || "$ENABLE_XFORMERS" == "auto" ]]; then + echo "[STEP] Installing xformers (optional)" + pip install --extra-index-url https://download.pytorch.org/whl/cu121 xformers || true + fi + fi + + echo "[TIP] Place your models in: $TARGET_DIR/stable-diffusion-webui/models/Stable-diffusion" + echo "[RUN] To start: cd '$TARGET_DIR/stable-diffusion-webui' && source .venv/bin/activate && \ +python launch.py --xformers --opt-sdp-attention" \ No newline at end of file