Repository: ollama/ollama
File: scripts/install.sh (Shell)

Code before:
        fi
    else
        SUDO_CMD=""
    fi
}

install_cuda_drivers() {
    local os_name

    if command -v lsb_release >/dev/null 2>&1; then
        os_name=$(lsb_release -is)
    else
        # If lsb_release is not available, fall back to /etc/os-release
        if [ -f "/etc/os-release" ]; then
            . /etc/os-release
            os_name=$ID
        else
            echo "Unable to detect operating system."
            return 1
        fi
    fi

    # based on https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#package-manager-installation
    case $os_name in
        CentOS)
            {$SUDO} yum install yum-utils
            {$SUDO} yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
            {$SUDO} yum clean all
            {$SUDO} yum -y install nvidia-driver-latest-dkms
            {$SUDO} yum -y install cuda-driver
            {$SUDO} yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)
            {$SUDO} dkms status | awk -F: '/added/ { print $1 }' | xargs -n1 {$SUDO} dkms install
            {$SUDO} modprobe nvidia
            ;;
        RedHatEnterprise*|Kylin|Fedora|SLES|openSUSE*|Microsoft|Ubuntu|Debian)
            echo "NVIDIA CUDA drivers may not be installed, you can install them from: https://developer.nvidia.com/cuda-downloads"
            ;;
        *)
            echo "Unsupported or unknown distribution, skipping GPU CUDA driver install: $os_name"
            ;;
    esac
}

check_install_cuda_drivers() {
    if command -v nvidia-smi >/dev/null 2>&1; then
        CUDA_VERSION=$(nvidia-smi | grep -o "CUDA Version: [0-9]*\.[0-9]*")
        if [ -z "$CUDA_VERSION" ]; then
            echo "Warning: NVIDIA-SMI is available, but the CUDA version cannot be detected. Installing CUDA drivers..."
            install_cuda_drivers
        else
            echo "Detected CUDA version $CUDA_VERSION"

Review comment (suggestion):
```suggestion
            $SUDO_CMD yum install yum-utils
```

Code after:
        fi
    else
        SUDO_CMD=""
    fi
}

install_cuda_drivers() {
    local os_name
    if [ -f "/etc/os-release" ]; then
        . /etc/os-release
        os_name=$ID
    else
        echo "Unable to detect operating system. Skipping CUDA installation."
        return 1
    fi

    # based on https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#package-manager-installation
    case $os_name in
        CentOS)
            $SUDO_CMD yum install yum-utils
            $SUDO_CMD yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
            $SUDO_CMD yum clean all
            $SUDO_CMD yum -y install nvidia-driver-latest-dkms
            $SUDO_CMD yum -y install cuda-driver
            $SUDO_CMD yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)
            $SUDO_CMD dkms status | awk -F: '/added/ { print $1 }' | xargs -n1 $SUDO_CMD dkms install
            $SUDO_CMD modprobe nvidia
            ;;
        RedHatEnterprise*|Kylin|Fedora|SLES|openSUSE*|Microsoft|Ubuntu|Debian)
            echo "NVIDIA CUDA drivers may not be installed, you can install them from: https://developer.nvidia.com/cuda-downloads"
            ;;
        *)
            echo "Unsupported or unknown distribution, skipping GPU CUDA driver install: $os_name"
            ;;
    esac
}

check_install_cuda_drivers() {
    if lspci -d '10de:' | grep 'NVIDIA' >/dev/null; then
        # NVIDIA Corporation [10de] device is available
        if command -v nvidia-smi >/dev/null 2>&1; then
            CUDA_VERSION=$(nvidia-smi | grep -o "CUDA Version: [0-9]*\.[0-9]*")
            if [ -z "$CUDA_VERSION" ]; then
                echo "Warning: NVIDIA-SMI is available, but the CUDA version cannot be detected. Installing CUDA drivers..."
                install_cuda_drivers
            else
                echo "Detected CUDA version $CUDA_VERSION"
            fi
        else
            echo "Warning: NVIDIA GPU detected but NVIDIA-SMI is not available. Installing CUDA drivers..."
            install_cuda_drivers