Add 03-stable_diffusion_install_v3.sh

This commit is contained in:
RomanNum3ral 2025-09-28 23:20:10 +00:00
parent 85e48b687f
commit 3524ea2bd3
1 changed files with 58 additions and 0 deletions

View File

@ -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"