initial script based on http://www.raspberrypi.org/phpBB3/viewtopic.php?p=136912