auto-krokodil/krokodil-legacy-converter.php
2021-10-04 02:59:43 +03:00

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);
?>