Friday, December 11, 2009

Nvidia Updater in Python

I rewrote this script in python because I figured it'd be more cross platform. It require python 2.6.x and the python-beautifulsoup package in Ubuntu.

Everything runs pretty much identically in this python version as it does in the php version. I've supplied this second version mostly to help myself become more proficient in python.

You still have to install the driver manually because they require user input. This just makes it much easier to find out if a new version exists and then download the new version.

I'm just giving a link to this one because indentation matters in python, and as you can see in the php version below, blogspot isn't too kind to indentation.


and here's also a direct link to an updated php version

Wednesday, December 9, 2009

Nvidia Driver Updater for Linux

I've created a php script to automatically check the nvidia website and download a new driver if available. It's pretty simple how it works. Just run the script and it will do it's magic. The first time it is run, it will create a file called "current" in the same directory. Also, on the first run, it will always download the latest version of the driver in the same directory. After the first run, every other run will only download the driver if a new version is available.

This is mainly for those who are using nvidia drivers from outside the Ubuntu repository. If you're using the (often slightly old) driver in the repository, there is no need to use this script because Ubuntu will update it when ever the Ubuntu devs update the repo (I think each Ubuntu release comes with a new version of the driver). This is only for those who want the bleeding edge nvidia drivers and know how to install them manually.

I should note that you have to actually install the driver yourself as usual, this script just automates the download process and lets you avoid nvidia's click-fest of a website.

Just copy the code below into a text file and save it in your desired location as updater.php. From the command line, cd into the directory you save it and run 'php updater.php'. Better yet, set up a cron to run every few days or few hours to automatically download the updates.

<?php
function curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);
return $result;
}

$site = curl('http://www.nvidia.com/object/unix.html');

$doc = @DOMDocument::loadHTML($site);
$p = $doc->getElementsByTagName('p');
$node = $p->item(3)->nodeValue;
//$node = $p->item(5)->nodeValue; // uncomment this line for the 64-bit version

$del = explode("\n", trim($node));
$latest = trim(substr($del[0], strpos($del[0], ':')+2));
$current = (is_file('current')) ? trim(file_get_contents('current')) : 0;
if ($current != $latest) {
$url = "http://us.download.nvidia.com/XFree86/Linux-x86/$latest/NVIDIA-Linux-x86-$latest-pkg1.run";
system("wget -p $url");
file_put_contents('current', $latest);
}
?>

I've only actually tested this in Ubuntu, but in theory, it should work elsewhere. You just need to have php5-cli installed. The code above is for the 32-bit version of the nvidia driver. Uncomment "$node = $p->item(5)->nodeValue;" and it will download the 64-bit version.