endeavouros-team/PKGBUILDS

Nvidia urls doesnt work anymore

Schplatter opened this issue · 2 comments

Hey guys, I went into errors and found out that the nvidia urls doesnt work anymore.

The new urls I have successfully tested are here:

#!/bin/bash

# Find the right Nvidia driver for a card.

echo2()   { echo   "$@" >&2 ; }
printf2() { printf "$@" >&2 ; }

DIE() {
    echo2 "$progname: error: $1"
    exit 1
}

if false ; then
GetNvidiaIds_old()
{
    local version="$1"
    local ids="$(curl -Lsm $curl_timeout -o- https://download.nvidia.com/XFree86/Linux-x86_64/$version/README/supportedchips.html)"
    local true_series="${version%%.*}"

    [ -n "$ids" ] || DIE "fetcing supported ids for $version failed"

    ids="$(echo "$ids" | sed -n '1,/.*Below are the legacy GPUs that are no longer supported.*/p' | grep '<tr id=')"

    # old (340 series):
    #    <tr id="0x064C">                   # take 064C
    #
    # new (390 ... ):
    #    <tr id="devid17FD_10DE_1173">      # take 17FD
    #    <tr id="devid17FD">                # take 17FD

    if [ -n "$(echo "$ids" | grep 'id="devid')" ] ; then
        ids="$(echo "$ids" | grep '<tr id="devid' | sed 's|.*devid\([0-9A-F]*\)["_].*|\1|')"        # new
    else
        ids="$(echo "$ids" | sed 's|.*id="0x\([0-9A-F]*\)">|\1|')"                                  # old
    fi

    ids=$(echo "$ids" | sort | uniq | tr '[:upper:]' '[:lower:]')
    echo "$true_series|$ids"
}
fi

FilterIds() {
    # supports series 390 and later
    grep '<tr id="devid' | sed 's|.*devid\([0-9A-F]*\)["_].*|\1|' | sort -u | tr '[:upper:]' '[:lower:]'

    # grep 'id="devid' | grep '<tr id="devid' | sed 's|.*devid\([0-9A-F]*\)["_].*|\1|' | sort -u | tr '[:upper:]' '[:lower:]'
}

GetNvidiaIds() {
    local series="$1"
    [ -n "$series" ] || return 1
    local ids=""
    local sid1="${series_ids[0]}"   # e.g. 520
    local sid2="${series_ids[1]}"   # e.g. 470
    local sid3="${series_ids[2]}"   # e.g. 390
    local sidX="$series_id_out"

    case "$series" in
        $sid1) ids="$(echo "$ids_all" | sed -n '1,/.*Below are the legacy GPUs that are no longer supported.*/p' | FilterIds)" ;;
        $sid2) ids="$(echo "$ids_all" | sed -n "/.*\"legacy_$sid2.xx\"*/,/.*\"legacy_$sid3.xx\".*/p" | FilterIds)" ;;
        $sid3) ids="$(echo "$ids_all" | sed -n "/.*\"legacy_$sid3.xx\"*/,/.*\"legacy_$sidX.xx\".*/p" | FilterIds)" ;;

        $beta_series) ids="$(echo "$ids_beta" | sed -n '1,/.*Below are the legacy GPUs that are no longer supported.*/p' | FilterIds)" ;;

        *) DIE "unsupported series '$series'" ;;
    esac

    echo "$ids"
}

ShowDriversForId() {
    local id="$1"
    local ix
    local ids
    local ver
    local true_series=""   # found from the Nvidia website
    local ids_all
    local ids_beta
    local found=no
    local exit_code=0
    local -r url_of_ids="$(UrlOfIds "$pacman_pkgver")"
    local -r url_of_beta_ids="$(UrlOfIds "$beta_pkgver")"

    ids_all="$(curl --fail -Lsm $curl_timeout -o- "$url_of_ids")"
    exit_code=$?

    [ -n "$ids_all" ] || DIE "Nvidia id data not available from '$url_of_ids'! Curl exit code $exit_code."

    ids_beta="$(curl --fail -Lsm $curl_timeout -o- "$url_of_beta_ids")"
    [ -n "$ids_beta" ] || DIE "Nvidia id data not available from '$url_of_beta_ids'! Curl exit code $exit_code."

    for ver in "${nvidia_versions[@]}" ; do
        true_series="${ver%%.*}"
        if [ "$testing" = "yes" ] ; then
            [ $true_series -eq 390 ] || continue
        fi
        ids="$(GetNvidiaIds "$true_series")"
        if [ -n "$(echo "$ids" | grep "$id")" ] ; then
            printf "\nSeries %s: supported (nvidia.com: %s)\n\n" "$true_series" "$ver"     # DO NOT CHANGE THIS LINE! Other apps use it.
            if [ "$ver" = "$beta_pkgver" ] && [ "$beta_pkgver" != "$pacman_pkgver" ] ; then
                printf2 "NOTE: $beta_pkg $ver is an AUR package. To install it, use command:\n   yay -S $beta_pkg\n"
            fi
            case "$true_series" in
                ${series_ids[1]} | ${series_ids[2]} | 470 | 390)
                    printf2 "NOTE: nvidia-inst does not support series $true_series. To install, use the 'yay' command.\n"
                    ;;
            esac
            [ "$all" = "no" ] && return
            found=yes
        else
            [ "$all" = "yes" ] && echo2 "Series $true_series: not supported"
        fi
    done
    if [ "$found" = "no" ] ; then
        echo2 "Sorry, none of the Nvidia driver series [$(echo "${series_ids[*]}" | sed 's| |, |g')] is supported."
        printf2 "\nMore info:\n   %s\n   %s\n" "$starting_url" "$url_of_ids"
    fi
}

GetNvidiaVersions() {
    echo2 "NVIDIA card id: $nvidia_id"
    echo2 "Fetching driver data from nvidia.com ..."

    local s n
    local ret=0
    local versions
    versions=$(curl --fail -Lsm $curl_timeout -o- "$starting_url")       # get the html data about the versions of the Nvidia drivers
    ret=$?
    [ -n "$versions" ] || DIE "Fetching Nvidia driver info from '$starting_url' failed (curl code $ret). Please try again later."

    versions=$(echo "$versions" | grep "Linux x86_64/AMD64")                   # extract the line with only Linux x86_64 versions
    versions=$(echo "$versions" | sed 's|</a>|</a>\n|g' | grep Latest)         # make each version appear on a separate line
    versions=$(echo "$versions" | sed -E 's|.*>[ ]*([0-9\.]+)[ ]*<.*|\1|')     # extract version number on each line between '>' and '<' (excluding spaces)

    for n in $versions ; do
        [ $(vercmp $n $series_id_out) -lt 0 ] && continue
        for s in "${series_ids[@]}" ; do
            case "$n" in
                $s.*) nvidia_versions+=("$n") ;;
            esac
        done
    done
    if [ "$beta_pkgver" != "$pacman_pkgver" ] ; then
        nvidia_versions+=("$beta_pkgver")
    fi
}

Options() {
    local opts

    opts="$(/usr/bin/getopt -o=hajt: --longoptions help,all,test,timeout: --name "$progname" -- "$@")" || {
        Options -h
        return 1
    }

    eval set -- "$opts"

    while true ; do
        case "$1" in
            -a | --all) echo2 "Info: option '$1' recognized but is no more used." ;; # all=yes ;;
            -j | --test) testing=yes ;;
            -t | --timeout) curl_timeout="$2" ;;

            -h | --help)
                cat <<EOF >&2
Usage: $progname [options] [parameters]

Options:
  -t, --timeout     Timeout in seconds for operations that fetch driver data from nvidia.com.
                    Default: $curl_timeout_default
  -a, --all         (Show status for all available driver branches.)
                    NOTE: this option does nothing due to implementation change.

  -h, --help        This help.

Parameters:
  card_id           Nvidia card id (4 hex numbers, lower case letters).
                    Example: 1b83
                    Note: card_id is an optional parameter.

Tip: the "card_id" value can be found with command:

  lspci -vnn | grep -P 'VGA|3D|Display' | sed 's|.*\[10de:\([0-9a-f]*\)\].*|\1|'

EOF
                exit 0
                ;;
            
            --) shift ; break ;;
        esac
        shift
    done

    nvidia_id="$1"

    case "$nvidia_id" in
        [0-9a-f][0-9a-f][0-9a-f][0-9a-f] | "") ;;
        *) DIE "given card id '$nvidia_id' is invalid" ;;
    esac
}

UrlOfIds() {
    local ver="$1"
    echo "https://download.nvidia.com/XFree86/Linux-x86_64/$ver/README/supportedchips.html"
}

GetPacmanVersion() {
    local infopkg="$1"
    {
        if [ -x /usr/bin/expac ] ; then
            expac -S %v "$infopkg"
        else
            LANG=C pacman -Si "$infopkg" | grep -w ^Version | awk '{print $NF}'
        fi
    } | head -n1   # in case multiple repos have it, take the first
}

Main() {
    local -r progname="$(basename "$0")"
    local -r infopkg=nvidia-dkms
    local -r pacman_version=$(GetPacmanVersion "$infopkg")
    local -r pacman_pkgver=$(echo "$pacman_version" | sed 's|-[0-9.]*$||')
    local -r pacman_version_series=${pacman_pkgver%%.*}
    local -r starting_url="https://www.nvidia.com/en-us/drivers/unix"
    local -r all=no                                                      # this will no more be changed!
    local testing=no
    local -r curl_timeout_default=30
    local curl_timeout=$curl_timeout_default
    local nvidia_id=""
    local nvidia_versions=()
    local -r beta_pkg=nvidia-beta-dkms
    local -r beta_pkgver=$(yay -Ss $beta_pkg | grep ^aur/ | awk '{print $2}' | sed 's|-[0-9.]*$||')
    local -r beta_series=${beta_pkgver%%.*}

    [ -n "$pacman_pkgver" ] || DIE "cannot determine the version of the latest available package $infopkg"
    [ -n "$beta_pkgver" ]   || DIE "cannot determine the version of the latest available package $beta_pkg"

    Options "$@"

    local series_ids=(
        $pacman_version_series        # latest provided by Arch
        470                           # legacy series ids
        390                           # ditto
    )
    local series_id_out=367           # may change as series_ids change!

    if [ -z "$nvidia_id" ] ; then
        nvidia_id="$(lspci -vnn | grep -P 'VGA|Display|3D' | grep "\[10de:" | sed 's|.*\[10de:\([0-9a-f]*\).*|\1|')"
    fi

    GetNvidiaVersions                 # find versions NVIDIA is currently supporting

    if [ -n "$nvidia_id" ] ; then
        ShowDriversForId "$nvidia_id"
    fi
}

Thanks! Released new version (23-6) of nvidia-installer-common which should fix this.