mirror of
https://abf.rosa.ru/djam/auto-krokodil.git
synced 2025-02-23 18:42:58 +00:00
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
#!/usr/bin/php
|
|
|
|
<?php
|
|
|
|
/* Old Nvidia drivers do not have a JSON with supported models,
|
|
* but JSONs of newer drivers specify GPUs supported by older drivers.
|
|
* This scripts takes a JSON from a newer driver and converts it
|
|
* into a JSON for an older driver which does not ship a native JSON. */
|
|
|
|
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);
|
|
}
|
|
|
|
$BRANCH = getenv("BRANCH");
|
|
if (empty($BRANCH)) {
|
|
fwrite(STDERR, "Env BRANCH is not set! Set e.g. ENV=390 to generate JSON for branch 390.xx" . 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);
|
|
}
|
|
|
|
$chips_arr = array();
|
|
|
|
foreach($array->chips as $chip) {
|
|
if (empty($chip->legacybranch))
|
|
continue;
|
|
// php 8+ has str_starts_with()
|
|
if (!(strpos($chip->legacybranch, $BRANCH . ".", 0) === 0))
|
|
continue;
|
|
// devid (Device ID) cannot be empty, other params can be empty
|
|
if (empty($chip->devid)) {
|
|
fwrite(STDERR, "Device ID cannot be empty!" . PHP_EOL);
|
|
exit(EXIT_CODE_PARSEERROR);
|
|
}
|
|
$arr = array("devid" => $chip->devid,
|
|
"subdevid" => $chip->subdevid,
|
|
"subvendorid" => $chip->subvendorid,
|
|
"name" => $chip->name,
|
|
"features" => $chip->features);
|
|
array_push($chips_arr, $arr);
|
|
}
|
|
|
|
$chips_arr = array("chips" => $chips_arr);
|
|
echo json_encode($chips_arr);
|
|
|
|
?>
|