Last active
July 23, 2025 19:42
-
-
Save doggeddalle/0bf1b600b76f4a17f42031970f245f87 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "--- ComfyUI Installation Script ---" | |
| # --- Configuration --- | |
| COMFYUI_DIR=$(pwd) | |
| VENV_DIR="${COMFYUI_DIR}/venv" | |
| COMFYUI_REPO="https://github.com/comfyanonymous/ComfyUI.git" | |
| COMFYUI_MANAGER_REPO="https://github.com/Comfy-Org/ComfyUI-Manager.git" | |
| # Specific PyTorch index URL for stable CUDA | |
| PYTORCH_CUDA_INDEX_URL="https://download.pytorch.org/whl/cu128" | |
| # --- Helper Functions --- | |
| # Function to check if a Python module is importable within the activated venv | |
| check_module_import() { | |
| local module_name="$1" | |
| if [ -z "${VIRTUAL_ENV}" ]; then | |
| echo "Error: Virtual environment not activated. Cannot check module import for ${module_name}." | |
| return 1 | |
| fi | |
| python -c "import ${module_name}" &> /dev/null | |
| return $? | |
| } | |
| # Function to check if PyTorch is installed and CUDA enabled | |
| check_pytorch_cuda() { | |
| if [ -z "${VIRTUAL_ENV}" ]; then | |
| echo "Error: Virtual environment not activated. Cannot check PyTorch CUDA status." | |
| return 1 | |
| fi | |
| python -c " | |
| import torch | |
| if torch.cuda.is_available(): | |
| print('PyTorch with CUDA is available.') | |
| else: | |
| raise RuntimeError('PyTorch CUDA is not available.') | |
| " &> /dev/null | |
| return $? | |
| } | |
| # --- Prerequisites Check --- | |
| echo "" | |
| echo "Checking for essential build tools..." | |
| if ! command -v git &> /dev/null; then | |
| echo "Error: git is not installed. Please install it, for example: 'sudo pacman -S git'." | |
| exit 1 | |
| fi | |
| if ! command -v python &> /dev/null; then | |
| echo "The 'python' command is not installed. Attempting to install it via pacman..." | |
| echo "This is exclusive to Arch Linux. You may be prompted for your password." | |
| sudo pacman -S --noconfirm python | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to install Python with pacman." | |
| echo "Please install it manually and re-run the script. Example: 'sudo pacman -S python'" | |
| exit 1 | |
| fi | |
| echo "Python installed successfully." | |
| fi | |
| if ! command -v cmake &> /dev/null; then | |
| echo "cmake is not installed. Attempting to install it via pacman..." | |
| echo "This is exclusive to Arch Linux. You may be prompted for your password." | |
| sudo pacman -S --noconfirm cmake | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to install cmake with pacman." | |
| echo "Please install it manually and re-run the script. Example: 'sudo pacman -S cmake'" | |
| exit 1 | |
| fi | |
| echo "cmake installed successfully." | |
| fi | |
| if ! pkg-config --exists sentencepiece &> /dev/null; then | |
| echo "The 'sentencepiece' system library is not installed. Attempting to install it via pacman..." | |
| echo "This is exclusive to Arch Linux. You may be prompted for your password." | |
| sudo pacman -S --noconfirm sentencepiece | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to install sentencepiece with pacman." | |
| echo "Please install it manually and re-run the script. Example: 'sudo pacman -S sentencepiece'" | |
| exit 1 | |
| fi | |
| echo "sentencepiece installed successfully." | |
| fi | |
| # --- ComfyUI Cloning --- | |
| echo "" | |
| echo "ComfyUI repository setup..." | |
| if [ ! -d "${COMFYUI_DIR}/ComfyUI" ]; then | |
| git clone "${COMFYUI_REPO}" "${COMFYUI_DIR}/ComfyUI" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to clone ComfyUI repository." | |
| exit 1 | |
| fi | |
| else | |
| echo "ComfyUI directory already exists. Pulling latest changes." | |
| (cd "${COMFYUI_DIR}/ComfyUI" && git pull) | |
| fi | |
| # --- Virtual Environment Setup --- | |
| echo "" | |
| echo "Setting up Python virtual environment at ${VENV_DIR}..." | |
| if [ ! -d "${VENV_DIR}" ]; then | |
| python -m venv "${VENV_DIR}" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to create virtual environment." | |
| exit 1 | |
| fi | |
| echo "Virtual environment created." | |
| else | |
| echo "Virtual environment already exists." | |
| fi | |
| # Activate the virtual environment | |
| source "${VENV_DIR}/bin/activate" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to activate virtual environment." | |
| exit 1 | |
| fi | |
| echo "Virtual environment activated." | |
| # --- Python Package Installation --- | |
| echo "" | |
| echo "Installing/Updating core PyTorch, torchvision, and torchaudio with CUDA support..." | |
| if check_pytorch_cuda; then | |
| echo "PyTorch with CUDA is already installed. Skipping." | |
| else | |
| echo "Attempting to uninstall existing PyTorch installations before clean install..." | |
| pip uninstall -y torch torchvision torchaudio 2>/dev/null | |
| pip install torch torchvision torchaudio --extra-index-url "${PYTORCH_CUDA_INDEX_URL}" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to install PyTorch with CUDA support. Check your CUDA setup and network connection." | |
| deactivate | |
| exit 1 | |
| fi | |
| echo "PyTorch, torchvision, and torchaudio installed." | |
| fi | |
| echo "" | |
| echo "Installing ComfyUI's core requirements..." | |
| pip install -r "${COMFYUI_DIR}/ComfyUI/requirements.txt" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to install ComfyUI requirements. Check the log for specific package errors." | |
| deactivate | |
| exit 1 | |
| fi | |
| echo "ComfyUI requirements installed." | |
| # --- ComfyUI-Manager Installation --- | |
| echo "" | |
| echo "ComfyUI-Manager setup..." | |
| COMFYUI_MANAGER_DIR="${COMFYUI_DIR}/ComfyUI/custom_nodes/ComfyUI-Manager" | |
| mkdir -p "${COMFYUI_DIR}/ComfyUI/custom_nodes" | |
| if [ ! -d "${COMFYUI_MANAGER_DIR}" ]; then | |
| echo "Cloning ComfyUI-Manager repository..." | |
| git clone "${COMFYUI_MANAGER_REPO}" "${COMFYUI_MANAGER_DIR}" | |
| if [ $? -ne 0 ]; then | |
| echo "Error: Failed to clone ComfyUI-Manager repository." | |
| echo "You may need to install it manually later or check network connectivity." | |
| else | |
| echo "ComfyUI-Manager cloned successfully." | |
| if [ -f "${COMFYUI_MANAGER_DIR}/requirements.txt" ]; then | |
| echo "Installing ComfyUI-Manager specific requirements (if any)..." | |
| pip install -r "${COMFYUI_MANAGER_DIR}/requirements.txt" | |
| fi | |
| fi | |
| else | |
| echo "ComfyUI-Manager directory already exists. Pulling latest changes." | |
| (cd "${COMFYUI_MANAGER_DIR}" && git pull) | |
| if [ $? -ne 0 ]; then | |
| echo "Warning: Failed to pull latest changes for ComfyUI-Manager." | |
| else | |
| echo "ComfyUI-Manager updated." | |
| if [ -f "${COMFYUI_MANAGER_DIR}/requirements.txt" ]; then | |
| echo "Re-installing ComfyUI-Manager specific requirements (if any)..." | |
| pip install -r "${COMFYUI_MANAGER_DIR}/requirements.txt" | |
| fi | |
| fi | |
| fi | |
| # --- Create Shortcuts --- | |
| echo "" | |
| echo "Creating desktop launchers for quick access..." | |
| # 1. Create the desktop launcher for running ComfyUI | |
| DESKTOP_FILE_PATH="${COMFYUI_DIR}/ComfyUI.desktop" | |
| echo "Creating ComfyUI.desktop launcher..." | |
| cat > "${DESKTOP_FILE_PATH}" << EOL | |
| [Desktop Entry] | |
| Name=ComfyUI | |
| Comment=Launch ComfyUI in a new terminal | |
| Exec=zsh -c "cd ${COMFYUI_DIR}/ComfyUI && source ${VENV_DIR}/bin/activate && python main.py; read -p 'Press Enter to close...'" | |
| Terminal=true | |
| Type=Application | |
| Icon=comfyui | |
| EOL | |
| chmod +x "${DESKTOP_FILE_PATH}" | |
| # 2. Create the desktop launcher for the virtual environment terminal | |
| VENV_DESKTOP_FILE_PATH="${COMFYUI_DIR}/ComfyUI_Terminal.desktop" | |
| echo "Creating ComfyUI_Terminal.desktop launcher..." | |
| cat > "${VENV_DESKTOP_FILE_PATH}" << EOL | |
| [Desktop Entry] | |
| Name=ComfyUI Terminal | |
| Comment=Open a terminal with the ComfyUI virtual environment active | |
| Exec=zsh -c "cd ${COMFYUI_DIR}/ComfyUI && source ${VENV_DIR}/bin/activate && exec zsh" | |
| Terminal=true | |
| Type=Application | |
| Icon=comfyui-terminal | |
| EOL | |
| chmod +x "${VENV_DESKTOP_FILE_PATH}" | |
| # --- Final Message --- | |
| echo "" | |
| echo "--- ComfyUI installation process completed ---" | |
| echo "You will now find the following files in this directory:" | |
| echo " - ComfyUI.desktop" | |
| echo " - ComfyUI_Terminal.desktop" | |
| echo "" | |
| echo "To get started, you can double-click 'ComfyUI.desktop'." | |
| echo "You may need to grant it permission to run the first time." | |
| echo "If you want to install more nodes, double-click 'ComfyUI_Terminal.desktop'." | |
| # Deactivate the environment at the end of the script to not leave it active globally | |
| deactivate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment