mirror of
https://abf.rosa.ru/djam/auto-krokodil.git
synced 2025-02-23 18:42:58 +00:00
64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
#!/usr/bin/php
|
|
|
|
<?php
|
|
|
|
/* Proprietary Nvidia drivers ship JSONs which specify which GPUs
|
|
* are supported by the driver. This script creates RPM provides from it. */
|
|
|
|
define("EXIT_CODE_EINPUT", 10);
|
|
define("EXIT_CODE_PARSEERROR", 20);
|
|
|
|
$FILE = getenv("FILE");
|
|
if (empty($FILE)) {
|
|
fwrite(STDERR, "Env FILE is not set! Set FILE=supported-gpus.json" . PHP_EOL);
|
|
exit(EXIT_CODE_EINPUT);
|
|
}
|
|
|
|
$data = file_get_contents($FILE);
|
|
$array = json_decode($data);
|
|
|
|
if (empty($array)) {
|
|
fwrite(STDERR, "Error decoding JSON from file " . $FILE . " !" . PHP_EOL);
|
|
exit(EXIT_CODE_EINPUT);
|
|
}
|
|
|
|
// EVR=%{version}-%{release}
|
|
$EVR = getenv("EVR");
|
|
|
|
if (empty($EVR)) {
|
|
fwrite(STDERR, "Empty package version! Set env EVR=version-release" . PHP_EOL);
|
|
exit(EXIT_CODE_EINPUT);
|
|
}
|
|
|
|
// 0x1E90 -> 1e90
|
|
function _dec_to_text($text) {
|
|
return strtolower(preg_replace("/^0x/", "", $text));
|
|
}
|
|
|
|
foreach($array->chips as $chip) {
|
|
// Skip GPUs not supported by this branch
|
|
if (!empty($chip->legacybranch)) {
|
|
continue;
|
|
} else {
|
|
$devid = _dec_to_text($chip->devid);
|
|
$subdevid = _dec_to_text($chip->subdevid);
|
|
$subvendorid = _dec_to_text($chip->subvendorid);
|
|
$name = $chip->name;
|
|
// Nvidia's JSON always specifies device ID but specifies other params not always
|
|
if (!(empty($devid))) {
|
|
echo "nvidia-blob-devid(" . $devid . ") = " . $EVR . PHP_EOL;
|
|
} else {
|
|
fwrite(STDERR, "Device ID must not be empty!" . PHP_EOL);
|
|
exit(EXIT_CODE_PARSEERROR);
|
|
}
|
|
if (!(empty($subdevid)))
|
|
echo "nvidia-blob-subdevid(" . $subdevid . ") = " . $EVR . PHP_EOL;
|
|
if (!(empty($subvendorid)))
|
|
echo "nvidia-blob-subvendorid(" . $subvendorid . ") = " . $EVR . PHP_EOL;
|
|
if (!(empty($name)))
|
|
echo "nvidia-blob-name(" . preg_replace("/ /", "+", $name) . ") = " . $EVR . PHP_EOL;
|
|
echo "nvidia-blob-info()" . "(devid=" . $devid . ")" . "(subdevid=" . $subdevid . ")" . "(subvendorid=" . $subvendorid . ")" . " = " . $EVR . PHP_EOL;
|
|
}
|
|
}
|
|
|
|
?>
|